Description
Current limitation:
With the proposed changes to the RFC in #230 that are already implemented in graphql-js, it is only possible to determine which field caused an error. (Unless I am missing something?)
If you want to implement input validation with custom constraints for specific arguments, there is no way for the client to tell which input argument value is invalid with the current spec, especially if we have input values that contain lists or other complex objects.
Possible usecases:
If we would have a standardized way to process input errors, this would open up the possibility to create standard compliant libraries with server side form validation or generate complete forms and admin interfaces based on introspection queries.
Example:
Given the following schema:
# Input object type for createUser mutation
input MutationInput {
username: String!
categories: [ID!]!
}
# Mutation type
type Mutation {
createUser(input: MutationInput!): ID!
}
Executed query:
# Query:
mutation CreateUser($input: MutationInput!) {
createUser(input: $input)
}
# Variables
{
input: {
username: "invalidusername",
categories: [ "1", "2", "someinvalidid" ]
}
}
This could result in a response like this:
{
"data": null,
"errors": [
{
"message": "Input validation failed",
"path": ["createUser"],
// If the error was caused by one or more argument values on that field
// we have a list with errors that each contain a human readable message
// and the path within the field arguments to the value that caused the error
"argumentErrors": [
{
"message": "Please provide a valid category ID",
// We use 0-indexed path values for list input values
"path": [ "input", "categories", 2 ]
},
{
"message": "Please provide a valid username",
"path": [ "input", "username" ]
}
]
}
]
}
This is just a quick draft. I would like to know what you think of the idea.