Skip to content

Commit

Permalink
Add tests for #1346 (#1392)
Browse files Browse the repository at this point in the history
* Add tests for #1346

* Remove unnecessary dep

* Fix format
  • Loading branch information
ardatan committed Apr 23, 2020
1 parent daed81b commit 6ee1613
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions src/test/makeRemoteExecutableSchema.test.ts
@@ -1,10 +1,13 @@
/* eslint-disable */
import { forAwaitEach } from 'iterall';
import {
GraphQLSchema,
ExecutionResult,
subscribe,
parse,
graphql,
execute,
print,
} from 'graphql';

import { makeRemoteExecutableSchema } from '../wrap/index';
Expand Down Expand Up @@ -191,4 +194,83 @@ describe('respects buildSchema options', () => {
const customScalar = remoteSchema.getType('CustomScalar');
expect(customScalar.description).toBe('Scalar description');
});

describe('when query for multiple fields', () => {
const schema = `
type Query {
fieldA: Int!
fieldB: Int!
field3: Int!
}
`;
const query = parse(`
query {
fieldA
fieldB
field3
}
`);
let calls: Array<any> = [];
const fetcher = (args: any) => {
calls.push(args);
return Promise.resolve({
data: {
fieldA: 1,
fieldB: 2,
field3: 3,
},
});
};
const remoteSchema = makeRemoteExecutableSchema({
fetcher,
schema,
});

beforeEach(() => {
calls = [];
});

// One of the two tests below should work depending upon what the correct intended behaviour is
it.skip('forwards one upstream query', async () => {
const result = await execute(remoteSchema, query);
expect(result).toEqual({
data: {
fieldA: 1,
fieldB: 2,
field3: 3,
},
});

expect(calls).toHaveLength(1);
expect(print(calls[0].query)).toEqual(print(query));
});

it('forwards three upstream queries', async () => {
const result = await execute(remoteSchema, query);
expect(result).toEqual({
data: {
fieldA: 1,
fieldB: 2,
field3: 3,
},
});

expect(calls).toHaveLength(3);
expect(print(calls[0].query)).toEqual(`\
{
fieldA
}
`);
expect(print(calls[1].query)).toEqual(`\
{
fieldB
}
`);
expect(print(calls[2].query)).toEqual(`\
{
field3
}
`);
});
});
});

0 comments on commit 6ee1613

Please sign in to comment.