Graphql-engine: add custom names to root level types

Created on 1 Aug 2018  路  11Comments  路  Source: hasura/graphql-engine

Hi,
Great product and service you are building there,
https://docs.hasura.io/1.0/graphql/manual/queries/index.html says :

...query and insert/update/delete mutations each are added as nested fields under the root level types, query_root and mutation_root respectively.

Is there a way to configure/change those type names for "Query" and "Mutation" as some graphql consuming projects rely on those naming conventions ?

Thanks for your answer

server enhancement triag2-needs-rfc

Most helpful comment

Any update on this? Cant connect my angular app with apollo to hasura because of this issue

All 11 comments

You would like to change the names query_root and mutation_root to something else? The GraphQL spec doesn't enforce any restrictions what these type names should be. Can you point us to a project where this is causing an issues? We can definitely add a couple of command line flags to change this.

Thanks for your answer,
I'm trying to plug hasura and https://github.com/wittydeveloper/react-apollo-form/
That tool parses the schema on the assumption that mutations root type is named "Mutation".
See here : https://github.com/wittydeveloper/react-apollo-form/blob/88f7ca37a56c15d9f150a4a2f3cc06178ad9e4fb/lib/forms/definitions.ts#L38

Okay. We'll add --query-root-name, --mutation-root-name, --subscription-root-name flags to the server.

Great thing :+1: thanks

Hi Vamshi,
To get a glimpse on this, could you tell me rough steps to implement renaming hard coding it ?
I've located where those root names are defined : https://github.com/hasura/graphql-engine/search?q=mutation_root&type=Code
But I cant see what I need to do to get to a modified docker version of graphql-engine. How do I go from code modification to a running docker version of hasura ?
Thanks in advance

You can cd into the server directory and run make image. A fair warning, this step will download a docker image which is 2-3 GB and the compilation could take a while.

@cwartel I completely forgot to mention if you make a change and then submit a PR you鈥檒l get a build and a sample heroku app deployed automatically that you can test with! And of course the docker image gets built too once the tests pass automatically

Do try it out and let me know if you need help!

Hi Tanmai I'll do it the PR way as I had no success building from source as Vamshi suggested

For anyone that comes here for the error query_root must define one or more fields, I received this because the admin authorization header is not set for the GraphQL Playground after running hasura api-console. I grabbed the admin token from local storage and put it in the Authorization: Bearer <token> header and stopped receiving the error.

Edit: I realized after I wrote this that there is a button to add the Admin token to Graphiql in Hasura platform.

Any update on this? Cant connect my angular app with apollo to hasura because of this issue

@dilame This issue is something we would like to pick up and we are figuring out its priority 馃檪

Was this page helpful?
0 / 5 - 0 ratings