@apollo/federation-internals 2.4.7 → 2.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.ts CHANGED
@@ -3,8 +3,9 @@
3
3
  */
4
4
 
5
5
  import {
6
- AbstractType,
6
+ AbstractType,
7
7
  InterfaceType,
8
+ isCompositeType,
8
9
  isInterfaceType,
9
10
  isListType,
10
11
  isNamedType,
@@ -144,3 +145,23 @@ export function isStrictSubtype(
144
145
  && isSubtype(type.ofType, maybeSubType, allowedRules, unionMembershipTester, implementsInterfaceTester);
145
146
  }
146
147
  }
148
+
149
+ /**
150
+ * This essentially follows the beginning of https://spec.graphql.org/draft/#SameResponseShape().
151
+ * That is, the types cannot be merged unless:
152
+ * - they have the same nullability and "list-ability", potentially recursively.
153
+ * - their base type is either both composite, or are the same type.
154
+ */
155
+ export function typesCanBeMerged(t1: Type, t2: Type): boolean {
156
+ if (isNonNullType(t1)) {
157
+ return isNonNullType(t2) ? typesCanBeMerged(t1.ofType, t2.ofType) : false;
158
+ }
159
+ if (isListType(t1)) {
160
+ return isListType(t2) ? typesCanBeMerged(t1.ofType, t2.ofType) : false;
161
+ }
162
+ if (isCompositeType(t1)) {
163
+ return isCompositeType(t2);
164
+ }
165
+ return sameType(t1, t2);
166
+ }
167
+