graphql_devise icon indicating copy to clipboard operation
graphql_devise copied to clipboard

How to change names of queries and mutations ?

Open maszuDEV opened this issue 3 years ago • 5 comments

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!

maszuDEV avatar Sep 07 '21 10:09 maszuDEV

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 avatar Sep 07 '21 13:09 00dav00

@00dav00 This is what I needed! Works great, thanks a lot!

maszuDEV avatar Sep 07 '21 20:09 maszuDEV

Good to know @maszuDEV !

00dav00 avatar Sep 07 '21 20:09 00dav00

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

mcelicalderon avatar Sep 07 '21 20:09 mcelicalderon

@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?

mcelicalderon avatar Sep 08 '21 17:09 mcelicalderon