Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking change in 1.12.6: Int variable no longer accepted for ID argument #3418

Closed
RobinDaugherty opened this issue Mar 30, 2021 · 1 comment

Comments

@RobinDaugherty
Copy link
Contributor

RobinDaugherty commented Mar 30, 2021

Describe the bug

#3370 fixed a bug with input object argument validation.

Prior to this fix, an Int variable could be passed for an ID-type argument, and it would succeed. As of the change in #3370, which was released in 1.12.6, this will now result in an error:

{"message"=>"Type mismatch on variable $id and argument id (Int! / ID!)", "locations"=>[{"line"=>2, "column"=>31}], "path"=>["mutation Xxx", "xxx", "input", "id"], "extensions"=>{"code"=>"variableMismatch", "variableName"=>"id", "typeName"=>"Int!", "argumentName"=>"id", "errorMessage"=>"Type mismatch"}}

Versions

graphql version: 1.12.6
rails (or other framework): 6.1.2.1
newrelic_rpm 6.15.0 included via use(GraphQL::Tracing::NewRelicTracing, set_transaction_name: true)

GraphQL schema

Are you using interpreter?

Yes.

Any custom instrumentation, etc?

New Relic (listed above)

Here's a stripped-down example of the mutation clas:

class TestMutation < BaseMutation
  field :success, Boolean, null: true
  argument :id, ID, required: true
  def resolve(id:)
    { success: true }
  end
end

class MutationType < Types::BaseObject
  field :test, mutation: TestMutation
end

GraphQL query

Example GraphQL query and response

mutation Test($id: Int!) {
  test(input: {id: $id) {
    success
  }
}

With 1.12.5

{
  "data": {
    "test": { "success" : true }
  }
}

With 1.12.6

{
  "errors" : [
    {
      "path" : [
        "mutation Test",
        "test",
        "input",
        "id"
      ],
      "message" : "Type mismatch on variable $id and argument id (Int! / ID!)",
      "extensions" : {
        "code" : "variableMismatch",
        "typeName" : "Int!",
        "argumentName" : "id",
        "variableName" : "id",
        "errorMessage" : "Type mismatch"
      },
      "locations" : [
        {
          "line" : 2,
          "column" : 31
        }
      ]
    }
  ]
}

Steps to reproduce

  1. Use graphql gem version 1.12.6
  2. Create a mutation that accepts an ID! argument
  3. Execute the mutation with an argument of type Int!

Expected behavior

Behavior before 1.12.6 was to accept the Int variable as an ID type.

Actual behavior

As of 1.12.6, this results in an error.

This might conform better to the GraphQL spec, but it's unexpected in a patch version, since it breaks backward compatibility.

Additional context

This only affects variables passed to ID! arguments. You can still pass an integer value for an ID! argument, and this succeeds in 1.12.6.

mutation {
  test(input: {id: 5) {
    success
  }
}
@RobinDaugherty RobinDaugherty changed the title Breaking change in 1.12.6: Int! variable no longer accepted for ID! argument Breaking change in 1.12.6: Int variable no longer accepted for ID argument Mar 30, 2021
@rmosolgo
Copy link
Owner

Sorry for the unpleasant surprise 😖 I don't plan to revert the change, since, as you noted, it's a fix to properly implement the specification. However, I updated the changelog in dcd0e11 to alert any future readers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants