Field Resolver Base
Base interface for field resolver implementations in the Java Tenant API.
This is the Java equivalent of Kotlin's ResolverBase<T>. Generated resolver base classes implement this interface, and tenant developers extend those generated classes.
Resolvers can implement either:
resolve(Context)for single-item resolutionbatchResolve(List)for batch resolution (more efficient)batchResolveWithErrors(List)for batch resolution with per-item FieldValue results
For batched fields, override either batch method. The runtime calls
batchResolveWithErrors, which defaults to wrapping each batchResolve value in
FieldValue.ofValue.
Single Resolution
Use for simple fields where each resolution is independent:
public class UserNameResolver extends UserNameResolverBase {
public CompletableFuture<String> resolve(Context ctx) {
User user = ctx.getObjectValue();
return CompletableFuture.completedFuture(
user.getFirstName() + " " + user.getLastName()
);
}
}
Batch Resolution
Use for fields that benefit from batching (e.g., database lookups) to prevent N+1 queries:
public class CharacterHomeworldResolver extends CharacterHomeworldResolverBase {
CharacterService characterService;
public CompletableFuture<Map<Context, Planet>> batchResolve(List<Context> contexts) {
List<String> characterIds = contexts.stream()
.map(ctx -> ctx.getObjectValue().getId())
.toList();
return characterService.fetchHomeworldsByCharacterIds(characterIds)
.thenApply(homeworlds -> matchContextsToHomeworlds(contexts, homeworlds));
}
}
Parameters
the return type of the resolver (the field's GraphQL type)
the parent object type containing this field
the Query root type
the arguments type for this field
the selections type for the output