apollographql / apollo-rs

Spec compliant GraphQL Tools in Rust.
Apache License 2.0
574 stars 45 forks source link

Verbose validation errors to match graphql-js #874

Closed smyrick closed 4 months ago

smyrick commented 4 months ago

Recreating the issue from the Router since this is where validation happens now: https://github.com/apollographql/router/issues/2984

Description

Previously on the Gateway, operation validation errors would be verbose about the serialization issues, in particular with input and arguments.

For example here is the error message from Gateway on passing null to a Float! inside a nested param block

type Query {
  getData(params: MyInput)
}

input MyInput {
  coordinates: CoordinatesInput
  # ...many other input options
}

input CoordinatesInput {
  latitude: Float!
  longitude: Float!
}

Variable "$params" got invalid value null at "params.coordinates.latitude"; Expected non-nullable type "Float!" not to be null.

This is clear on what the error is and where is needs to be fixed.

In the Router all we get back is this:

invalid type for variable: 'params'

When the input arguments are large this can be much more problematic to debug and find where within params the error occurred

Possible Solutions

Router includes parsing/serialization error locations when parsing variables and input.

goto-bus-stop commented 4 months ago

Since this is about variables, this actually should be addressed in the router. It's not a validation error but an execution error. The query is valid, but the JSON inputs in the HTTP request are not.