Class TypeDefinitionRegistry

java.lang.Object
graphql.schema.idl.TypeDefinitionRegistry
All Implemented Interfaces:
Serializable

@PublicApi @NullMarked public class TypeDefinitionRegistry extends Object implements Serializable
A TypeDefinitionRegistry contains the set of type definitions that come from compiling a graphql schema definition file via SchemaParser.parse(String)
See Also:
  • Constructor Details

    • TypeDefinitionRegistry

      public TypeDefinitionRegistry()
  • Method Details

    • getParseOrder

      public SchemaParseOrder getParseOrder()
      Returns:
      the order in which SDLDefinitions were parsed
    • merge

      public TypeDefinitionRegistry merge(TypeDefinitionRegistry typeRegistry) throws SchemaProblem
      This will merge these type registries together and return this one
      Parameters:
      typeRegistry - the registry to be merged into this one
      Returns:
      this registry
      Throws:
      SchemaProblem - if there are problems merging the types such as redefinitions
    • addAll

      public Optional<GraphQLError> addAll(Collection<SDLDefinition> definitions)
      Adds a a collections of definitions to the registry
      Parameters:
      definitions - the definitions to add
      Returns:
      an optional error for the first problem, typically type redefinition
    • add

      public Optional<GraphQLError> add(SDLDefinition definition)
      Adds a definition to the registry
      Parameters:
      definition - the definition to add
      Returns:
      an optional error
    • remove

      public void remove(SDLDefinition definition)
      Removes a SDLDefinition from the definition list.
      Parameters:
      definition - the definition to remove
    • remove

      public void remove(String key, SDLDefinition definition)
      Removes a SDLDefinition from a map.
      Parameters:
      key - the key to remove
      definition - the definition to remove
    • types

      public Map<String,TypeDefinition> types()
    • scalars

      public Map<String,ScalarTypeDefinition> scalars()
    • objectTypeExtensions

      public Map<String,List<ObjectTypeExtensionDefinition>> objectTypeExtensions()
    • interfaceTypeExtensions

      public Map<String,List<InterfaceTypeExtensionDefinition>> interfaceTypeExtensions()
    • unionTypeExtensions

      public Map<String,List<UnionTypeExtensionDefinition>> unionTypeExtensions()
    • enumTypeExtensions

      public Map<String,List<EnumTypeExtensionDefinition>> enumTypeExtensions()
    • scalarTypeExtensions

      public Map<String,List<ScalarTypeExtensionDefinition>> scalarTypeExtensions()
    • inputObjectTypeExtensions

      public Map<String,List<InputObjectTypeExtensionDefinition>> inputObjectTypeExtensions()
    • schemaDefinition

      public Optional<SchemaDefinition> schemaDefinition()
    • getSchemaExtensionDefinitions

      public List<SchemaExtensionDefinition> getSchemaExtensionDefinitions()
    • getDirectiveDefinition

      public Optional<DirectiveDefinition> getDirectiveDefinition(String directiveName)
    • getDirectiveDefinitions

      public Map<String,DirectiveDefinition> getDirectiveDefinitions()
    • hasType

      public boolean hasType(TypeName typeName)
    • getType

      public Optional<TypeDefinition> getType(Type type)
    • getType

      public <T extends TypeDefinition> Optional<T> getType(Type type, Class<T> ofType)
    • getType

      public Optional<TypeDefinition> getType(String typeName)
    • getType

      public <T extends TypeDefinition> Optional<T> getType(String typeName, Class<T> ofType)
    • isInterfaceOrUnion

      public boolean isInterfaceOrUnion(Type type)
      Returns true if the specified type exists in the registry and is an abstract (Interface or Union) type
      Parameters:
      type - the type to check
      Returns:
      true if its abstract
    • isObjectTypeOrInterface

      public boolean isObjectTypeOrInterface(Type type)
      Returns true if the specified type exists in the registry and is an object type or interface
      Parameters:
      type - the type to check
      Returns:
      true if its an object type or interface
    • isObjectType

      public boolean isObjectType(Type type)
      Returns true if the specified type exists in the registry and is an object type
      Parameters:
      type - the type to check
      Returns:
      true if its an object type
    • getTypes

      public <T extends TypeDefinition> List<T> getTypes(Class<T> targetClass)
      Returns a list of types in the registry of that specified class
      Type Parameters:
      T - must extend TypeDefinition
      Parameters:
      targetClass - the class to search for
      Returns:
      a list of types of the target class
    • getTypesMap

      public <T extends TypeDefinition> Map<String,T> getTypesMap(Class<T> targetClass)
      Returns a map of types in the registry of that specified class keyed by name
      Type Parameters:
      T - must extend TypeDefinition
      Parameters:
      targetClass - the class to search for
      Returns:
      a map of types
    • getAllImplementationsOf

      public List<ImplementingTypeDefinition> getAllImplementationsOf(InterfaceTypeDefinition targetInterface)
      Returns the list of object and interface types that implement the given interface type
      Parameters:
      targetInterface - the target to search for
      Returns:
      the list of object types that implement the given interface type
      See Also:
    • getImplementationsOf

      public List<ObjectTypeDefinition> getImplementationsOf(InterfaceTypeDefinition targetInterface)
      Returns the list of object interface types that implement the given interface type
      Parameters:
      targetInterface - the target to search for
      Returns:
      the list of object types that implement the given interface type
      See Also:
    • isPossibleType

      public boolean isPossibleType(Type abstractType, Type possibleType)
      Returns true of the abstract type is in implemented by the object type or interface
      Parameters:
      abstractType - the abstract type to check (interface or union)
      possibleType - the object type or interface to check
      Returns:
      true if the object type or interface implements the abstract type
    • isSubTypeOf

      public boolean isSubTypeOf(Type maybeSubType, Type superType)
      Returns true if the maybe type is either equal or a subset of the second super type (covariant).
      Parameters:
      maybeSubType - the type to check
      superType - the equality checked type
      Returns:
      true if maybeSubType is covariant or equal to superType