From f1350946c3d1d9765f776c465df33685d959ce07 Mon Sep 17 00:00:00 2001 From: DavisCacici <71649801+DavisCacici@users.noreply.github.com> Date: Tue, 11 Feb 2025 14:07:29 +0100 Subject: [PATCH 1/2] Update resolvers.ts, handle error when "resolver" variable in addObject is undefined I suggest this update to the addObject method: if the resolver is undefined, provide a clear message to the user. --- packages/graphql-modules/src/module/resolvers.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/graphql-modules/src/module/resolvers.ts b/packages/graphql-modules/src/module/resolvers.ts index f74bebcc99..29f76f14a7 100644 --- a/packages/graphql-modules/src/module/resolvers.ts +++ b/packages/graphql-modules/src/module/resolvers.ts @@ -258,6 +258,13 @@ function addObject({ if (fields.hasOwnProperty(fieldName)) { const resolver = fields[fieldName]; + if(typeof resolver === 'undefined'){ + throw new ResolverDuplicatedError( + `Resolver not implement of "${typeName}.${fieldName}"`, + useLocation({ dirname: config.dirname, id: config.id }) + ); + } + if (isResolveFn(resolver)) { if (container[typeName][fieldName]) { throw new ResolverDuplicatedError( From e9edbcd5aeeae1152b681ca1a553a5ec19d1acee Mon Sep 17 00:00:00 2001 From: DavisCacici <71649801+DavisCacici@users.noreply.github.com> Date: Tue, 8 Apr 2025 09:46:46 +0000 Subject: [PATCH 2/2] Add test and changeset --- .changeset/tough-dolphins-pump.md | 5 +++++ .../graphql-modules/tests/context.spec.ts | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 .changeset/tough-dolphins-pump.md diff --git a/.changeset/tough-dolphins-pump.md b/.changeset/tough-dolphins-pump.md new file mode 100644 index 0000000000..2e8f82cca0 --- /dev/null +++ b/.changeset/tough-dolphins-pump.md @@ -0,0 +1,5 @@ +--- +'graphql-modules': major +--- + +Update resolvers.ts, handle error when "resolver" variable in addObject diff --git a/packages/graphql-modules/tests/context.spec.ts b/packages/graphql-modules/tests/context.spec.ts index 6fd7f75b6b..61a2de262f 100644 --- a/packages/graphql-modules/tests/context.spec.ts +++ b/packages/graphql-modules/tests/context.spec.ts @@ -130,3 +130,25 @@ test('Global context and module context should be reachable', async () => { expect.objectContaining({ postRegion: 1234 }) ); }); + +test('Resolver is implemented', () => { + const invalidModule = createModule({ + id: 'invalid-module', + typeDefs: gql` + type Query { + post(id: Int!): String! + } + `, + resolvers: { + Query: { + post: undefined, + }, + }, + }); + + expect(() => { + createApplication({ + modules: [invalidModule], + }); + }).toThrow('Resolver not implement of "Query.post"'); +});