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

Compiler incorrectly reports missing required fields #4122

Closed
beaumontjonathan opened this issue Nov 13, 2022 · 0 comments
Closed

Compiler incorrectly reports missing required fields #4122

beaumontjonathan opened this issue Nov 13, 2022 · 0 comments

Comments

@beaumontjonathan
Copy link
Contributor

Description

When checking for valid input objects, the compiler incorrectly reports that required fields are missing if they come after fields which are of the incorrect type. This makes tracking down incorrect types more difficult, especially in the case of incorrect of modified enum values.

Example

https://codesandbox.io/s/nervous-mendeleev-88r0yi?file=/client/src/App.jsx:297-325

Schema

input NewUserInput {
  name: String!
  age: String!
}

mutation {
  newUser(input: NewUserInput!): User
}

Current behaviour A (correct ✅)

Query

mutation AppMutation($name: String! $age: Float!) {
  newUser(input: { name: $name, age: $age }
}

Compiler output

[ERROR] Error in the project `default`: ✖︎ Variable was defined as type 'Float!' but used where a variable of type 'String!' is expected.

  client/src/App.jsx:10:44
    9 │       mutation AppMutation($name: String!, $age: Float!) {
   10 │         newUser(input: { name: $name, age: $age }) {
      │                                            ^^^^
   11 │           id

[ERROR] Compilation failed.
[ERROR] Unable to run relay compiler. Error details:
Failed to build:
 - Validation errors:
 - Variable was defined as type 'Float!' but used where a variable of type 'String!' is expected.:client/src/App.jsx:103:107

Current behaviour B (incorrect ❎)

Query

mutation AppMutation($name: String! $age: Float!) {
  newUser(input: { age: $age, name: $name }
}

Compiler output

[ERROR] Error in the project `default`: ✖︎ Missing required fields '["name"]' of type 'NewUserInput'

  client/src/App.jsx:10:24
    9 │       mutation AppMutation($name: String!, $age: Float!) {
   10 │         newUser(input: { age: $age, name: $name }) {
      │                        ^^^^^^^^^^^^^^^^^^^^^^^^^^
   11 │           id

[ERROR] Compilation failed.
[ERROR] Unable to run relay compiler. Error details:
Failed to build:
 - Validation errors:
 - Missing required fields '["name"]' of type 'NewUserInput':client/src/App.jsx:83:109
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

Successfully merging a pull request may close this issue.

1 participant