Skip to content

GraphQL customization

Custom schema

You can customize the GraphQL schema that is generated from your repository.

You can use it if your application requires custom GraphQL resources, for instance for Doctrine entities.

To do so, create an app/config/graphql/Query.types.yml file. It will be used as the GraphQL query root.

In that file, add new fields that use any custom type or custom logic you require, based on overblog/GraphQLBundle.

Configuration

You can include the eZ Platform schema in two ways: either through inheritance or composition.

Inheritance

To use inheritance, apply the following configuration in app/config/graphql/Query.types.yml:

1
2
3
4
5
6
7
8
Query:
    type: object
    inherits:
        - Domain
    config:
        fields:
            customField:
                type: object

Composition

To use composition, define eZ Platform schema as a field in your custom schema. For example, in app/config/graphql/Query.types.yml:

1
2
3
4
5
6
7
8
Query:
    type: object
    config:
        fields:
            myCustomField: {}
            myOtherCustomField: {}
            ezplatform:
                type: Domain

Custom mutations

Custom mutations are created in the same way as custom query configuration. An app/config/graphql/Mutation.types.yml file will be used as the source for mutation definitions in your schema.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Mutation:
    type: object
    inherits: [PlatformMutation]
    config:
        fields:
            createSomething:
                builder: Mutation
                builderConfig:
                        inputType: CreateSomethingInput
                        payloadType: SomethingPayload
                        mutateAndGetPayload: '@=mutation('CreateSomething', [value])'

CreateSomethingInput:
    type: relay-mutation-input
    config:
        fields:
            name:
                type: String

SomethingPayload:
    type: object
    config:
        fields:
            name:
                type: String
Read the Docs