Skip to content

Missing coercion or validation for default values #3248

@eapache

Description

@eapache

Describe the bug

@benjie pointed out in graphql/graphql-spec#793 that the GraphQL Spec and JS reference implementations are both somewhat confusing/broken when dealing with mistyped default values. I haven't gone through and tried to reproduce all the various combinations of this issue, but I did demonstrate a simple case to show that graphql-ruby suffers from at least a similar class of bug.

Versions

graphql version: 1.11.4 w/ interpreter, but I'm pretty sure it applies to master too

GraphQL schema

  field :test, :integer, null: true do |field|
    field.argument(:arg, :integer, required: true, default_value: "string")
  end

  def test(arg:)
    arg
  end

GraphQL query

query {
  test
}
{
  "data": {
    "test": null
  }
}

Expected vs actual behaviour

There are two interesting points in this example:

  • GraphiQL actually says the sample query is invalid; apparently the default_value is not making it through into the introspection output, so GraphiQL claims the argument needs a value. However, if you actually run it then it works (sorta).
  • When you run it, the default_value doesn't make it through into the resolver method, which gets nil instead. This could really mess with resolver code which assumes a value (since the argument is required-with-a-default at the GraphQL layer).

@rmosolgo there is still some debate on what the final specified behaviour should be, but I wanted to put this on your radar. The fact that the default value is getting stripped out in places suggests to me that we are validating it already somewhere, we're just not handling validation failures aggressively enough?

cc @swalkinshaw.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions