nuwave / nuwave/lighthouse

Providing an unknown field as if it were a list results in cryptic error

Open
#1,893 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
3.5k
Forks
468
Avg merge
3h 9m
Merged PRs (30d)
2

Description

When you provide an unknown field as if it were a list, rather than getting an error stating the field does not exist, you get the following error:

Argument 1 passed to GraphQL\Type\Definition\Type::getNullableType() must be an instance of GraphQL\Type\Definition\Type, null given, called in /src/vendor/webonyx/graphql-php/src/Validator/Rules/ValuesOfCorrectType.php on line 75

For example, I have this input type:

input SomeInput {
    name: String!
}

And in the query you add an unknown field like this:

{
  name: "Example"
  unknown: [
  ]
}

You'll get the error mentioned above.

However, if you add the unknown field like this:

{
  name: "Example"
  unknown: "Foo"
}

You simply get an error message stating "Field "unknown" is not defined by type SomeInput."

I would expect in both cases to get the error "Field "unknown" is not defined by type SomeInput.".

Steps to reproduce

  1. Create any input type
  2. Provide an extra field that is not present in the input type, and make it's value a list
  3. View error

v5.6.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with an input type containing name and an unknown list-valued field, then inspect the validation path at vendor/webonyx/graphql-php/src/Validator/Rules/ValuesOfCorrectType.php around line 75. Compare it with the unknown scalar-field case. Done means both forms report that the field is not defined by type SomeInput.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.