Version 6 pre-stable
This version of Silverstripe CMS has not yet been given a stable release. See the release roadmap for more information. Go to documentation for the most recent stable version.

Getting started

Server Requirements
What you will need to run GraphQL on a web server
Activating the default server
Open up the default server that comes pre-configured with the module
Configuring your schema
Add a basic type to the schema configuration
Building the schema
Turn your schema configuration into executable code
Building a schema with procedural code
Use PHP code to build your schema
Deploying the schema
Deploy your GraphQL schema to a test or production environment

Activating the default GraphQL server

GraphQL is used through a single route, typically /graphql. You need to define types and queries to expose your data via this endpoint.

These separate endpoints have their own identifiers. default refers to the GraphQL server in the user space (e.g. /graphql) - i.e. your custom schema. You can also set up a new schema server if you wish.

The word "server" here refers to a route with its own isolated GraphQL schema. It does not refer to a web server.

By default, silverstripe/graphql does not route any GraphQL servers. To activate the default, public-facing GraphQL server that ships with the module, just add a rule to Director.

SilverStripe\Control\Director:
  rules:
    'graphql': '%$SilverStripe\GraphQL\Controller.default'

Setting up a custom GraphQL server

In addition to the default /graphql endpoint provided by this module by default, you may want to set up another GraphQL server running on the same installation of Silverstripe CMS.

Let's set up a new controller to handle the requests.

SilverStripe\Core\Injector\Injector:
  # ...
  SilverStripe\GraphQL\Controller.myNewSchema:
    class: SilverStripe\GraphQL\Controller
    constructor:
      schemaKey: myNewSchema

We'll now need to route the controller.

SilverStripe\Control\Director:
  rules:
    'my-graphql': '%$SilverStripe\GraphQL\Controller.myNewSchema'

Now, once you have configured and built your schema, you can access it at /my-graphql.

Further reading

Server Requirements
What you will need to run GraphQL on a web server
Activating the default server
Open up the default server that comes pre-configured with the module
Configuring your schema
Add a basic type to the schema configuration
Building the schema
Turn your schema configuration into executable code
Building a schema with procedural code
Use PHP code to build your schema
Deploying the schema
Deploy your GraphQL schema to a test or production environment