Skip to content

Commit

Permalink
Allow to use a map of extensions in a field resolver (#1324)
Browse files Browse the repository at this point in the history
Closes #1279
  • Loading branch information
kamilkisiela authored Apr 1, 2020
1 parent f39fc24 commit 8689b4b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export interface IResolverOptions<TSource = any, TContext = any, TArgs = any> {
fragment?: string;
resolve?: IFieldResolver<TSource, TContext, TArgs>;
subscribe?: IFieldResolver<TSource, TContext, TArgs>;
extensions?: Record<string, any>;
__resolveType?: GraphQLTypeResolver<TSource, TContext>;
__isTypeOf?: GraphQLIsTypeOfFn<TSource, TContext>;
}
Expand Down
25 changes: 25 additions & 0 deletions src/test/schemaGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,31 @@ describe('generating schema from shorthand', () => {
expect(jsSchema.getQueryType().getFields().bar).toBeDefined();
});

test('allow for a map of extensions in field resolver', () => {
const jsSchema = makeExecutableSchema({
typeDefs: /* GraphQL */ `
type Query {
foo: String
}
`,
resolvers: {
Query: {
foo: {
resolve() {
return 'Foo';
},
extensions: {
verbose: true,
},
},
},
},
});
const extensions = jsSchema.getQueryType().getFields().foo.extensions;
expect(extensions).toHaveProperty('verbose');
expect(extensions.verbose).toBe(true);
});

test('can concatenateTypeDefs created by a function inside a closure', () => {
const typeA = { typeDefs: () => ['type TypeA { foo: String }'] };
const typeB = { typeDefs: () => ['type TypeB { bar: String }'] };
Expand Down

0 comments on commit 8689b4b

Please sign in to comment.