Skip to content

Commit

Permalink
Fixing error when filtering or generating propTypes for fragments wit…
Browse files Browse the repository at this point in the history
…h variables
  • Loading branch information
Jonathan Felchlin committed Mar 1, 2019
1 parent 660042f commit 1902939
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 15 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/graphql-anywhere/src/__tests__/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('directives', () => {
}
`;

const result = graphql(resolver, query);
const result = graphql(resolver, query, '', null, {});

expect(result).toEqual({});
});
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('directives', () => {
}
`;

const result = graphql(resolver, query, input);
const result = graphql(resolver, query, input, null, {});

expect(result).toEqual({ a: 'something' });
});
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-anywhere/src/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ const execute = (graphql, r) => () => {
}
`;

const result = await graphql(resolver, query, null, null, null);
const result = await graphql(resolver, query, null, null, {});

expect(result).toEqual({
a: {
Expand Down
36 changes: 35 additions & 1 deletion packages/graphql-anywhere/src/__tests__/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import gql, { disableFragmentWarnings } from 'graphql-tag';
// Turn off warnings for repeated fragment names
disableFragmentWarnings();

import { filter, check } from '../utilities';
import { filter, check, propType } from '../utilities';

describe('utilities', () => {
describe('with a single query', () => {
Expand All @@ -16,6 +16,24 @@ describe('utilities', () => {
}
}
`;
const fragment = gql`
fragment foo on Foo {
alias: name
height(unit: METERS)
avatar {
square
}
}
`;
const fragmentWithAVariable = gql`
fragment foo on Foo {
alias: name
height(unit: METERS)
avatar @include(if: $foo) {
square
}
}
`;
const data = {
alias: 'Bob',
name: 'Wrong',
Expand Down Expand Up @@ -80,6 +98,22 @@ describe('utilities', () => {
expect(filter(doc, arrayData)).toEqual(filteredArrayData);
});

it('can filter data for fragments ', () => {
expect(filter(fragment, data)).toEqual(filteredData);
});

it('can filter data for fragments with variables', () => {
expect(filter(fragmentWithAVariable, data)).toEqual(filteredData);
});

it('can generate propTypes for fragments', () => {
expect(propType(fragment)).toEqual(expect.any(Function));
});

it('can generate propTypes for fragments with variables', () => {
expect(propType(fragmentWithAVariable)).toEqual(expect.any(Function));
});

it('can check matching data', () => {
check(doc, filteredData);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/graphql-anywhere/src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ function executeSelectionSet(
const result = {};

selectionSet.selections.forEach(selection => {
if (!shouldInclude(selection, variables)) {
// Skip this entirely
if (variables && !shouldInclude(selection, variables)) {
// Skip selection sets which we're able to determine should not be run
return;
}

Expand Down

0 comments on commit 1902939

Please sign in to comment.