Skip to content

Commit

Permalink
fix(extensions): support defining on field resolver level for fields
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalLytek committed Feb 1, 2021
1 parent aab8be8 commit 73736e2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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`

Expand Down
1 change: 1 addition & 0 deletions src/schema/schema-generator.ts
Expand Up @@ -343,6 +343,7 @@ export abstract class SchemaGenerator {
extensions: {
complexity: field.complexity,
...field.extensions,
...fieldResolverMetadata?.extensions,
},
};
return fieldsMap;
Expand Down
39 changes: 39 additions & 0 deletions tests/functional/extensions.ts
Expand Up @@ -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,
});
});
});
});
});

0 comments on commit 73736e2

Please sign in to comment.