You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When TransformQuery is used with a too generic path which might also match an attribute in the subtree, users get unexpected results when using fragments:
For example using TransformQuery with path ['editorialCategory'] transform both matches the query and the fragment:
The problem is probably in this section: The visitor needs an indication if it currently in the root query or the fragment, als in both cases the index is set to 1:
awaitdelegateToSchema({schema: subschemafieldName: 'editorialCategory',args: { id },
context,
info,transforms: [// Wrap document takes a subtree as an AST nodenewTransformQuery({// path at which to apply wrapping and extractingpath: ['editorialCategory'],queryTransformer: (subtree: SelectionSetNode)=>({kind: Kind.SELECTION_SET,selections: [{kind: Kind.FIELD,name: {kind: Kind.NAME,value: 'programSets',},selectionSet: {kind: Kind.SELECTION_SET,selections: [{// we create a wrapping AST Fieldkind: Kind.FIELD,name: {kind: Kind.NAME,value: 'nodes',},// Inside the field selectionselectionSet: subtree,},],},},],}),// how to process the data result at pathresultTransformer: (result)=>result?.programSets?.nodes,errorPathTransformer: (path)=>path.slice(2),}),]});
Describe the bug
When
TransformQuery
is used with a too genericpath
which might also match an attribute in the subtree, users get unexpected results when using fragments:For example using TransformQuery with path
['editorialCategory']
transform both matches the query and the fragment:The problem is probably in this section: The visitor needs an indication if it currently in the root query or the fragment, als in both cases the index is set to
1
:graphql-tools/packages/wrap/src/transforms/TransformQuery.ts
Lines 49 to 78 in 343e697
Example delegateToSchema call using transform
To Reproduce
Steps to reproduce the behaviour:
Query A, which triggers path matching bug
Query B, with workaround for path matching bug
Expected behavior
Environment:
Additional context
The text was updated successfully, but these errors were encountered: