graphql-anywhere
Version:
Run GraphQL queries with no schema and just one resolver
52 lines (41 loc) • 1.11 kB
text/typescript
import gql from 'graphql-tag';
import graphql from '../';
describe('directives', () => {
it('skips a field that has the skip directive', () => {
const resolver = () => {
throw new Error('should not be called');
};
const query = gql`
{
a (if: true)
}
`;
const result = graphql(resolver, query);
expect(result).toEqual({});
});
it('includes info about arbitrary directives', () => {
const resolver = (fieldName, root, args, context, info) => {
const { doSomethingDifferent } = info.directives;
let data = root[info.resultKey];
if (doSomethingDifferent) {
if (doSomethingDifferent.but === 'notTooCrazy') {
return data;
}
return undefined;
}
return data;
};
const input = {
a: 'something',
b: 'hidden',
};
const query = gql`
{
a (but: notTooCrazy)
b (but: nope)
}
`;
const result = graphql(resolver, query, input);
expect(result).toEqual({ a: 'something' });
});
});