apollographql / router

A configurable, high-performance routing runtime for Apollo Federation 🚀
https://www.apollographql.com/docs/router/
Other
796 stars 265 forks source link

Input validation errors to match gateway #2984

Open smyrick opened 1 year ago

smyrick commented 1 year ago

Is your feature request related to a problem? Please describe. 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

Describe the solution you'd like Router includes parsing/serialization error locations when parsing variables and input.

macnibblet commented 1 year ago

I hole heartedly agree that this issue has a massive impact on developer productivity

goto-bus-stop commented 2 months ago

Can you share also the/a query that's used here? The error is about the input to a variable declared in the query.

e; it might just be this:

query ($params: MyInput) {
  getData(params: $params)
}
smyrick commented 2 months ago

@goto-bus-stop It is on the variable definition

Using Router 1.49.1

Schema

input MyInput {
  coordinates: CoordinatesInput
}

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

type Query {
  getData(params: MyInput): String
}

Query

query Test($argParams: MyInput) {
  getData(params: $argParams)
}

Variables

{
  "argParams": {
    "coordinates": {
      "latitude": 0,
      "longitude": true
    }
  }
}

Response

{
  "errors": [
    {
      "message": "invalid type for variable: 'argParams'",
      "extensions": {
        "name": "argParams",
        "code": "VALIDATION_INVALID_TYPE_VARIABLE"
      }
    }
  ]
}