diff --git a/CHANGELOG.md b/CHANGELOG.md index 447c30f27..de407befb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ - **Breaking Change**: `AuthChecker` type is now "function or class" - update to `AuthCheckerFn` if the function form is needed in the code - support class-based auth checker, which allows for dependency injection - allow defining directives for interface types and theirs fields, with inheritance for object types fields (#744) +### Fixes +- allow defining extension on field resolver level for fields also defined as a property of the class (#776) ### Others - **Breaking Change**: update `graphql-js` peer dependency to `^15.4.0` diff --git a/src/schema/schema-generator.ts b/src/schema/schema-generator.ts index c3810f782..e8563e7fa 100644 --- a/src/schema/schema-generator.ts +++ b/src/schema/schema-generator.ts @@ -343,6 +343,7 @@ export abstract class SchemaGenerator { extensions: { complexity: field.complexity, ...field.extensions, + ...fieldResolverMetadata?.extensions, }, }; return fieldsMap; diff --git a/tests/functional/extensions.ts b/tests/functional/extensions.ts index cbe4b672d..8511fc27f 100644 --- a/tests/functional/extensions.ts +++ b/tests/functional/extensions.ts @@ -321,5 +321,44 @@ describe("Extensions", () => { expect(childObjectTypeParentField.extensions).toEqual({ parentField: true }); }); }); + + describe("Fields with field resolvers", () => { + beforeAll(async () => { + getMetadataStorage().clear(); + + @ObjectType() + class Child { + @Field() + @Extensions({ childField: true }) + childField!: string; + } + @Resolver(of => Child) + class ChildResolver { + @Query() + sampleQuery(): Child { + return {} as Child; + } + + @Extensions({ childFieldResolver: true }) + @FieldResolver() + childField(): string { + return "childField"; + } + } + + schema = await buildSchema({ + resolvers: [ChildResolver], + }); + }); + + it("should merge field level with field resolver level extensions", () => { + const childObjectType = schema.getType("Child") as GraphQLObjectType; + + expect(childObjectType.getFields().childField.extensions).toEqual({ + childField: true, + childFieldResolver: true, + }); + }); + }); }); });