Graphqlbundle: Conditional Schema Configuration / Splitting

Created on 16 Aug 2018  路  3Comments  路  Source: overblog/GraphQLBundle

| Q | A
| ---------------- | -----
| Bug report? | no
| Feature request? | no
| BC Break report? | no
| RFC? | yes
| Version/Branch | v0.11.4

Hey guys, great bundle!

I was wondering if it would be possible to have some kind of conditional schema configuration. Say we have a big project and split features into seperate Symfony bundles. One of these bundles would be the graphql api bundle that defines the graphql schema. Now we want the root query to only define the users field if the user bundle is included in the project.

What i found out was that we currently can't define the graphql schema in multiple files. So i can't extend the root query in the user bundle and append a users field. Also i can't just define the users field in the api bundle since it would then be exposed if the user bundle is not registered and the resolver would throw.

What options do I have to define the schema based on availability of bundles or maybe even entities / other conditions? Can I somehow generate the schema config in a service instead of using Yaml? Any help would be appreciated.

question

All 3 comments

hi @tjuenger, you can use type inheritance
to do that:

here your main query

RootQuery:
    type: object
    config:
        fields:
            name: {type: String!}

adding user field in your user bundle

UserQuery:
    decorator: true
    heirs: [RootQuery] # Inheritance is done here
    config:
        fields:
            user: {type: User!}

result would be:

RootQuery:
    type: object
    config:
        fields:
            name: {type: String!}
            user: {type: User!}

This does the trick. Thank you very much!

Feel free to continue discussion here if needed :+1:

Was this page helpful?
0 / 5 - 0 ratings