Repository navigation
fix(dang): send arguments on nested selection fields - #89
Merged
Merged
Conversation
Emit each outgoing GraphQL request payload via slog at debug level before it is sent. This makes it possible to see the exact query produced by the selection builder when running with --debug, which is invaluable when diagnosing query-construction bugs. Signed-off-by: Alex Suraci <[email protected]>
A field with both arguments and a nested selection inside an object
selection (e.g. repositories(first: 3).{nodes.{name}}) dropped its
arguments: buildGraphQLQuery built a field builder carrying the args, then
overwrote it with the nested selection builder. The mixed-selection query
builder also keys subselections by field name with no slot for their
arguments.
Fold the arguments into the field-name string the builder renders verbatim,
so repositories(first: 3) survives into the query. This also covers scalar
fields that take arguments but have no nested selection.
The bug was masked by the test server's optional pagination arguments, but
real connections like GitHub's repositories require first or last and
rejected the query outright.
Signed-off-by: Alex Suraci <[email protected]>
Deploying dang with
|
| Latest commit: |
6b2c4a6
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://fe36f786.dang-3kk.pages.dev |
| Branch Preview URL: | https://fix-nested-selection-args.dang-3kk.pages.dev |
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]>
fix(dang): point GraphQL errors at the failing field
The previous fix formatted nested-field arguments in the Dang layer and folded them into the field-name string handed to the query builder. That put GraphQL argument formatting and marshalling in the wrong place. Teach the query builder to render arguments attached to a nested selection: arguments are marshalled through the existing argument machinery, marshalling now recurses into subSelections, and a field's arguments are emitted on the field (stripped from the inner selection set so they aren't rendered twice). The Dang layer goes back to calling .Arg, including for scalar fields that only take arguments. Add query-builder tests covering nested arguments, an argument-only scalar field, and a field with both arguments and an inline-fragment selection. Signed-off-by: Alex Suraci <[email protected]>
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.
Problem
A field with both arguments and a nested selection inside an object selection had its arguments silently dropped. For example:
produced the query
viewer{login repositories{nodes{...}}}— note the missing(first: 3). Against GitHub this fails outright, since therepositoriesconnection requiresfirstorlast:Root cause
In
ObjectSelection.buildGraphQLQuery, the branch for a field with args + nested selection built a field builder carrying the args, then immediately overwrote it with the nested-selection builder (fieldBuilder = nestedResult), discarding the args. Structurally,SelectMixedkeys subselections by field name and renders that key verbatim, with no slot for arguments on nested fields.Fix
Fold the arguments into the field-name string the builder renders verbatim, so the map key becomes
repositories(first: 3). A newbuildFieldArgumentshelper marshals args viaquerybuilder.MarshalGQL. This also handles scalar fields that take arguments but have no nested selection.Unpacking is unaffected because it is AST-driven and binds the response blob — it does not depend on the querybuilder's subselection keys.
Why it wasn't caught
test_multiselect_args_graphql.dangexercises this exact pattern, but its assertions pass regardless because the test server's pagination arguments are all optional — dropping them still returns data. The newtest_nested_field_args_paginate.dangassertsposts(first: 1)returns exactly one post (the author has four), so it fails when the argument is dropped and passes once it's sent.Also included
feat(querybuilder): log GraphQL request at debug level— logs each outgoing query payload via slog, which is how the dropped argument was spotted directly under--debug.Testing
go test ./...passes. Verified end-to-end against GitHub's API with the github demo.