-
Notifications
You must be signed in to change notification settings - Fork 1.2k
RFC: Add Schema Coordinate to GraphQL Errors #1200
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
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for graphql-spec-draft ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
This would really help us simplify error tracking! |
|
Adding the schema coordinate together with the existing |
|
After trying to actually implement walking the path to determine schema coordinate, it appears that the coordinate can be impossible to determine with certitude. If there is a Union or an Interface involved in the path, you will need to visit the result to know the actual type. But, in combination with non-nullable field, you have situations where can't determine the actual coordinate. Example: #schema.gql
interface Node {
id: String!,
}
type Query {
node(id: String!): Node!
}
type User implements Node {
id: String!,
}
type Comment implements Node {
id: String!,
}#query.gql
query {
node(id: 'a-user-id') {
id
__typename
}
}If an error occurs in the {
data: null,
errors: [{
message: 'An error occured',
path: ['node', 'id']
}]
}Now you have no way to determine if the coordinate is actually |
|
@EmrysMyrddin You're right but the security concern is still there, and if this schema coordinate property will be standard in the error object, then we should document this concern clearly. |
@EmrysMyrddin this is yet another use case for |
Add an optional
coordinatefield to GraphQL errors that contains the schema coordinate of the object field or field argument associated with the error, enabling direct identification of schema elements that caused runtime errors.📜 Problem Statement
When a GraphQL error occurs, developers must perform multiple steps to identify which type system member caused the error:
pathfield in the errorThis process is cumbersome and requires tooling to correlate runtime errors back to their schema definitions. While the
pathfield identifies where in the response the error occurred, it doesn't directly indicate which schema element is responsible for the error.Example
Consider this error response:
{ "errors": [ { "message": "Name for character with ID 1002 could not be fetched.", "locations": [{ "line": 6, "column": 7 }], "path": ["hero", "heroFriends", 1, "name"] } ] }To determine that this error originated from the
Human.namefield in the schema, developers must:["hero", "heroFriends", 1, "name"]heroFriendsreturns[Friend]Human.name💡 Proposed Solution
Add an optional
coordinatefield to GraphQL errors that directly references the object fiel or field argument where the error originated.Example
{ "errors": [ { "message": "Name for character with ID 1002 could not be fetched.", "locations": [{ "line": 6, "column": 7 }], "path": ["hero", "heroFriends", 1, "name"], "coordinate": "Human.name" } ] }In this example
coordinatedirectly identifiesHuman.namein the schema as the source, without requiring any parsing or traversalSimplified Error Tracking: Developers can immediately identify which schema element caused an error without complex analysis.
Better Tooling Support: IDEs, monitoring systems, and debugging tools can directly link errors to schema definitions.
The
coordinatefield should be included when:The
coordinatefield may be omitted when: