Skip to content

Commit

Permalink
🐛 Fix rare issue when objects implement >1 interface
Browse files Browse the repository at this point in the history
  • Loading branch information
adbouygues committed Jul 12, 2024
1 parent 0613586 commit f77491e
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions packages/graphql-mesh/patches/@graphql-tools+stitch+9.0.3.patch
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ index 5e752ad..3b487f5 100644
const currentNamedType = (0, graphql_1.getNamedType)(c.type);
if (finalNamedType.toString() !== currentNamedType.toString()) {
diff --git a/node_modules/@graphql-tools/stitch/cjs/typeCandidates.js b/node_modules/@graphql-tools/stitch/cjs/typeCandidates.js
index c915942..d28ed66 100644
index c915942..d6fa958 100644
--- a/node_modules/@graphql-tools/stitch/cjs/typeCandidates.js
+++ b/node_modules/@graphql-tools/stitch/cjs/typeCandidates.js
@@ -119,6 +119,29 @@ function buildTypes({ typeCandidates, directives, stitchingInfo, rootTypeNames,
Expand Down Expand Up @@ -45,31 +45,18 @@ index c915942..d28ed66 100644
typeMap[typeName] = (0, mergeCandidates_js_1.mergeCandidates)(typeName, typeCandidates[typeName], typeMergingOptions);
}
else {
@@ -128,6 +151,58 @@ function buildTypes({ typeCandidates, directives, stitchingInfo, rootTypeNames,
@@ -128,6 +151,66 @@ function buildTypes({ typeCandidates, directives, stitchingInfo, rootTypeNames,
typeMap[typeName] = candidateSelector(typeCandidates[typeName]).type;
}
}
+
+ /**
+ * When an object implements an interface, it needs to have every property
+ * of this interface. Because interfaces have been possibly merged earlier
+ * in this file, this statement is sometimes not true anymore.
+ * Really tidious edge case when an object implements more than 1 interface
+ */
+ Object.values(typeMap).forEach((type) => {
+ if (type.constructor.name === "GraphQLObjectType") {
+ const typeInterfaces = type.getInterfaces()
+
+ if (typeInterfaces.length !== 0) {
+ type._fields = type.getFields()
+
+ typeInterfaces.forEach(i => {
+ const iFields = typeMap[i.name].getFields()
+ Object.keys(iFields).forEach(keyName => {
+ type._fields[keyName] = iFields[keyName]
+ })
+ })
+ }
+
+ if (typeInterfaces.length >= 2) {
+ let uniqueFields = {}
+ let duplicateFields = {}
Expand Down Expand Up @@ -100,6 +87,27 @@ index c915942..d28ed66 100644
+ }
+ }
+ });
+ /**
+ * When an object implements an interface, it needs to have every property
+ * of this interface. Because interfaces have been possibly merged earlier
+ * in this file, this statement is sometimes not true anymore.
+ */
+ Object.values(typeMap).forEach((type) => {
+ if (type.constructor.name === "GraphQLObjectType") {
+ const typeInterfaces = type.getInterfaces()
+
+ if (typeInterfaces.length !== 0) {
+ type._fields = type.getFields()
+
+ typeInterfaces.forEach(i => {
+ const iFields = typeMap[i.name].getFields()
+ Object.keys(iFields).forEach(keyName => {
+ type._fields[keyName] = iFields[keyName]
+ })
+ })
+ }
+ }
+ })
+
return (0, utils_1.rewireTypes)(typeMap, directives);
}
Expand Down

0 comments on commit f77491e

Please sign in to comment.