Adding and Managing Resolvers on a Resolver Map is a common task when setting up different scenarios. This library provides two Resolver Map Middleware functions to make this easy,
layer, both which can apply Resolver Wrappers.
The generated Resolver Map Middleware from
layer create Resolver Map Middlewares that most often used with
GraphQLHandler and its
embed is commonly used to:
- Target specific parts of the Resolver Map with Highlight
- Add a Resolver with or without Resolver Wrappers
- Target existing Resolvers already on the Resolver Map with Resolver Wrappers
Adds a resolver on the
users field on the
Query type, using a highlight callback that provides a highlight instance. See the available highlighters for more options on targeting the schema.
Add Resolver with a Resolver Wrapper
Wrappers can be applied to the resolver being embedded, also. This example passes
fooWrapper in an array of
wrappers that are applied in order by the
wrappers option on `embed.
Add Resolver Replacing Existing
true for the
replace option to replace any existing resolvers that might exist on the Resolver Map.
Wrap Existing Resolvers with Resolver Wrappers
By not specifying a resolver, the
highlight option will be used to select existing Resolvers and apply the the Resolver Wrappers passed into the
Take fragments, or Resolver Map partials, and layer one or more lazily into a Resolver Map with the generated Resolver Map Middleware. These Resolver Map Partials can be defined separately and combined as needed with
Adding Resolve Map Partials
middleware in this example would lazily apply the
queryPersonPartial, then the
mutationAddPersonPartial via the generated Resolver Map Middleware.
Adding Resolvers with Resolver Wrappers
Additionally, the Resolvers that are being layered in can also be wrapped with Resolver Wrappers by passing a
wrappers option on the second argument to
Replace Existing Resolvers
As a safeguard, by default, resolver being added by
layer won't replace existing resolvers unless the
replace true option is provided.