From 9ce705c5ccc5e6f4ac26af6e6471a6d2f4e995db Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Tue, 3 Dec 2024 06:10:38 -0500 Subject: [PATCH] fix(delegate): do not forward non-nullability errors to the gateway (#257) --- .changeset/slow-cars-mate.md | 5 +++++ packages/delegate/src/mergeFields.ts | 13 ++++++++++++- packages/stitch/tests/mergeFailures.test.ts | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 .changeset/slow-cars-mate.md diff --git a/.changeset/slow-cars-mate.md b/.changeset/slow-cars-mate.md new file mode 100644 index 00000000..0f6aca4e --- /dev/null +++ b/.changeset/slow-cars-mate.md @@ -0,0 +1,5 @@ +--- +'@graphql-tools/delegate': patch +--- + +Do not show internal non-nullability errors in the gateway diff --git a/packages/delegate/src/mergeFields.ts b/packages/delegate/src/mergeFields.ts index a5860926..5cd5ad80 100644 --- a/packages/delegate/src/mergeFields.ts +++ b/packages/delegate/src/mergeFields.ts @@ -147,7 +147,18 @@ export function handleResolverResult( for (const [responseKey, fieldNodes] of fields) { const combinedPath = [...path, responseKey]; if (resolverResult instanceof GraphQLError) { - nullResult[responseKey] = relocatedError(resolverResult, combinedPath); + if ( + resolverResult.message.includes( + 'Cannot return null for non-nullable field', + ) + ) { + nullResult[responseKey] = null; + } else { + nullResult[responseKey] = relocatedError( + resolverResult, + combinedPath, + ); + } } else if (resolverResult instanceof Error) { nullResult[responseKey] = locatedError( resolverResult, diff --git a/packages/stitch/tests/mergeFailures.test.ts b/packages/stitch/tests/mergeFailures.test.ts index 9ada0b04..a56da9d0 100644 --- a/packages/stitch/tests/mergeFailures.test.ts +++ b/packages/stitch/tests/mergeFailures.test.ts @@ -240,7 +240,7 @@ describe('merge failures', () => { data: { thing: null }, errors: [ createGraphQLError( - 'Cannot return null for non-nullable field Thing.id.', + 'Cannot return null for non-nullable field Thing.description.', ), ], };