From 6a64df8e8961c898f8a6c7a8ac34d365ecb989c5 Mon Sep 17 00:00:00 2001 From: axelhildingson Date: Sat, 21 Aug 2021 09:58:02 +0200 Subject: [PATCH 1/2] inital test that shows the bug --- spec/ParseGraphQLServer.spec.js | 70 +++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/spec/ParseGraphQLServer.spec.js b/spec/ParseGraphQLServer.spec.js index b8673cbe22..3aa31b27a6 100644 --- a/spec/ParseGraphQLServer.spec.js +++ b/spec/ParseGraphQLServer.spec.js @@ -10219,6 +10219,7 @@ describe('ParseGraphQLServer', () => { userEcho(user: CreateUserFieldsInput!): User! @resolve hello3: String! @mock(with: "Hello world!") hello4: User! @mock(with: { username: "somefolk" }) + arrayOfSuperCar: [SuperCar] @resolve(to: "arrayOfSuperCar") } `, }); @@ -10260,6 +10261,75 @@ describe('ParseGraphQLServer', () => { expect(result.data.hello).toEqual('Hello world!'); }); + it('can resolve a custom query, that returns an array', async () => { + Parse.Cloud.define('helloArray', async () => { + return ['Hello', 'world!']; + }); + + const result = await apolloClient.query({ + query: gql` + query HelloArray { + helloArray + } + `, + }); + + expect(result.data.helloArray).toEqual(['Hello', 'world!']); + }); + + fit('can resolve a custom query, that returns an array', async () => { + const schemaController = await parseServer.config.databaseController.loadSchema(); + + await schemaController.addClassIfNotExists('SuperCar', { + engine: { type: 'String' }, + doors: { type: 'Number' }, + price: { type: 'String' }, + mileage: { type: 'Number' }, + gears: { type: 'Array' }, + }); + + await new Parse.Object('SuperCar').save({ + engine: 'petrol', + doors: 3, + price: '£7500', + mileage: 0, + gears: ['1', '2', '3', '4'], + }); + + await new Parse.Object('SuperCar').save({ + engine: 'petrol', + doors: 3, + price: '£7500', + mileage: 10000, + gears: ['1', '2', '3', '4', '5'], + }); + + await Promise.all([ + parseGraphQLServer.parseGraphQLController.cacheController.graphQL.clear(), + parseGraphQLServer.parseGraphQLSchema.schemaCache.clear(), + ]); + + Parse.Cloud.define('arrayOfSuperCar', async () => { + const superCars = await new Parse.Query('SuperCar').find({ useMasterKey: true }); + return superCars; + }); + const result = await apolloClient.query({ + query: gql` + query FindSuperCar { + arrayOfSuperCar { + objectId + gears { + ... on Element { + value + } + } + } + } + `, + }); + expect(result.data.superCars.gears[2].value).toEqual('3'); + }); + it('can resolve a custom query using function name set by "to" argument', async () => { Parse.Cloud.define('hello', async () => { return 'Hello world!'; From e6e604330468ec20c82b856e6e945f691a1d0c5b Mon Sep 17 00:00:00 2001 From: axelhildingson Date: Tue, 24 Aug 2021 13:49:18 +0200 Subject: [PATCH 2/2] remove old test cases. --- spec/ParseGraphQLServer.spec.js | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/spec/ParseGraphQLServer.spec.js b/spec/ParseGraphQLServer.spec.js index 3aa31b27a6..2390c6a939 100644 --- a/spec/ParseGraphQLServer.spec.js +++ b/spec/ParseGraphQLServer.spec.js @@ -10262,22 +10262,6 @@ describe('ParseGraphQLServer', () => { }); it('can resolve a custom query, that returns an array', async () => { - Parse.Cloud.define('helloArray', async () => { - return ['Hello', 'world!']; - }); - - const result = await apolloClient.query({ - query: gql` - query HelloArray { - helloArray - } - `, - }); - - expect(result.data.helloArray).toEqual(['Hello', 'world!']); - }); - - fit('can resolve a custom query, that returns an array', async () => { const schemaController = await parseServer.config.databaseController.loadSchema(); await schemaController.addClassIfNotExists('SuperCar', {