lirown / graphql-custom-directive

A custom directive for GraphQL which hooks the query or schema execution
MIT License
53 stars 8 forks source link

Resolvers not attaching on fields below `[MyType]!` #2

Closed krabbypattified closed 6 years ago

krabbypattified commented 6 years ago

wrapFieldsWithMiddleware should recursively search ofType. if i have something like this:

search: [Document]!

or this:

search: [[[[[Document!]]]]]!

Resolvers will not attach to fields below that point.

Here's the fix (for the wrapFieldsWithMiddleware function):

if (!!field && typeof field == 'object') {
    field.resolve = resolveMiddlewareWrapper(field.resolve, field.directives);
    var child = field.type
    while (child.ofType) child = child.ofType
    if (child._fields) wrapFieldsWithMiddleware(child._fields)
}
lirown commented 6 years ago

fixed in 0.2.0 (thanks for that)