Package graphql.schema.idl
Class TypeDefinitionRegistry
- java.lang.Object
-
- graphql.schema.idl.TypeDefinitionRegistry
-
- All Implemented Interfaces:
java.io.Serializable
@PublicApi public class TypeDefinitionRegistry extends java.lang.Object implements java.io.Serializable
ATypeDefinitionRegistry
contains the set of type definitions that come from compiling a graphql schema definition file viaSchemaParser.parse(String)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,DirectiveDefinition>
directiveDefinitions
private java.util.Map<java.lang.String,java.util.List<EnumTypeExtensionDefinition>>
enumTypeExtensions
private java.util.Map<java.lang.String,java.util.List<InputObjectTypeExtensionDefinition>>
inputObjectTypeExtensions
private java.util.Map<java.lang.String,java.util.List<InterfaceTypeExtensionDefinition>>
interfaceTypeExtensions
private java.util.Map<java.lang.String,java.util.List<ObjectTypeExtensionDefinition>>
objectTypeExtensions
private java.util.Map<java.lang.String,java.util.List<ScalarTypeExtensionDefinition>>
scalarTypeExtensions
private java.util.Map<java.lang.String,ScalarTypeDefinition>
scalarTypes
private SchemaDefinition
schema
private java.util.List<SchemaExtensionDefinition>
schemaExtensionDefinitions
private SchemaParseOrder
schemaParseOrder
private java.util.Map<java.lang.String,TypeDefinition>
types
private java.util.Map<java.lang.String,java.util.List<UnionTypeExtensionDefinition>>
unionTypeExtensions
-
Constructor Summary
Constructors Constructor Description TypeDefinitionRegistry()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Optional<GraphQLError>
add(SDLDefinition definition)
Adds a definition to the registryjava.util.Optional<GraphQLError>
addAll(java.util.Collection<SDLDefinition> definitions)
Adds a a collections of definitions to the registryprivate java.util.Optional<GraphQLError>
checkAddOperationDefs()
private java.util.Map<java.lang.String,OperationTypeDefinition>
checkMergeSchemaDefs(TypeDefinitionRegistry toBeMergedTypeRegistry, java.util.List<GraphQLError> errors)
private <T extends TypeDefinition>
java.util.Optional<GraphQLError>define(java.util.Map<java.lang.String,T> source, java.util.Map<java.lang.String,T> target, T newEntry)
private <T extends TypeDefinition>
java.util.Optional<GraphQLError>defineExt(java.util.Map<java.lang.String,java.util.List<T>> typeExtensions, T newEntry, java.util.function.Function<T,java.lang.String> namerFunc)
java.util.Map<java.lang.String,java.util.List<EnumTypeExtensionDefinition>>
enumTypeExtensions()
java.util.List<ImplementingTypeDefinition>
getAllImplementationsOf(InterfaceTypeDefinition targetInterface)
Returns the list of object and interface types that implement the given interface typejava.util.Optional<DirectiveDefinition>
getDirectiveDefinition(java.lang.String directiveName)
java.util.Map<java.lang.String,DirectiveDefinition>
getDirectiveDefinitions()
java.util.List<ObjectTypeDefinition>
getImplementationsOf(InterfaceTypeDefinition targetInterface)
Returns the list of object interface types that implement the given interface typeSchemaParseOrder
getParseOrder()
java.util.List<SchemaExtensionDefinition>
getSchemaExtensionDefinitions()
java.util.Optional<TypeDefinition>
getType(Type type)
<T extends TypeDefinition>
java.util.Optional<T>getType(Type type, java.lang.Class<T> ofType)
java.util.Optional<TypeDefinition>
getType(java.lang.String typeName)
<T extends TypeDefinition>
java.util.Optional<T>getType(java.lang.String typeName, java.lang.Class<T> ofType)
<T extends TypeDefinition>
java.util.List<T>getTypes(java.lang.Class<T> targetClass)
Returns a list of types in the registry of that specified class<T extends TypeDefinition>
java.util.Map<java.lang.String,T>getTypesMap(java.lang.Class<T> targetClass)
Returns a map of types in the registry of that specified class keyed by nameprivate GraphQLError
handleReDefinition(DirectiveDefinition oldEntry, DirectiveDefinition newEntry)
private GraphQLError
handleReDefinition(TypeDefinition oldEntry, TypeDefinition newEntry)
boolean
hasType(TypeName typeName)
java.util.Map<java.lang.String,java.util.List<InputObjectTypeExtensionDefinition>>
inputObjectTypeExtensions()
java.util.Map<java.lang.String,java.util.List<InterfaceTypeExtensionDefinition>>
interfaceTypeExtensions()
boolean
isInterfaceOrUnion(Type type)
Returns true if the specified type exists in the registry and is an abstract (Interface or Union) typeboolean
isObjectType(Type type)
Returns true if the specified type exists in the registry and is an object typeboolean
isObjectTypeOrInterface(Type type)
Returns true if the specified type exists in the registry and is an object type or interfaceboolean
isPossibleType(Type abstractType, Type possibleType)
Returns true of the abstract type is in implemented by the object type or interfaceboolean
isSubTypeOf(Type maybeSubType, Type superType)
Returns true if the maybe type is either equal or a subset of the second super type (covariant).TypeDefinitionRegistry
merge(TypeDefinitionRegistry typeRegistry)
This will merge these type registries together and return this onejava.util.Map<java.lang.String,java.util.List<ObjectTypeExtensionDefinition>>
objectTypeExtensions()
void
remove(SDLDefinition definition)
Removes aSDLDefinition
from the definition list.void
remove(java.lang.String key, SDLDefinition definition)
Removes aSDLDefinition
from a map.private void
removeFromList(java.util.Map source, TypeDefinition value)
private void
removeFromMap(java.util.Map source, java.lang.String key)
java.util.Map<java.lang.String,ScalarTypeDefinition>
scalars()
java.util.Map<java.lang.String,java.util.List<ScalarTypeExtensionDefinition>>
scalarTypeExtensions()
java.util.Optional<SchemaDefinition>
schemaDefinition()
java.util.Map<java.lang.String,TypeDefinition>
types()
java.util.Map<java.lang.String,java.util.List<UnionTypeExtensionDefinition>>
unionTypeExtensions()
-
-
-
Field Detail
-
objectTypeExtensions
private final java.util.Map<java.lang.String,java.util.List<ObjectTypeExtensionDefinition>> objectTypeExtensions
-
interfaceTypeExtensions
private final java.util.Map<java.lang.String,java.util.List<InterfaceTypeExtensionDefinition>> interfaceTypeExtensions
-
unionTypeExtensions
private final java.util.Map<java.lang.String,java.util.List<UnionTypeExtensionDefinition>> unionTypeExtensions
-
enumTypeExtensions
private final java.util.Map<java.lang.String,java.util.List<EnumTypeExtensionDefinition>> enumTypeExtensions
-
scalarTypeExtensions
private final java.util.Map<java.lang.String,java.util.List<ScalarTypeExtensionDefinition>> scalarTypeExtensions
-
inputObjectTypeExtensions
private final java.util.Map<java.lang.String,java.util.List<InputObjectTypeExtensionDefinition>> inputObjectTypeExtensions
-
types
private final java.util.Map<java.lang.String,TypeDefinition> types
-
scalarTypes
private final java.util.Map<java.lang.String,ScalarTypeDefinition> scalarTypes
-
directiveDefinitions
private final java.util.Map<java.lang.String,DirectiveDefinition> directiveDefinitions
-
schema
private SchemaDefinition schema
-
schemaExtensionDefinitions
private final java.util.List<SchemaExtensionDefinition> schemaExtensionDefinitions
-
schemaParseOrder
private final SchemaParseOrder schemaParseOrder
-
-
Method Detail
-
getParseOrder
public SchemaParseOrder getParseOrder()
- Returns:
- the order in which
SDLDefinition
s 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
-
checkMergeSchemaDefs
private java.util.Map<java.lang.String,OperationTypeDefinition> checkMergeSchemaDefs(TypeDefinitionRegistry toBeMergedTypeRegistry, java.util.List<GraphQLError> errors)
-
checkAddOperationDefs
private java.util.Optional<GraphQLError> checkAddOperationDefs()
-
addAll
public java.util.Optional<GraphQLError> addAll(java.util.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 java.util.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 aSDLDefinition
from the definition list.- Parameters:
definition
- the definition to remove
-
removeFromList
private void removeFromList(java.util.Map source, TypeDefinition value)
-
remove
public void remove(java.lang.String key, SDLDefinition definition)
Removes aSDLDefinition
from a map.- Parameters:
key
- the key to removedefinition
- the definition to remove
-
removeFromMap
private void removeFromMap(java.util.Map source, java.lang.String key)
-
define
private <T extends TypeDefinition> java.util.Optional<GraphQLError> define(java.util.Map<java.lang.String,T> source, java.util.Map<java.lang.String,T> target, T newEntry)
-
define
private <T extends DirectiveDefinition> java.util.Optional<GraphQLError> define(java.util.Map<java.lang.String,T> source, java.util.Map<java.lang.String,T> target, T newEntry)
-
defineExt
private <T extends TypeDefinition> java.util.Optional<GraphQLError> defineExt(java.util.Map<java.lang.String,java.util.List<T>> typeExtensions, T newEntry, java.util.function.Function<T,java.lang.String> namerFunc)
-
types
public java.util.Map<java.lang.String,TypeDefinition> types()
-
scalars
public java.util.Map<java.lang.String,ScalarTypeDefinition> scalars()
-
objectTypeExtensions
public java.util.Map<java.lang.String,java.util.List<ObjectTypeExtensionDefinition>> objectTypeExtensions()
-
interfaceTypeExtensions
public java.util.Map<java.lang.String,java.util.List<InterfaceTypeExtensionDefinition>> interfaceTypeExtensions()
-
unionTypeExtensions
public java.util.Map<java.lang.String,java.util.List<UnionTypeExtensionDefinition>> unionTypeExtensions()
-
enumTypeExtensions
public java.util.Map<java.lang.String,java.util.List<EnumTypeExtensionDefinition>> enumTypeExtensions()
-
scalarTypeExtensions
public java.util.Map<java.lang.String,java.util.List<ScalarTypeExtensionDefinition>> scalarTypeExtensions()
-
inputObjectTypeExtensions
public java.util.Map<java.lang.String,java.util.List<InputObjectTypeExtensionDefinition>> inputObjectTypeExtensions()
-
schemaDefinition
public java.util.Optional<SchemaDefinition> schemaDefinition()
-
getSchemaExtensionDefinitions
public java.util.List<SchemaExtensionDefinition> getSchemaExtensionDefinitions()
-
handleReDefinition
private GraphQLError handleReDefinition(TypeDefinition oldEntry, TypeDefinition newEntry)
-
handleReDefinition
private GraphQLError handleReDefinition(DirectiveDefinition oldEntry, DirectiveDefinition newEntry)
-
getDirectiveDefinition
public java.util.Optional<DirectiveDefinition> getDirectiveDefinition(java.lang.String directiveName)
-
getDirectiveDefinitions
public java.util.Map<java.lang.String,DirectiveDefinition> getDirectiveDefinitions()
-
hasType
public boolean hasType(TypeName typeName)
-
getType
public java.util.Optional<TypeDefinition> getType(Type type)
-
getType
public <T extends TypeDefinition> java.util.Optional<T> getType(Type type, java.lang.Class<T> ofType)
-
getType
public java.util.Optional<TypeDefinition> getType(java.lang.String typeName)
-
getType
public <T extends TypeDefinition> java.util.Optional<T> getType(java.lang.String typeName, java.lang.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> java.util.List<T> getTypes(java.lang.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> java.util.Map<java.lang.String,T> getTypesMap(java.lang.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 java.util.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(InterfaceTypeDefinition)
-
getImplementationsOf
public java.util.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:
getAllImplementationsOf(InterfaceTypeDefinition)
-
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 checksuperType
- the equality checked type- Returns:
- true if maybeSubType is covariant or equal to superType
-
-