The graphql.execution.instrumentation.Instrumentation
interface allows you to inject code that can observe the
execution of a query and also change the runtime behaviour.
The primary use case for this is to allow say performance monitoring and custom logging but it could be used for many different purposes.
When you build the Graphql
object you can specify what Instrumentation
to use (if any).
|
|
An implementation of Instrumentation
needs to implement the “begin” step methods that represent the execution of a graphql query.
Each step must give back a non null graphql.execution.instrumentation.InstrumentationContext
object which will be called back
when the step completes, and will be told that it succeeded or failed with a Throwable.
The following is a basic custom Instrumentation
that measures overall execution time and puts it into a stateful object.
|
|
You can combine multiple Instrumentation
objects together using the graphql.execution.instrumentation.ChainedInstrumentation
class which
accepts a list of Instrumentation
objects and calls them in that defined order.
|
|
graphql.execution.instrumentation.tracing.TracingInstrumentation
is an Instrumentation
implementation that creates tracing information
about the query that is being executed.
It follows the Apollo proposed tracing format defined at https://github.com/apollographql/apollo-tracing <https://github.com/apollographql/apollo-tracing>
_
A detailed tracing map will be created and placed in the extensions
section of the result.
So given a query like
|
|
It would return a result like
|
|
graphql.execution.instrumentation.fieldvalidation.FieldValidationInstrumentation
is an Instrumentation
implementation that
can be used to validate fields and their arguments before query execution. If errors are returned during this process then
the query execution is aborted and the errors will be in the query result.
You can make you own custom implementation of FieldValidation
or you can use the SimpleFieldValidation
class
to add simple per field checks rules.
|
|