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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addMapping
(Class<?> clazz, String graphQlTypeName) Add a mapping from a JavaClass
to a GraphQL Object type name.Return the map with configuredexplicit mappings
.getType
(TypeResolutionEnvironment environment) void
setClassNameExtractor
(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 JavaClass
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).- Parameters:
clazz
- the Java class to mapgraphQlTypeName
- the matching GraphQL object type
-
getMappings
Return the map with configuredexplicit mappings
.- Since:
- 1.3.0
-
getType
- Specified by:
getType
in interfaceTypeResolver
-