graphql-devise / graphql_devise

GraphQL interface on top devise_token_auth
MIT License
200 stars 39 forks source link

How to change names of queries and mutations ? #196

Open maszuDEV opened 3 years ago

maszuDEV commented 3 years ago

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!

00dav00 commented 3 years ago

Hi @maszuDEV , the names of the default operations will use the class and namespace, check these links for reference:

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:

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.

maszuDEV commented 3 years ago

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

00dav00 commented 3 years ago

Good to know @maszuDEV !

mcelicalderon commented 3 years ago

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 commented 3 years ago

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