Skip to content

fix: pass object and list arguments of a nested field to the subgraph - #97

Open
mikaelkaron wants to merge 1 commit into
platformatic:mainfrom
mikaelkaron:fix/nested-field-args
Open

mikaelkaron wants to merge 1 commit into
platformatic:mainfrom
mikaelkaron:fix/nested-field-args

Conversation

@mikaelkaron

Copy link
Copy Markdown
Contributor

Fixes #69

The composer reads a nested field's arguments from the query's syntax tree, in collectNodeArgs (lib/utils.js), where it took node.value.value. Object and list values have no .value there, so an argument such as tags(where: { id: { eq: "1" } }) was dropped from the query sent to the subgraph, and every tag came back. Top-level fields were not affected, because graphql-js resolves their arguments before the composer sees them. A whole-object variable (tags(where: $where)) was not affected either.

Each value is now read with graphql's valueFromASTUntyped, which also fills in the variables inside it.

test/nested-args.test.js covers, on a nested field:

an inline object (the case from #69)
a list, an enum and an int (in: [...], orderBy: [{ direction: ASC }], limit: 1)
variables inside an inline object
a whole-object variable
Without the fix the first three fail. With it, npm test passes: lint plus 158 tests.

Assisted-by: Claude Code:claude-opus-5-5

The arguments of a nested field are collected from the query AST, where
an object or a list literal has no value of its own, so an argument such
as tags(where: { id: { eq: "1" } }) was dropped from the subquery and the
subgraph returned every tag. Collect each literal with
valueFromASTUntyped, which also resolves the variables inside it.

Fixes platformatic#69

Signed-off-by: Mikael Karon <mikael@karon.se>
Assisted-by: Claude Code:claude-opus-5-5

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

graphql-composer does not handle nesting when

1 participant