public class ClassNameTypeResolver
extends java.lang.Object
implements graphql.schema.TypeResolver
TypeResolver that tries to find a GraphQL Object type based on the
class name of a value returned from a DataFetcher. If necessary, it
walks up the base class and interface hierarchy to find a match.| Constructor and Description |
|---|
ClassNameTypeResolver() |
| Modifier and Type | Method and Description |
|---|---|
void |
addMapping(java.lang.Class<?> clazz,
java.lang.String graphQlTypeName)
Add a mapping from a Java
Class to a GraphQL Object type name. |
graphql.schema.GraphQLObjectType |
getType(graphql.TypeResolutionEnvironment environment) |
void |
setClassNameExtractor(java.util.function.Function<java.lang.Class<?>,java.lang.String> classNameExtractor)
Customize how the name of a class, or a base class/interface, is determined.
|
public void setClassNameExtractor(java.util.function.Function<java.lang.Class<?>,java.lang.String> classNameExtractor)
By default, this is just Class.getSimpleName().
classNameExtractor - the function to usepublic void addMapping(java.lang.Class<?> clazz,
java.lang.String graphQlTypeName)
Class to a GraphQL Object type name.
The mapping applies to the given type and to all of its sub-classes
(for a base class) or implementations (for an interface).clazz - the Java class to mapgraphQlTypeName - the matching GraphQL object type@Nullable public graphql.schema.GraphQLObjectType getType(graphql.TypeResolutionEnvironment environment)
getType in interface graphql.schema.TypeResolver