Skip to content

Commit 16a974a

Browse files
authored
Fix Unknow type merge bug on overloaded types (#6494)
* Fix Unknow type bug on overloaded types * check args too
1 parent 35d76b8 commit 16a974a

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

spec/ParseGraphQLServer.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10821,11 +10821,11 @@ describe('ParseGraphQLServer', () => {
1082110821
expect(result2.data.someClass.name).toEqual('aname');
1082210822
expect(result.data.someClass.language).toEqual('fr');
1082310823
const result3 = await apolloClient.mutate({
10824-
variables: { id: obj.id, name: 'anewname' },
10824+
variables: { id: obj.id, name: 'anewname', type: 'human' },
1082510825
mutation: gql`
10826-
mutation someClass($id: ID!, $name: String!) {
10826+
mutation someClass($id: ID!, $name: String!, $type: TypeEnum!) {
1082710827
updateSomeClass(
10828-
input: { id: $id, fields: { name: $name, type: human } }
10828+
input: { id: $id, fields: { name: $name, type: $type } }
1082910829
) {
1083010830
someClass {
1083110831
nameUpperCase

src/GraphQL/ParseGraphQLSchema.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,33 @@ class ParseGraphQLSchema {
211211
const autoGraphQLSchemaType = this.graphQLAutoSchema.getType(
212212
customGraphQLSchemaType.name
213213
);
214-
if (autoGraphQLSchemaType) {
214+
if (
215+
autoGraphQLSchemaType &&
216+
typeof customGraphQLSchemaType.getFields === 'function'
217+
) {
218+
const findAndAddLastType = type => {
219+
if (type.name) {
220+
if (!this.graphQLAutoSchema.getType(type)) {
221+
// To avoid schema stitching (Unknow type) bug on variables
222+
// transfer the final type to the Auto Schema
223+
this.graphQLAutoSchema._typeMap[type.name] = type;
224+
}
225+
} else {
226+
if (type.ofType) {
227+
findAndAddLastType(type.ofType);
228+
}
229+
}
230+
};
231+
Object.values(customGraphQLSchemaType.getFields()).forEach(
232+
field => {
233+
findAndAddLastType(field.type);
234+
if (field.args) {
235+
field.args.forEach(arg => {
236+
findAndAddLastType(arg.type);
237+
});
238+
}
239+
}
240+
);
215241
autoGraphQLSchemaType._fields = {
216242
...autoGraphQLSchemaType._fields,
217243
...customGraphQLSchemaType._fields,

0 commit comments

Comments
 (0)