Skip to content

Commit 73736e2

Browse files
committed
fix(extensions): support defining on field resolver level for fields
1 parent aab8be8 commit 73736e2

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
- **Breaking Change**: `AuthChecker` type is now "function or class" - update to `AuthCheckerFn` if the function form is needed in the code
77
- support class-based auth checker, which allows for dependency injection
88
- allow defining directives for interface types and theirs fields, with inheritance for object types fields (#744)
9+
### Fixes
10+
- allow defining extension on field resolver level for fields also defined as a property of the class (#776)
911
### Others
1012
- **Breaking Change**: update `graphql-js` peer dependency to `^15.4.0`
1113

src/schema/schema-generator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ export abstract class SchemaGenerator {
343343
extensions: {
344344
complexity: field.complexity,
345345
...field.extensions,
346+
...fieldResolverMetadata?.extensions,
346347
},
347348
};
348349
return fieldsMap;

tests/functional/extensions.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,5 +321,44 @@ describe("Extensions", () => {
321321
expect(childObjectTypeParentField.extensions).toEqual({ parentField: true });
322322
});
323323
});
324+
325+
describe("Fields with field resolvers", () => {
326+
beforeAll(async () => {
327+
getMetadataStorage().clear();
328+
329+
@ObjectType()
330+
class Child {
331+
@Field()
332+
@Extensions({ childField: true })
333+
childField!: string;
334+
}
335+
@Resolver(of => Child)
336+
class ChildResolver {
337+
@Query()
338+
sampleQuery(): Child {
339+
return {} as Child;
340+
}
341+
342+
@Extensions({ childFieldResolver: true })
343+
@FieldResolver()
344+
childField(): string {
345+
return "childField";
346+
}
347+
}
348+
349+
schema = await buildSchema({
350+
resolvers: [ChildResolver],
351+
});
352+
});
353+
354+
it("should merge field level with field resolver level extensions", () => {
355+
const childObjectType = schema.getType("Child") as GraphQLObjectType;
356+
357+
expect(childObjectType.getFields().childField.extensions).toEqual({
358+
childField: true,
359+
childFieldResolver: true,
360+
});
361+
});
362+
});
324363
});
325364
});

0 commit comments

Comments
 (0)