Class ClassNameTypeResolver
java.lang.Object
org.springframework.graphql.execution.ClassNameTypeResolver
- All Implemented Interfaces:
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.- Since:
- 1.0.0
- Author:
- Rossen Stoyanchev
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMapping(Class<?> clazz, String graphQlTypeName) Add a mapping from a JavaClassto a GraphQL Object type name.getType(TypeResolutionEnvironment environment) voidsetClassNameExtractor(Function<Class<?>, String> classNameExtractor) Customize how the name of a class, or a base class/interface, is determined.
-
Constructor Details
-
ClassNameTypeResolver
public ClassNameTypeResolver()
-
-
Method Details
-
setClassNameExtractor
Customize how the name of a class, or a base class/interface, is determined. An application can use this to adapt to a common naming convention, e.g. remove an "Impl" suffix or a "Base" prefix, and so on.By default, this is just
Class.getSimpleName().- Parameters:
classNameExtractor- the function to use
-
addMapping
Add a mapping from a JavaClassto 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).- Parameters:
clazz- the Java class to mapgraphQlTypeName- the matching GraphQL object type
-
getType
- Specified by:
getTypein interfaceTypeResolver
-