From c5d5c8dfed74ee3dce8e1235a19b07c4b755d1a2 Mon Sep 17 00:00:00 2001 From: Aaron Reisman Date: Wed, 4 Sep 2019 03:22:04 -0700 Subject: [PATCH] Update utilites.ts to cover null case (#5110) * Update utilites.ts * fix edge case when data is resolved to null * Update packages/graphql-anywhere/src/__tests__/utilities.ts Co-Authored-By: Carlo Palinckx --- packages/graphql-anywhere/src/__tests__/utilities.ts | 6 +++++- packages/graphql-anywhere/src/utilities.ts | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/graphql-anywhere/src/__tests__/utilities.ts b/packages/graphql-anywhere/src/__tests__/utilities.ts index a993a8edbaa..ab33030421c 100644 --- a/packages/graphql-anywhere/src/__tests__/utilities.ts +++ b/packages/graphql-anywhere/src/__tests__/utilities.ts @@ -108,7 +108,11 @@ describe('utilities', () => { expect(filter(doc, arrayData)).toEqual(filteredArrayData); }); - it('can filter data for fragments ', () => { + it('can short circuit when data is null', () => { + expect(filter(doc, null)).toEqual(null); + }); + + it('can filter data for fragments', () => { expect(filter(fragment, data)).toEqual(filteredData); }); diff --git a/packages/graphql-anywhere/src/utilities.ts b/packages/graphql-anywhere/src/utilities.ts index 732f7e92598..b71c1a0c49c 100644 --- a/packages/graphql-anywhere/src/utilities.ts +++ b/packages/graphql-anywhere/src/utilities.ts @@ -13,6 +13,8 @@ export function filter( data: D, variableValues: VariableMap = {}, ): FD { + if (data === null) return data; + const resolver = ( fieldName: string, root: any, @@ -63,7 +65,8 @@ function hasVariableInclusions( directives: ReadonlyArray, ): boolean { return getInclusionDirectives(directives).some( - ({ ifArgument }) => ifArgument.value && ifArgument.value.kind === 'Variable', + ({ ifArgument }) => + ifArgument.value && ifArgument.value.kind === 'Variable', ); }