graphql-devise / graphql_devise

GraphQL interface on top devise_token_auth
MIT License
199 stars 42 forks source link

Customized Mutations #206

Closed tonekk closed 2 years ago

tonekk commented 2 years ago

Hi there,

what is the best way to alter / customize the mutations that are already given by the gem? For example, I want to use the register mutation, but in our case we need to also send a username and check the terms of service.

I could fork the gem and edit the mutation, but I do not think that this is a good way, since I would have to maintain the fork. Can I subclass the Mutation somehow and include it in my schema?

Thanks :)

mcelicalderon commented 2 years ago

Hey, @tonekk, you sure can! Take a look at the operations option in https://github.com/graphql-devise/graphql_devise#available-mount-options

There's an example in https://github.com/graphql-devise/graphql_devise/blob/b5985036e01ea064e43e457b4f0c8516f172471c/spec/dummy/app/graphql/mutations/login.rb#L6 but the operation was already removed. Anyway, the same should work for the new register mutation.

mcelicalderon commented 2 years ago

Actually, we do have an updated example in master https://github.com/graphql-devise/graphql_devise/blob/ca345f3f4fd0b54fb1941471d520e502fa06375d/spec/dummy/app/graphql/mutations/register.rb#L9

tonekk commented 2 years ago

Thank you, I implemented it :)