From 750b9dddad42200c02de97ad3ea2b601caed1bcd Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Thu, 23 Apr 2020 12:57:30 +0300 Subject: [PATCH] Add tests for #1346 --- package.json | 1 + src/test/makeRemoteExecutableSchema.test.ts | 82 +++++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/package.json b/package.json index e301c260cc7..256b8a11747 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "dependencies": { "apollo-link": "^1.2.14", "apollo-upload-client": "^13.0.0", + "dataloader": "2.0.0", "deprecated-decorator": "^0.1.6", "form-data": "^3.0.0", "iterall": "^1.3.0", diff --git a/src/test/makeRemoteExecutableSchema.test.ts b/src/test/makeRemoteExecutableSchema.test.ts index 909330c5ca0..281cb62b4ba 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 +} +`); + }); + }); });