From 16a974a04ab7fef9e55e5129b9cca070d8915992 Mon Sep 17 00:00:00 2001 From: Antoine Cormouls Date: Wed, 11 Mar 2020 20:59:18 +0100 Subject: [PATCH] Fix Unknow type merge bug on overloaded types (#6494) * Fix Unknow type bug on overloaded types * check args too --- spec/ParseGraphQLServer.spec.js | 6 +++--- src/GraphQL/ParseGraphQLSchema.js | 28 +++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/spec/ParseGraphQLServer.spec.js b/spec/ParseGraphQLServer.spec.js index e9cbc64d..ba11c0a9 100644 --- a/spec/ParseGraphQLServer.spec.js +++ b/spec/ParseGraphQLServer.spec.js @@ -10821,11 +10821,11 @@ describe('ParseGraphQLServer', () => { expect(result2.data.someClass.name).toEqual('aname'); expect(result.data.someClass.language).toEqual('fr'); const result3 = await apolloClient.mutate({ - variables: { id: obj.id, name: 'anewname' }, + variables: { id: obj.id, name: 'anewname', type: 'human' }, mutation: gql` - mutation someClass($id: ID!, $name: String!) { + mutation someClass($id: ID!, $name: String!, $type: TypeEnum!) { updateSomeClass( - input: { id: $id, fields: { name: $name, type: human } } + input: { id: $id, fields: { name: $name, type: $type } } ) { someClass { nameUpperCase diff --git a/src/GraphQL/ParseGraphQLSchema.js b/src/GraphQL/ParseGraphQLSchema.js index d596eae5..dd071b1f 100644 --- a/src/GraphQL/ParseGraphQLSchema.js +++ b/src/GraphQL/ParseGraphQLSchema.js @@ -211,7 +211,33 @@ class ParseGraphQLSchema { const autoGraphQLSchemaType = this.graphQLAutoSchema.getType( customGraphQLSchemaType.name ); - if (autoGraphQLSchemaType) { + if ( + autoGraphQLSchemaType && + typeof customGraphQLSchemaType.getFields === 'function' + ) { + const findAndAddLastType = type => { + if (type.name) { + if (!this.graphQLAutoSchema.getType(type)) { + // To avoid schema stitching (Unknow type) bug on variables + // transfer the final type to the Auto Schema + this.graphQLAutoSchema._typeMap[type.name] = type; + } + } else { + if (type.ofType) { + findAndAddLastType(type.ofType); + } + } + }; + Object.values(customGraphQLSchemaType.getFields()).forEach( + field => { + findAndAddLastType(field.type); + if (field.args) { + field.args.forEach(arg => { + findAndAddLastType(arg.type); + }); + } + } + ); autoGraphQLSchemaType._fields = { ...autoGraphQLSchemaType._fields, ...customGraphQLSchemaType._fields,