Repository navigation
fix(dang): point GraphQL errors at the failing field - #90
Merged
Merged
Conversation
When a GraphQL query built from an object selection failed, the error
highlighted the whole selection (the receiver's `.{`) rather than the field
the server actually rejected. For example, a server complaining about
`repositories` pointed at `viewer.{` several lines up.
GraphQL execution errors carry a machine-readable path identifying the
field. Extract that path, walk the selection tree to find the deepest
matching field, and attach its source location so the error highlights the
offending field. When no path is present the previous behaviour is kept.
Add a unit test for the path extraction and tree walk, plus an error test
backed by a new alwaysFails field on the test server's User type so a field
nested inside a selection can fail server-side.
Signed-off-by: Alex Suraci <[email protected]>
Deploying dang with
|
| Latest commit: |
d3a5779
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://818df30d.dang-3kk.pages.dev |
| Branch Preview URL: | https://improve-graphql-field-errors.dang-3kk.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #89 — review/merge that first; GitHub will retarget this to
mainonce it lands.Problem
When a GraphQL query built from an object selection failed, the error highlighted the whole selection (the receiver's
.{) instead of the field the server actually rejected:The caret points at
viewer.{(line 3), but the offending field isrepositoriesseveral lines down.Fix
GraphQL execution errors carry a machine-readable
path(["viewer", "repositories"]).evalGraphQLSelectionnow:gqlerror.List(graphqlErrorFieldPath).locateErrorField), skipping leading segments like the receiver.ObjectSelection.evalGraphQLSelection:prefix also drops away for this case.When the error carries no path, the previous behaviour is preserved.
Now:
Tests
pkg/dang/graphql_error_test.go— unit tests for path extraction (names, indices, wrapping) and the tree walk (receiver skip, nested descent, deepest-known-field, no match).tests/errors/graphql_field_error.dang+ golden — end-to-end error test. Backed by a newalwaysFailsfield on the test server'sUsertype so a field nested inside a selection can fail server-side. Verified the golden points at the whole selection (with the noisy prefix) before the fix and atalwaysFailsafter.go test ./...passes.