evilmartians / chronicles-gql-martian-library

71 stars 36 forks source link

Fixed error with email variable in signIn mutation #15

Closed marcnjaramillo closed 4 years ago

marcnjaramillo commented 4 years ago

Hello,

First of all, I am really enjoying this tutorial. It's easy to read and follow, and having the complete repo as a reference is very helpful. While working through Part 2, I ran into an issue with the signIn mutation. I followed along and implemented everything correctly, but I kept seeing this error:

  "errors": [
    {
      "message": "Field 'signIn' is missing required arguments: input",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "mutation SignMeIn",
        "signIn"
      ],
      "extensions": {
        "code": "missingRequiredArguments",
        "className": "Field",
        "name": "signIn",
        "arguments": "input"
      }
    },
    {
      "message": "Field 'signIn' doesn't accept argument 'email'",
      "locations": [
        {
          "line": 2,
          "column": 10
        }
      ],
      "path": [
        "mutation SignMeIn",
        "signIn",
        "email"
      ],
      "extensions": {
        "code": "argumentNotAccepted",
        "name": "signIn",
        "typeName": "Field",
        "argumentName": "email"
      }
    },
    {
      "message": "Variable $email is declared by SignMeIn but not used",
      "locations": [
        {
          "line": 1,
          "column": 1
        }
      ],
      "path": [
        "mutation SignMeIn"
      ],
      "extensions": {
        "code": "variableNotUsed",
        "variableName": "email"
      }
    }
  ]
}

It took me a few hours, and I finally went into GraphiQL (this is my first time using GraphQL, so the tools are new to me) to test out the mutation. I noticed that signIn(email: on the second line was underlined in red. I hovered over and saw these two messages: Field "signIn" argument "input" of type "SignInMutationInput!" is required but not provided." (signIn), Unknown argument "email" on field "signIn" of type "Mutation". (email:).

I changed line 2 as you can see in the PR, and the error message went away. I went back into the development app and tried it out and it worked.

I hope this helps!

DmitryTsepelev commented 4 years ago

Hi @marcnjaramillo, thank you for the feedback!

I've tried to reproduce the issue locally and for some reason sign in works for me (I've just cloned the repo, no any local changes at all). There is a chance that the code in the guide is different from this repo (and we need to figure that out), could you please share what you have in your sign_in_mutation.rb?

In the implementation provided in this repo we have only one plain argument email, it's not wrapped with the input:

module Mutations
  class SignInMutation < Mutations::BaseMutation
    argument :email, String, required: true

  ...
marcnjaramillo commented 4 years ago

Hi Dimitry,

I think I just found the issue. I glazed over it (spent too much time staring at lines of code), but just spotted it clear as day.

When I ran rails generate graphql:install, my base_mutation.rb looks like this:

module Mutations
  class BaseMutation < GraphQL::Schema::RelayClassicMutation
    argument_class Types::BaseArgument
    field_class Types::BaseField
    input_object_class Types::BaseInputObject
    object_class Types::BaseObject
  end
end

while the same file in the tutorial repo looks like this:

module Mutations
  class BaseMutation < GraphQL::Schema::Mutation
  end
end

Further, in my /types there are three files that have code that the tutorial repo does not:

// base_field.rb
module Types
  class BaseField < GraphQL::Schema::Field
    argument_class Types::BaseArgument
  end
end

// base_input_object.rb
module Types
  class BaseInputObject < GraphQL::Schema::InputObject
    argument_class Types::BaseArgument
  end
end

// base_object.rb
module Types
  class BaseObject < GraphQL::Schema::Object
    field_class Types::BaseField
  end
end

I have no idea why my installation yielded such different results...my version of graphql in the Gemfile.lock matches that of the tutorial. My ruby version is 2.6.2, but I can't imagine that playing a role in it. Any ideas?

DmitryTsepelev commented 4 years ago

I think I've figured it out! At the moment when the second part of the tutorial was released, generator did not include the base_mutation at all (and in the tutorial we ask to create it manually). However, at the end of the October, base_mutation was added to the generator.

I'll update the article in a few days, thank you for catching that! I think that other generated classes should not affect the tutorial in any ways, but please let me know if you find something (or just freeze the graphql-ruby version, it was 1.19.6 at the moment of the tutorial release).

marcnjaramillo commented 4 years ago

It can be so hard to keep up with all of the changes that happen all the time. So many other tutorials have broken code and aren't maintained, which I get. Thanks for making the time for this!

DmitryTsepelev commented 4 years ago

We've updated the article, so I'm closing this PR, thanks again!