Middleware
The GraphQl component heavily relies on middleware for both schema declaration and execution. It is possible to declare your own middleware to handle the schema and execution.
#
Schema middlewareWith Schema middleware you can modify declaration before they are registered in the schema. You can also block a definition from being registered in the schema. Or wrap in a new definition. Below a fairly simple example where a new resolver function is registered on the user credentials to hash them.
For a more advanced example, see how the Relay Component wraps 'simple' types in a Connection type: example. Here you can see how an existing type is modified and new types are added.
#
Execution middlewareWith Execution middleware you can modify the execution of a query or mutation. You can for example add a cache to your execution, or hash a field (e.g. the password of a user). Below again a fairly straight forward example where Relay uses a middleware to decode the id of Node to its actual internal id.
#
Advanced usageNote that calling the $next() function executes the rest of the middleware chain. It is possible to modify the output of your middleware by calling the $next() function, modifying its result and returning it.