graphql_devise
graphql_devise copied to clipboard
How to change names of queries and mutations ?
Question
Hello everyone,
In my case, I have a user model like: User::Model
, which is generating mutations named, e.g. userModelLogin
.
Is there any option to change the way how queries and mutations are naming? I would like to have just userLogin
.
Best regards!
Hi @maszuDEV , the names of the default operations will use the class and namespace, check these links for reference:
- https://github.com/graphql-devise/graphql_devise/blob/e9c9a8f6cf8ad9851261e907347e7a3c8d635e3e/lib/graphql_devise.rb#L40
- https://github.com/graphql-devise/graphql_devise/blob/e9c9a8f6cf8ad9851261e907347e7a3c8d635e3e/lib/graphql_devise/mount_method/operation_preparers/default_operation_preparer.rb#L18
I think a work around for your case could be to add additional_mutations
and additional_queries
with the names you are looking for. Please take a look at the README sections for this:
- https://github.com/graphql-devise/graphql_devise#mounting-auth-schema-on-a-separate-route
- https://github.com/graphql-devise/graphql_devise#mounting-operations-in-an-existing-schema
Remember that only
or skip
(they are mutually exclusive) can also help you choose which of the default operations you want to be mounted on the schema.
@00dav00 This is what I needed! Works great, thanks a lot!
Good to know @maszuDEV !
We should probably add a simpler way to rename queries...
Another way to do this if you are using the plugin to mount this gem in your own schema, would be to create your own login mutation that inherits from the one included in this gem, and use it in you own mutation type with the name you like. Like we do in here: https://github.com/graphql-devise/graphql_devise/blob/e9c9a8f6cf8ad9851261e907347e7a3c8d635e3e/spec/dummy/app/graphql/mutations/login.rb#L4
then, in your mutationType file you would just do:
field :user_login, mutation: Mutations::Login, authenticate: false
@00dav00 reopening this one as a feature request. Changing names of the queries should be straightforward and a nice addition. Perhaps something in the resource loaders like:
GraphqlDevise::ResourceLoader.new(User, only: [:login, :confirm_registration_with_token], custom_names: { login: :my_user_login_custom_mutation })
WDYT?