Skip to content

better error handling for required fields in an input object #1967

@modosc

Description

@modosc

consider something like:

input FooInput {
  bar: BarInput!
}
input BarInput {
  baz: BazInput!
}
input BazInput {
  bat: String!
}

if i leave out bat from my input i get an error like:

{      "message": "Argument 'baz' on InputObject 'BarInput' has an invalid value. Expected type 'BazInput!'.",
      "locations": [
        {
          "line": null,
          "column": null
        }
      ],
      "fields": [
        "mutation FooMutation",
        "fooMutation",
        "input",
        "bar",
        "baz"
      ]
    },

(sorry this may not be exact, i'm transposing from a work project)

i'd expect the missing required field (bat) to be the field referenced in the error message and the path, but currently that's not the case. i think the issue is here:

https://github.com/rmosolgo/graphql-ruby/blob/master/lib/graphql/static_validation/literal_validator.rb#L26

since there's no actual ast node for the missing field, the error message that's generated comes from the parent input object.

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