Subject: [PATCH] trying to test --- Index: packages/delegate/tests/finalizeGatewayRequest.break.test.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/packages/delegate/tests/finalizeGatewayRequest.break.test.ts b/packages/delegate/tests/finalizeGatewayRequest.break.test.ts new file mode 100644 --- /dev/null (date 1672844770246) +++ b/packages/delegate/tests/finalizeGatewayRequest.break.test.ts (date 1672844770246) @@ -0,0 +1,70 @@ +import { print, parse } from 'graphql'; +import { DelegationContext } from '@graphql-tools/delegate'; +import { bookingSchema } from '../../testing/fixtures/schemas.js'; +import { finalizeGatewayRequest } from '../src/finalizeGatewayRequest.js'; + +describe('finalizeGatewayRequest', () => { + test('should remove empty selection sets on objects', () => { + const query = parse(/* GraphQL */ ` + mutation MyMutation { + testMutation { + query { + ...FooingFragment + } + } + } + + fragment FooingFragment on Query { + foo { + ... on Fooing { + pk + } + ... on Bar { + bar + } + + ... on Baz { + baz + } + } + } + `); + const filteredQuery = finalizeGatewayRequest( + { + document: query, + variables: {}, + }, + { + targetSchema: bookingSchema, + } as DelegationContext + ); + + const expected = parse(/* GraphQL */ ` + mutation MyMutation { + testMutation { + query { + ...FooingFragment + } + } + } + + fragment FooingFragment on Query { + foo { + ... on Fooing { + pk + __typename + } + ... on Bar { + bar + } + + ... on Baz { + baz + } + __typename + } + } + `); + expect(print(filteredQuery.document)).toBe(print(expected)); + }); +}); Index: packages/testing/fixtures/schemas.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/packages/testing/fixtures/schemas.ts b/packages/testing/fixtures/schemas.ts --- a/packages/testing/fixtures/schemas.ts (revision e7fe51cda2759232c90b6701ea11811d3a34cb18) +++ b/packages/testing/fixtures/schemas.ts (date 1672834191738) @@ -489,12 +489,26 @@ licensePlate: String } + interface Fooing { + pk: ID + } + + type Bar implements Fooing { + pk: ID + bar: String + } + type Baz implements Fooing { + pk: ID + baz: String + } + type Query { bookingById(id: ID!): Booking bookingsByPropertyId(propertyId: ID!, limit: Int): [Booking!] customerById(id: ID!): Customer bookings(limit: Int): [Booking!] customers(limit: Int): [Customer!] + foo: Fooing } input BookingInput { @@ -504,8 +518,13 @@ endTime: DateTime! } + type TMReturn { + query: Query + } + type Mutation { addBooking(input: BookingInput): Booking + testMutation(input: ID): TMReturn } `; @@ -535,6 +554,12 @@ const list = Object.values(sampleData.Customer); return limit ? list.slice(0, limit) : list; }, + foo(_parent) { + return { + pk: 'ID', + baz: 'baz', + }; + }, }, Mutation: { @@ -547,6 +572,16 @@ endTime, }; }, + testMutation(_parent) { + return { + query: { + important: { + pk: 'ID', + baz: 'baz', + }, + }, + }; + }, }, Booking: {