GraphQL

Running silverstripe/graphql v4 on Silverstripe Cloud

silverstripe/graphql is an implementation of GraphQL specific to Silverstripe CMS. It is used to power some aspects of the CMS UI. It can also be used by developers to create APIs that other web services can use to read or update data in your CMS sites.


This documentation applies for silverstripe/graphql v4+


There is generic documentation for building and deploying these schemas on  docs.silverstripe.org - however this document provides information specific to projects hosted on Silverstripe Cloud.

Building the schema

In most cases, you can just let Silverstripe CMS generate the GraphQL schema on the first GraphQL request. The schema will be cleared during each deployment (if the code has changed), so there is no risk of the schema becoming stale. You may need to consider alternative means to generate your GraphQL schema if you have a more complex use case.

My project exposes a sizable custom GraphQL schema

For projects with more sophisticated requirements or bigger schemas exposing more than 100 DataObject classes, you may want to avoid slowing down the first GraphQL request by building your schema up front.


Your schema is stored in the .graphql-generated/ directory, and a json-encoded introspection file is stored in public/_graphql/. For the below instructions, treat both of these as “the generated schema”.

Include your generated schema in the deployment bundle

If you are using a CICD pipeline, you can run vendor/bin/sake dev/graphql/build as a step in that pipeline and include the generated schema in your deployment bundle. If you aren’t using such a pipeline, you can generate the schema in a development environment and include it in your VCS.


If you choose this option you may want to disable the DevBuildExtension so that your schema doesn’t get re-generated during the deployment:


SilverStripe\GraphQL\Extensions\DevBuildExtension:
  enabled: false


Was this answer helpful? Yes No

Sorry we couldn't be helpful. Help us improve this article with your feedback.