Silverstripe 3 graphql integration

Silverstripe Version:


I have a project built on SS3 back in 2016 and just updated to version 3.7.4 . I am planning to use
Graphql. I know SS4 support it natively but I don’t have time to update it because the application is so big. I have a lot of data object models and want to use SS3 ORM when querying data in Graphql. Is anyone here have successfully setup a working server and directly integrate it with SS3?. Please share your code or ideas how to make it work. Thanks in advance.

// Include any relevant code. If you have a lot of code, link to a gist instead.

I have figured it out. I have use digiaonline library. It doesn’t need a separate server to run. Just create a controller and action and bootstrap digiaonline graphql and it will work and for the GraphQL query tool, I have installed Graphiql and point the the url to my controller action.


use Digia\GraphQL\Language\FileSourceBuilder;
use function Digia\GraphQL\buildSchema;
use function Digia\GraphQL\graphql;

class GraphQLController extends Controller {

    public function index() {

        $sourceBuilder = new FileSourceBuilder(__DIR__ . '/schema.graphql');
        $resolvers = include __DIR__.'/resolvers.php';

        $schema = buildSchema($sourceBuilder->build(), $resolvers);

        $body =  json_decode($this->request->getBody(), true);
        $result = graphql($schema, $body['query']);

        $this->response->addHeader('Content-Type', 'application/json');
        return json_encode($result);