After learning how to use Resolvers to resolve data all that is left to organize them for query execution. Resolver Maps help define the GraphQL API by mapping Resolvers to the appropriate field (or Abstract Type in the case of Type Resolvers). The idea of Resolver Maps has been covered by Apollo and graphql-tools. With the Resolver Map format it is easier to see how Resolvers are applied to a GraphQLSchema and executed with a GraphQL handler.
Here is an example of a mapping between a GraphQL Schema and Resolvers via a Resolver Map.
The first level within a
resolverMap object represents the GraphQL Type which has a value of an object. This next
level object refers the field name referencing a Field Resolver or in
the case that the type is an Abstract type (Union or Interface) the key is
__resolveType and points to a
Type Resolver. In this example the resolver functions are references to
resolver functions would could be provided inline or imported from elsewhere.
Modifying the Resolver Map Surface Area
Resolver Maps have a direct impact on how Resolvers are organized and executed. If there was a way to make adaptive changes to the Resolver Map, as a primitive, it would mean being able to swap and modify the Resolver Map surface area for various mocking and test scenarios. These methods are covered by Resolver Map Middlewares and are part of the core concepts of graphql-mocks and what creates
The Apollo docs provide some great examples on Resovler Maps, Resolvers and the execution flow of GraphQL. Much of this documentation also applies in the goal of mocking GraphQL.