diff --git a/.changeset/sixty-plums-enjoy.md b/.changeset/sixty-plums-enjoy.md new file mode 100644 index 000000000..10fa1eab4 --- /dev/null +++ b/.changeset/sixty-plums-enjoy.md @@ -0,0 +1,5 @@ +--- +"@apollo/composition": patch +--- + +Allow merging external types when using arrays as default arguments. diff --git a/composition-js/src/__tests__/compose.test.ts b/composition-js/src/__tests__/compose.test.ts index df63bf699..3cc57c12f 100644 --- a/composition-js/src/__tests__/compose.test.ts +++ b/composition-js/src/__tests__/compose.test.ts @@ -614,6 +614,47 @@ describe('composition', () => { `); }); + it('merges default arguments when they are arrays', () => { + const subgraphA = { + name: 'subgraph-a', + typeDefs: gql` + type Query { + a: A @shareable + } + + type A @key(fields: "id") { + id: ID + get(ids: [ID] = []): [B] @external + req: Int @requires(fields: "get { __typename }") + } + + type B @key(fields: "id", resolvable: false) { + id: ID + } + ` + }; + const subgraphB = { + name: 'subgraph-b', + typeDefs: gql` + type Query { + a: A @shareable + } + + type A @key(fields: "id") { + id: ID + get(ids: [ID] = []): [B] + } + + type B @key(fields: "id") { + id: ID + } + ` + }; + + const result = composeAsFed2Subgraphs([subgraphA, subgraphB]); + assertCompositionSuccess(result); + }); + describe('merging of type references', () => { describe('for field types', () => { it('errors on incompatible types', () => { diff --git a/composition-js/src/merging/merge.ts b/composition-js/src/merging/merge.ts index e24ae25a7..539df9b47 100644 --- a/composition-js/src/merging/merge.ts +++ b/composition-js/src/merging/merge.ts @@ -1871,7 +1871,7 @@ class Merger { if (!sameType(destArg.type!, arg.type!) && !this.isStrictSubtype(arg.type!, destArg.type!)) { invalidArgsTypes.add(name); } - if (destArg.defaultValue !== arg.defaultValue) { + if (!valueEquals(destArg.defaultValue, arg.defaultValue)) { invalidArgsDefaults.add(name); } } diff --git a/composition-js/src/merging/reporter.ts b/composition-js/src/merging/reporter.ts index 3a9888ed6..a7d068bfa 100644 --- a/composition-js/src/merging/reporter.ts +++ b/composition-js/src/merging/reporter.ts @@ -1,4 +1,4 @@ -import { addSubgraphToASTNode, assert, ErrorCodeDefinition, joinStrings, MultiMap, NamedSchemaElement, printSubgraphNames, SubgraphASTNode } from '@apollo/federation-internals'; +import { addSubgraphToASTNode, ErrorCodeDefinition, joinStrings, MultiMap, NamedSchemaElement, printSubgraphNames, SubgraphASTNode } from '@apollo/federation-internals'; import { ASTNode, GraphQLError } from 'graphql'; import { CompositionHint, HintCodeDefinition } from '../hints'; import { Sources } from './merge'; @@ -182,7 +182,6 @@ export class MismatchReporter { } } const supergraphMismatch = (supergraphElement && mismatchAccessor(supergraphElement, true)) ?? ''; - assert(distributionMap.size > 1, () => `Should not have been called for ${supergraphElement}`); const distribution = []; // We always add the "supergraph" first (proper formatting of hints rely on this in particular). const subgraphsLikeSupergraph = distributionMap.get(supergraphMismatch);