From 6ee1613feb8077798808251bf060a1822fa39a67 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU <20847995+ardatan@users.noreply.github.com> Date: Thu, 23 Apr 2020 13:05:14 +0300 Subject: [PATCH] Add tests for #1346 (#1392) * Add tests for #1346 * Remove unnecessary dep * Fix format --- src/test/makeRemoteExecutableSchema.test.ts | 82 +++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/src/test/makeRemoteExecutableSchema.test.ts b/src/test/makeRemoteExecutableSchema.test.ts index 909330c5ca0..77c81e03496 100644 --- a/src/test/makeRemoteExecutableSchema.test.ts +++ b/src/test/makeRemoteExecutableSchema.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable */ import { forAwaitEach } from 'iterall'; import { GraphQLSchema, @@ -5,6 +6,8 @@ import { subscribe, parse, graphql, + execute, + print, } from 'graphql'; import { makeRemoteExecutableSchema } from '../wrap/index'; @@ -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 = []; + 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 +} +`); + }); + }); });