Skip to content

Commit 0b768c2

Browse files
committed
fix: do not throw error if resolver is a built-in one
1 parent dded140 commit 0b768c2

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Diff for: src/addDirectiveResolveFunctionsToSchema.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { defaultFieldResolver } from 'graphql'
33
import { DirectiveLocation } from 'graphql/type'
44
import { getArgumentValues } from 'graphql/execution/values'
55

6+
const BUILT_IN_DIRECTIVES = ['deprecated', 'skip', 'include']
7+
68
function getFieldResolver(field) {
79
const resolver = field.resolve || defaultFieldResolver
810
return resolver.bind(field)
@@ -33,7 +35,7 @@ function getDirectiveInfo(directive, resolverMap, schema, location) {
3335
}
3436

3537
const resolver = resolverMap[name]
36-
if (!resolver) {
38+
if (!resolver && !BUILT_IN_DIRECTIVES.includes(name)) {
3739
throw new Error(
3840
`Directive @${name} has no resolver.` +
3941
'Please define one using createFieldExecutionResolver().',

Diff for: src/addDirectiveResolveFunctionsToSchema.test.js

+15
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,21 @@ describe('addDirectiveResolveFunctionsToSchema', () => {
175175
}
176176
})
177177

178+
it('should not throw an error if resolver is a built-in one', async () => {
179+
const typeDefs = /* GraphQL */ `
180+
type Query {
181+
foo: String @deprecated
182+
}
183+
`
184+
const resolvers = {
185+
Query: {
186+
foo: () => 'foo',
187+
},
188+
}
189+
const schema = makeExecutableSchema({ typeDefs, resolvers })
190+
addDirectiveResolveFunctionsToSchema(schema, {})
191+
})
192+
178193
it('should work without directive', async () => {
179194
const query = /* GraphQL */ `{ foo }`
180195
const data = await run(schema, query)

0 commit comments

Comments
 (0)