Comments (14)
Hi @Gakamine, in the dummy app signUp
mutation the field name
was added. Basically what you need to do is:
- create a mutation that inherits from
GraphqlDevise::Mutations::SignUp
- define you custom response type, in this case
Types::UserType
. - tell gql_devise which
signUp
mutation to use in the routes file
Is this what you were looking for?
from graphql_devise.
Hey @Gakamine, as @00dav00 mentioned, that is the only way to do it right now and you can customize your mutation as much as you want. But we are thinking about the scenario were the ONLY thing you want is to add more fields to the sign up mutation and not change the behavior. Do you think adding another option to the mount method would be good? I didn't like the fact that the routes file might know too much about the models, but it could look something like this for those who wish to do it like that.
mount_graphql_devise_for(
'User',
at: 'api/v1',
authenticable_type: Types::MyCustomUserType,
operations: {
login: Mutations::Login
},
additional_sign_up_arguments: [
{ name: :username, type: String, required: true }
],
skip: [:sign_up]
)
What do you think?
from graphql_devise.
Closing this one as the more we work en the gem, the less I think we will end up implementing this as the cleaner alternative is to have your own mutation inherit from the one on the gem with the additional arguments.
Doesn't mean we might not still implement it down the line, specially if someone feels like that would definitively be a improvement over the proposed implementation.
from graphql_devise.
Reopening this so I don't forget to implement
from graphql_devise.
Thank you !! @00dav00 @mcelicalderon
I think it would be a good idea to add an option in the mount method, it would be easier for small changes. I would still use the solution that @00dav00 gave me because I don't like either that my route file know too much about the model and I want to add multiple field, it would make my route file impossible to read.
from graphql_devise.
I haven't fully customized my own mutations yet since I'm still attempting a simple create-react-app
example so I haven't hit this road block yet but I imagine being able to have your SignUp
mutation inherit from GraphqlDevise::Mutations::SignUp
and add whatever fields you wanted (First Name, Last Name, Phone Number etc) and just reference that mutation in your routes config.
I agree with @Gakamine that any custom fields you want for your custom mutations should be in that file and that simply doing:
operations: {
signIn: Mutations::MySignIn # this mutation will have fields added to it for what you need
}
from graphql_devise.
You may want to support nested attributes also @mcelicalderon. Devise supports it, so it should be assumed that we would also. See: https://github.com/plataformatec/devise#strong-parameters
from graphql_devise.
Hi @Gakamine, in the dummy app
signUp
mutation the fieldname
was added. Basically what you need to do is:
- create a mutation that inherits from
GraphqlDevise::Mutations::SignUp
- define you custom response type, in this case
Types::UserType
.- tell gql_devise which
signUp
mutation to use in the routes fileIs this what you were looking for?
@00dav00 I tried your example with the dummy app but it errored out undefined method 'resource_class' for nil:NilClass
# frozen_string_literal: true
module Mutations
class SignUp < GraphqlDevise::Mutations::SignUp
field :user, Types::UserType, null: true
field :profile, Types::ProfileType, null: true
def resolve(email:, **attrs)
binding.pry
original_payload = super
original_payload.merge(user: original_payload[:authenticatable])
end
end
end
This is my code, I planned on adding to it to create a profile.
from graphql_devise.
Hey @lassiter! So, not sure what the profile field is, but you should definitively include another key in the hash returned by the resolve
method. This issue is related to adding more values to the user model when using the sign up mutation, so not sure if you are trying to do this. If that's the case, just like in here, what you need to add is an argument to your mutation. Anyway, the undefined method error seems weird to me, please send the backtrace so we can identify the problem.
from graphql_devise.
Might have missed it, but I spent a while looking for this in README before coming here. I think someone else mentioned also but might be nice to have this in readme. happy to make a PR to place in README if that helps.
from graphql_devise.
Actually noticing an issue with the above subclass solution.
I only use a single endpoint, so I have the mounting operations in my own schema. This works great.
However, if I try to do the above solution, the rest of my schema is not seen by graphiql.
So:
mount_graphql_devise_for 'User', at: '/graphql', operations: {
sign_up: Mutations::Users::SignUp
}
post "/graphql", to: "graphql#execute"
get "/graphql", to: "graphql#execute"
...causes all of my other schema to be ignored.
If I swap the order, then the custom operation is ignored. They seem to be mutually exclusive.
I really want to keep a single endpoint. Is it possible?
from graphql_devise.
Hi @keithmgould, if you mount the operations using the routes, the gem expects the endpoint to be exclusively for auth. If want to use a single endpoint/schema you will have to use the schema plugin, have you checked this section of the readme?
Please take a look at the steps there as well as the example in the tests and let us know if it works for you, if something is not working correctly I would recommend opening a different issue to keep track of the problem :)
from graphql_devise.
Hi @00dav00, happy to open a different thread, though the issue is v similar: it is adding a new field to SignUp, though in my case I want a single endpoint. I have successfully followed instructions you linked to, have auth and my own schema in the same graph (yay!) however now that I want to add a new field to the sign-up mutation, I don't know what to do. The solution above does not work for reasons mentioned.
from graphql_devise.
Let's open a new issue @keithmgould. It would be helpful if you can post:
- The schema
- The inherited type
- The controller were the schema is added
- The error you are getting
And just to confirm, you need to remove the route if you want to have the auth operations in the same schema.
from graphql_devise.
Related Issues (20)
- Override `graphql_name` to allow for shared mutations HOT 2
- GraphQL::Schema::DuplicateNamesError HOT 5
- how to set current_resource for both authenticated and unauthenticated fields HOT 1
- Support for ruby-graphql v2 HOT 3
- A class must be provided when mounting a model. String values are no longer supported HOT 3
- Mount only necessary operations in existing schema. HOT 3
- Authenticate non-root fields HOT 6
- Cannot make it work with Mongoid HOT 5
- `context[:controller]` is nil when trying to login HOT 1
- Scoping auth tokens to more than one model HOT 1
- If expiry was in epoch seconds, it may be out of the range of INT. HOT 1
- Disable introspection HOT 1
- Support graphql v2.1 HOT 4
- NoMethodError: undefined method `resource=' for nil:NilClass HOT 5
- Add ability to customize raise_user_error_list and raise_user_error_list
- Add ability to customize raise_user_error_list method HOT 11
- Unable to set my message from #inactive_message method HOT 7
- NoMethodError: undefined method `case_insensitive_keys' for nil:NilClass HOT 5
- Is there a way to use the default devise template views? HOT 1
- Uninitialized constant `GraphqlDevise::SchemaPlugin` After trying to mount `graphql_devise` in my schema HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql_devise.