Git Product home page Git Product logo

Comments (14)

00dav00 avatar 00dav00 commented on May 18, 2024 6

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.

mcelicalderon avatar mcelicalderon commented on May 18, 2024 3

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.

mcelicalderon avatar mcelicalderon commented on May 18, 2024 3

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.

mcelicalderon avatar mcelicalderon commented on May 18, 2024 2

Reopening this so I don't forget to implement

from graphql_devise.

Gakamine avatar Gakamine commented on May 18, 2024 1

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.

aarona avatar aarona commented on May 18, 2024 1

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.

aarona avatar aarona commented on May 18, 2024

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.

lassiter avatar lassiter commented on May 18, 2024

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?

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

mcelicalderon avatar mcelicalderon commented on May 18, 2024

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.

keithmgould avatar keithmgould commented on May 18, 2024

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.

keithmgould avatar keithmgould commented on May 18, 2024

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.

00dav00 avatar 00dav00 commented on May 18, 2024

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.

keithmgould avatar keithmgould commented on May 18, 2024

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.

00dav00 avatar 00dav00 commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.