Node Resolvers
Writing resolvers for nodes in Viaduct
In Viaduct, all module code is provided in the form of either a node resolver or a field resolver. Node and field resolvers are implemented similarly:
@resolver
directive to fields you want to provide resolvers for.resolve
or batchResolve
.Responsibility sets (also known as “responsibility selection sets”) are an important concept in the Viaduct API. Every node and field resolver is responsible for resolving the fields in its responsibility set. This includes all fields, including nested fields, that themselves do not have a resolver. The node and field resolver pages provide more details with examples.
Viaduct is designed to create instances of resolver classes through dependency injection. You can define this behavior by implementing this interface:
interface TenantCodeInjector {
fun <T> getProvider(clazz: Class<T>): Provider<T>
}
Examples of using this dependency injection mechanism are available in the demo applications.
If you do not provide an implementation of TenantCodeInjector
, Viaduct will use a naive default implementation that assumes a zero-argument constructor is available for all resolvers. Whenever the GraphQL execution engine needs to invoke a resolver, it will use this to construct an instance of the resolver. While sufficient for toy applications, we strongly suggest using a dependency injection framework for real applications.
Writing resolvers for nodes in Viaduct
Writing resolvers for fields in Viaduct
Batch node and field resolvers
Using the @Resolver annotation
Creating node references in resolvers
Executing subqueries in resolvers
Mutating data in Viaduct
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.