As previously shown, a Resolver Wrapper is a function that receives a Resolver and must return a Resolver. This design
allows for a returned Resolver function that wraps the original. The original resolver can be
awaited for a result,
the arguments can be checked, changed, same with the final returned result.
The Generic Resolver Wrapper shows the basic concept but it is recommended to use the
createWrapper or the Generic Wrapper Function are passed
wrapperOptions includes useful contextual details about the Resolver being wrapped. Including
for the GraphQL type and
wrapperOptions.field if it is wrapping a Field Resolver.
createWrapper helps by providing more context about the wrapper and includes the following benefits:
- The wrapper is named which helps in debugging through multiple wrappers
- The second argument will apply the right typescript typing for
- There are runtime checks to ensure that the type specified by second argument match the resolver being wrapped
|Argument||From the Example||Description|
|Name||Provides the name of the wrapper|
|Wrapper Function||see function in example||The Resolver Wrapper function. The |
Generic Resolver Wrapper
Note: While this is a valid Resolver Wrapper Function it is recommended to use the
createWrapper for most cases
As we have seen in the Using Resolver there are two types of Resolvers: Field
Resolvers and Type Resolvers. Both can be wrapped but it's important to note the arguments to these two Resolver
functions are different. Therefore, there are some Resolver Wrappers that can only be used for Field Resolvers, or Type Resolvers. To make this easier it is recommended to use the
createWrapper helper which provides additional type checks and guards at runtime.