Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update utilites.ts to cover null case #5110

Merged
merged 6 commits into from
Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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