Skip to content

Commit

Permalink
fix(delegate): visit list values to collect variables
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Aug 6, 2021
1 parent 3c88831 commit d47dcf4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/breezy-gifts-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/delegate': patch
---

fix(delegate): visit list values to collect variables
1 change: 1 addition & 0 deletions packages/delegate/src/finalizeGatewayRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ const variablesVisitorKeys: Partial<VisitorKeyMap<ASTKindToNode>> = {
ObjectValue: ['fields'],
ObjectField: ['name', 'value'],
Directive: ['arguments'],
ListValue: ['values'],
};

function finalizeSelectionSet(
Expand Down
27 changes: 26 additions & 1 deletion packages/delegate/tests/finalizeGatewayRequest.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { print, parse } from 'graphql';
import { DelegationContext } from '@graphql-tools/delegate';
import { bookingSchema } from '../../wrap/tests/fixtures/schemas';
import { bookingSchema, propertySchema } from '../../wrap/tests/fixtures/schemas';
import { finalizeGatewayRequest } from '../src/finalizeGatewayRequest';

describe('finalizeGatewayRequest', () => {
Expand Down Expand Up @@ -71,6 +71,31 @@ describe('finalizeGatewayRequest', () => {
expect(print(filteredQuery.document)).toBe(print(expected));
});

test('should not remove used variables in nested inputs', () => {
const query = parse(`
query jsonTestQuery($test: String!) {
jsonTest(input: [{ test: $test }] )
}
`);
const filteredQuery = finalizeGatewayRequest({
document: query,
variables: {
test: 'test',
},
operationType: 'query' as const,
}, {
targetSchema: propertySchema
} as DelegationContext);

const expected = parse(`
query jsonTestQuery($test: String!) {
jsonTest(input: [{ test: $test }] )
}
`);
expect(filteredQuery.variables).toEqual({ test: 'test' })
expect(print(filteredQuery.document)).toBe(print(expected));
});

test('should remove empty selection sets on wrapped objects (non-nullable/lists)', () => {
const query = parse(`
query bookingQuery($id: ID!) {
Expand Down

1 comment on commit d47dcf4

@vercel
Copy link

@vercel vercel bot commented on d47dcf4 Aug 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.