From 357f136fc714ad8d0a5237d0e059f86f71c3173e Mon Sep 17 00:00:00 2001 From: Chris Lenfest Date: Mon, 16 Sep 2024 10:53:26 -0500 Subject: [PATCH] Revert #3142 --- .changeset/slow-cups-exist.md | 5 --- .../src/__tests__/compose.external.test.ts | 34 +------------------ composition-js/src/merging/merge.ts | 4 +-- 3 files changed, 2 insertions(+), 41 deletions(-) delete mode 100644 .changeset/slow-cups-exist.md diff --git a/.changeset/slow-cups-exist.md b/.changeset/slow-cups-exist.md deleted file mode 100644 index 994f3caa0..000000000 --- a/.changeset/slow-cups-exist.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@apollo/composition": patch ---- - -Relax error for detecting whether `@external` field matches. If the external field has extra optional parameters, allow it to pass composition as being able to pass the parameter is not necessary for a required field. diff --git a/composition-js/src/__tests__/compose.external.test.ts b/composition-js/src/__tests__/compose.external.test.ts index 00a661e4d..a2b62795c 100644 --- a/composition-js/src/__tests__/compose.external.test.ts +++ b/composition-js/src/__tests__/compose.external.test.ts @@ -62,7 +62,7 @@ describe('tests related to @external', () => { typeDefs: gql` type T @key(fields: "id") { id: ID! - f(x: Int!): String @shareable + f(x: Int): String @shareable } `, }; @@ -73,38 +73,6 @@ describe('tests related to @external', () => { ['EXTERNAL_ARGUMENT_MISSING', 'Field "T.f" is missing argument "T.f(x:)" in some subgraphs where it is marked @external: argument "T.f(x:)" is declared in subgraph "subgraphB" but not in subgraph "subgraphA" (where "T.f" is @external).'], ]); }); - - it('succeeds on @external definition where difference between definitions is an optional argument', () => { - const subgraphA = { - name: 'subgraphA', - typeDefs: gql` - type Query { - locations: [Location] - } - - type Location @key(fields: "id") { - id: ID! - name: String! - photo(smallVersion: Boolean): String! # New optional arg shouldn't break existing clients - } - `, - }; - - const subgraphB = { - name: 'subgraphB', - typeDefs: gql` - type Location @key(fields: "id") { - id: ID! - photo: String! @external - banner: String @requires(fields: "photo") - } - `, - }; - - const result = composeAsFed2Subgraphs([subgraphA, subgraphB]); - assertCompositionSuccess(result); - }); - it('errors on incompatible argument types in @external declaration', () => { const subgraphA = { diff --git a/composition-js/src/merging/merge.ts b/composition-js/src/merging/merge.ts index 722e04075..01b3430dd 100644 --- a/composition-js/src/merging/merge.ts +++ b/composition-js/src/merging/merge.ts @@ -1864,9 +1864,7 @@ class Merger { const name = destArg.name; const arg = source.argument(name); if (!arg) { - if (!destArg.type || destArg.type.kind === 'NonNullType') { - invalidArgsPresence.add(name); - } + invalidArgsPresence.add(name); continue; } if (!sameType(destArg.type!, arg.type!) && !this.isStrictSubtype(arg.type!, destArg.type!)) {