Skip to content

Commit

Permalink
Update utilites.ts to cover null case (#5110)
Browse files Browse the repository at this point in the history
* 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 <carlopalinckx@gmail.com>
  • Loading branch information
2 people authored and hwillson committed Sep 4, 2019
1 parent cbdf03a commit c5d5c8d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/graphql-anywhere/src/__tests__/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
5 changes: 4 additions & 1 deletion packages/graphql-anywhere/src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export function filter<FD = any, D extends FD = any>(
data: D,
variableValues: VariableMap = {},
): FD {
if (data === null) return data;

const resolver = (
fieldName: string,
root: any,
Expand Down Expand Up @@ -63,7 +65,8 @@ function hasVariableInclusions(
directives: ReadonlyArray<DirectiveNode>,
): boolean {
return getInclusionDirectives(directives).some(
({ ifArgument }) => ifArgument.value && ifArgument.value.kind === 'Variable',
({ ifArgument }) =>
ifArgument.value && ifArgument.value.kind === 'Variable',
);
}

Expand Down

0 comments on commit c5d5c8d

Please sign in to comment.