Class ClassNameTypeResolver

java.lang.Object
org.springframework.graphql.execution.ClassNameTypeResolver
All Implemented Interfaces:
TypeResolver

public class ClassNameTypeResolver extends Object implements 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 Details

    • ClassNameTypeResolver

      public ClassNameTypeResolver()
  • Method Details

    • setClassNameExtractor

      public void setClassNameExtractor(Function<Class<?>,String> classNameExtractor)
      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

      public void addMapping(Class<?> clazz, String graphQlTypeName)
      Add a mapping from a Java 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).
      Parameters:
      clazz - the Java class to map
      graphQlTypeName - the matching GraphQL object type
    • getMappings

      public Map<Class<?>,String> getMappings()
      Return the map with configured explicit mappings.
      Since:
      1.3.0
    • getType

      Specified by:
      getType in interface TypeResolver