Skip to content

Commit

Permalink
Fix Unknow type merge bug on overloaded types (parse-community#6494)
Browse files Browse the repository at this point in the history
* Fix Unknow type bug on overloaded types

* check args too
  • Loading branch information
Moumouls authored Mar 11, 2020
1 parent aefeb75 commit dc6743a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
6 changes: 3 additions & 3 deletions spec/ParseGraphQLServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 27 additions & 1 deletion src/GraphQL/ParseGraphQLSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit dc6743a

Please sign in to comment.