Version 4 supported
This version of Silverstripe CMS is still supported though will not receive any additional features. Go to documentation for the most recent stable version.

Working with generic types

Creating a generic type
Creating a type that doesn't map to a DataObject
Adding pagination
Add the pagination plugin to a generic query
Building a custom query
Add a custom query for any type of data
Adding arguments
Add arguments to your fields, queries, and mutations
The resolver discovery pattern
How you can opt out of mapping fields to resolvers by adhering to naming conventions
Enums, unions, and interfaces
Add some non-object types to your schema
Adding descriptions
Add descriptions to just about anything in your schema to improve your developer experience

You are viewing docs for silverstripe/graphql 4.x. If you are using 3.x, documentation can be found in the GitHub repository

Creating a generic type

Let's create a simple type that will work with the inbuilt features of Silverstripe CMS. We'll define some languages based on the i18n API.

# app/_graphql/types.yml
Country:
  fields:
    code: String!
    name: String!

We've defined a type called Country that has two fields: code and name. An example record could be something like:

[
    'code' => 'bt',
    'name' => 'Bhutan',
]

That's all we have to do for now! We'll need to tell GraphQL how to get this data, but first we need to building a custom query to see how we can use it.

Further reading

Creating a generic type
Creating a type that doesn't map to a DataObject
Adding pagination
Add the pagination plugin to a generic query
Building a custom query
Add a custom query for any type of data
Adding arguments
Add arguments to your fields, queries, and mutations
The resolver discovery pattern
How you can opt out of mapping fields to resolvers by adhering to naming conventions
Enums, unions, and interfaces
Add some non-object types to your schema
Adding descriptions
Add descriptions to just about anything in your schema to improve your developer experience