rmosolgo / rmosolgo/graphql-ruby
GraphQL::Schema::Validator::ValidationFailedError should include argument name and error description as separate fields
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 5.4k
- Forks
- 1.4k
- Avg merge
- 23h 19m
- Merged PRs (30d)
- 28
Description
Is your feature request related to a problem? Please describe.
Currently the ValidationFailedError class only provides access to the error details through the errors class attribute but this errors attribute is just an array of strings and its impossible to separate out the argument name and the error description without doing some regex on that those strings.
It is often useful to have the argument name separated out from the error description because API consumers need to know which argument had issues in a programmatic way.
This is what consumers of an API would receive today
{
"errors": [
{
"message": "lastName can't be blank",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"addUser"
]
}
]
}
This is what I believe API consumers should receive
{
"errors": [
{
"message": "lastName can't be blank",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"addUser"
],
"extensions": {
"code": "INPUT_ERROR",
"argument": "lastName",
"description": "can't be blank"
}
}
]
}
Describe the solution you'd like
Provide the argument name and description as separate class attributes on the ValidationFailledError class. I don't really care if it gets included in the "extensions" property as demonstrated above but including those attributes allows users of this library to include them in the extensions if they want to by using rescue_from and including the additional details.
Describe alternatives you've considered
The only alternative to adding this feature I believe is to parse out the argument name and description manually with regex. i.e.
if the error is "lastName can't be blank" then you would need to parse out "lastName" and "can't be blank" into separate variables.
Additional context
I would be happy to work on this feature if the library authors agree this is something they want to add. I believe this can be done in a non breaking way by leaving the current ValidationFailedError.errors class attribute the way it is and providing an additional attribute error_details or something similar that includes an array of hashes. error_details: [{ name: "lastName", description: "can't be blank" }]
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating GraphQL::Schema::Validator::ValidationFailedError and reading how its errors class attribute is populated. Determine how separate argument and description attributes should coexist with the existing errors array, then add coverage showing the two values can be accessed independently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, ruby
- Domain
- api
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100