FieldResolverBase

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 resolution
  • batchResolve(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

<T>

the return type of the resolver (the field's GraphQL type)

<O>

the parent object type containing this field

<Q>

the Query root type

<A>

the arguments type for this field

<S>

the selections type for the output

Inheritors

Types

Link copied to clipboard
Context type alias for this resolver, providing type-safe access to object value, query value, arguments, and selections.