viaduct.api) provides the foundational interfaces and utilities for application developers to implement GraphQL resolvers, define modules, and interact with the Viaduct execution context.
Overview
The Tenant API is designed to be used by application developers (tenant developers) who write business logic on top of Viaduct. It provides:- Base interfaces for resolvers (
ResolverBase,NodeResolverBase) - Execution contexts for accessing request data
- Field value handling
- Module definition interfaces
- Utilities for working with connections and pagination
Core Interfaces
ResolverBase
Base interface for all field resolver classes.The return type of the resolve function
viaduct.api
Stability: Stable
Usage:
When you mark a field with @resolver in your GraphQL schema, Viaduct generates an abstract resolver class that extends ResolverBase. You implement the generated abstract class to provide custom resolution logic.
NodeResolverBase
Base interface for node resolver classes that resolve entities by Global ID.The return type implementing
NodeObject (entities with global IDs)viaduct.api
Stability: Stable
Usage:
When your GraphQL type implements the Node interface, Viaduct generates a node resolver base class. Implement it to resolve entities by their Global ID:
SelectiveResolver
Marker interface for node resolvers that vary their response based on the requested selection set.viaduct.api
Stability: Stable
Effects of implementing this interface:
- Enables access to
ctx.selections()within resolver methods - Changes caching behavior to match by ID + selection set (instead of ID-only)
- Use when the resolver needs to optimize by fetching only requested fields
- Don’t use if the resolver always returns the same data for a given ID
TenantModule
Interface that all Viaduct modules must implement.Metadata to be associated with this module
The package name for the module (defaults to the Java package name)
viaduct.api
Stability: Stable
Usage:
Viaduct code generation creates a module class for each module. You typically don’t implement this directly.
Execution Contexts
Execution contexts provide access to request data, arguments, selections, and utilities within resolvers.ExecutionContext
Generic base context for all resolvers and variable providers.Creates a Global ID for a given type and internal IDParameters:
type: Type<T>- The reflection type (e.g.,User.Reflection)internalID: String- Your internal identifier
GlobalID<T> - Type-safe Global IDExample:Value set as
ExecutionInput.requestContext by the service engineer. Use this to access deployment-specific request context like authentication, tracing, etc.FieldExecutionContext
Execution context provided to field resolvers.The parent object type containing this field
The query type for data fetching
The arguments type for this field
The return type (composite output)
The parent object value with selections from
objectValueFragment populated. Access is lazy - fields resolve on demand.Example:Returns a synchronously-accessible version of
objectValue where all selections have been eagerly resolved. Use when you need all object data available before proceeding.Access to root Query type selections. Useful for fetching additional data.
Field arguments provided by the caller
The selection set requested by the caller for the return type
NodeExecutionContext
Execution context for Node resolvers (non-selective).The Global ID of the node being resolvedExample:
SelectiveNodeExecutionContext
Extended context for Node resolvers implementingSelectiveResolver.
The selection set requested for this node. Only available when the resolver implements
SelectiveResolver.ConnectionFieldExecutionContext
Specialized execution context for Relay-style connection fields with pagination.viaduct.api.context
Stability: Experimental
Usage:
Used for fields marked with @connection that return paginated results. The arguments type A automatically includes pagination parameters like first, after, last, before.
MutationFieldExecutionContext
Execution context for root Mutation type field resolvers.Executes selections on the root Mutation typeParameters:
selections: String- GraphQL selections to executevariables: Map<String, Any?>- Optional variables (defaults to empty)
Field Values
FieldValue
Represents the result of resolving a GraphQL field, which may be either a value or an error.Returns the value on success, or throws an exception for an error value
Whether this represents an error value
Constructs a FieldValue that resolved successfullyExample:
Constructs a FieldValue that resolved with an error. Use
FieldError to customize the GraphQL error response.Example:See Also
- Service API - Entry point for executing GraphQL operations
- Engine API - Core GraphQL execution engine
- Directives - GraphQL directives for schema definition
- Module Plugin - Gradle plugin for Viaduct modules