From 722abad7ea16521496b54d68e425cd43765bb6eb Mon Sep 17 00:00:00 2001 From: Yaacov Rydzinski Date: Wed, 30 Mar 2022 21:29:38 +0300 Subject: [PATCH] fix(addResolversToSchema): continue processing all types and fields in edge cases (#4355) * don't break * add changeset --- .changeset/dull-eyes-work.md | 9 +++++++++ packages/schema/src/addResolversToSchema.ts | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 .changeset/dull-eyes-work.md diff --git a/.changeset/dull-eyes-work.md b/.changeset/dull-eyes-work.md new file mode 100644 index 0000000000..a4ff051e28 --- /dev/null +++ b/.changeset/dull-eyes-work.md @@ -0,0 +1,9 @@ +--- +'@graphql-tools/schema': patch +--- + +Fix `addResolversToSchema` bug where type or field processing would be aborted prematurely. + +In previous versions, if `requireResolversToMatchSchema` was set to `ignore`, although no error would be thrown for an unexpected resolver type, type processing would still be aborted early. This fix changes the behavior to correctly continue resolver type processing with the next provided type. + +In previous versions, if a resolver field began with double underscores, it would correctly be used for legacy behavior to directly set a type property, but field processing would be aborted early. This fix changes the behavior to correctly continue type processing with the next field. diff --git a/packages/schema/src/addResolversToSchema.ts b/packages/schema/src/addResolversToSchema.ts index 64ce23f082..d1b73ee394 100644 --- a/packages/schema/src/addResolversToSchema.ts +++ b/packages/schema/src/addResolversToSchema.ts @@ -77,7 +77,7 @@ export function addResolversToSchema( if (type == null) { if (requireResolversToMatchSchema === 'ignore') { - break; + continue; } throw new Error(`"${typeName}" defined in resolvers, but not in schema`); @@ -235,7 +235,7 @@ function addResolversToExistingSchema( if (fieldName.startsWith('__')) { // this is for isTypeOf and resolveType and all the other stuff. type[fieldName.substring(2)] = resolverValue[fieldName]; - break; + continue; } const fields = type.getFields();