Package graphql.schema
Class GraphQLSchema
- java.lang.Object
-
- graphql.schema.GraphQLSchema
-
@PublicApi public class GraphQLSchema extends java.lang.Object
The schema represents the combined type system of the graphql engine. This is how the engine knows what graphql queries represent what data.See https://graphql.org/learn/schema/#type-language for more details
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGraphQLSchema.Builderstatic classGraphQLSchema.BuilderWithoutTypes
-
Constructor Summary
Constructors Constructor Description GraphQLSchema(GraphQLSchema.BuilderWithoutTypes builder)GraphQLSchema(GraphQLSchema existingSchema, GraphQLCodeRegistry codeRegistry, com.google.common.collect.ImmutableMap<java.lang.String,GraphQLNamedType> typeMap, com.google.common.collect.ImmutableMap<java.lang.String,com.google.common.collect.ImmutableList<GraphQLObjectType>> interfaceNameToObjectTypes)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleancontainsType(java.lang.String typeName)Returns true if the schema contains a type with the specified namejava.util.Set<GraphQLType>getAdditionalTypes()java.util.List<GraphQLNamedSchemaElement>getAllElementsAsList()This returns all the top levelGraphQLNamedSchemaElementnamed types and directives in the schemajava.util.Map<java.lang.String,java.util.List<GraphQLAppliedDirective>>getAllSchemaAppliedDirectivesByName()This returns a map of non-repeatable and repeatable directives that have been explicitly applied to the schema object.java.util.Map<java.lang.String,java.util.List<GraphQLDirective>>getAllSchemaDirectivesByName()Deprecated.Use theGraphQLAppliedDirectivemethods insteadjava.util.List<GraphQLNamedType>getAllTypesAsList()This returns all theGraphQLNamedTypenamed types in th schemaGraphQLCodeRegistrygetCodeRegistry()@Nullable SchemaDefinitiongetDefinition()@Nullable java.lang.StringgetDescription()GraphQLDirectivegetDirective(java.lang.String directiveName)Returns a named directive that (for legacy reasons) will be only in the set of non-repeatable directivesjava.util.List<GraphQLDirective>getDirectives()This returns the list of directives definitions that are associated with this schema object including built in ones.java.util.Map<java.lang.String,GraphQLDirective>getDirectivesByName()java.util.List<SchemaExtensionDefinition>getExtensionDefinitions()GraphQLFieldDefinitiongetFieldDefinition(FieldCoordinates fieldCoordinates)Returns aGraphQLFieldDefinitionas the specified co-ordinates or null if it does not existGraphqlFieldVisibilitygetFieldVisibility()Deprecated.useGraphQLCodeRegistry.getFieldVisibility()insteadjava.util.List<GraphQLObjectType>getImplementations(GraphQLInterfaceType type)This will return the list ofGraphQLObjectTypetypes that implement the given interface type.GraphQLFieldDefinitiongetIntrospectionSchemaFieldDefinition()GraphQLObjectTypegetIntrospectionSchemaType()GraphQLFieldDefinitiongetIntrospectionTypeFieldDefinition()GraphQLFieldDefinitiongetIntrospectionTypenameFieldDefinition()GraphQLObjectTypegetMutationType()GraphQLObjectTypegetObjectType(java.lang.String typeName)Called to return a namedGraphQLObjectTypefrom the schemaGraphQLObjectTypegetQueryType()GraphQLAppliedDirectivegetSchemaAppliedDirective(java.lang.String directiveName)This returns the named directive that have been explicitly applied to the schema object.java.util.List<GraphQLAppliedDirective>getSchemaAppliedDirectives()This returns the list of directives that have been explicitly applied to the schema object.java.util.List<GraphQLAppliedDirective>getSchemaAppliedDirectives(java.lang.String directiveName)GraphQLDirectivegetSchemaDirective(java.lang.String directiveName)Deprecated.Use theGraphQLAppliedDirectivemethods insteadjava.util.Map<java.lang.String,GraphQLDirective>getSchemaDirectiveByName()Deprecated.Use theGraphQLAppliedDirectivemethods insteadjava.util.List<GraphQLDirective>getSchemaDirectives()Deprecated.Use theGraphQLAppliedDirectivemethods insteadjava.util.List<GraphQLDirective>getSchemaDirectives(java.lang.String directiveName)Deprecated.Use theGraphQLAppliedDirectivemethods insteadGraphQLObjectTypegetSubscriptionType()@Nullable GraphQLTypegetType(@NotNull java.lang.String typeName)Gets the named type from the schema or null if it's not present<T extends GraphQLType>
TgetTypeAs(java.lang.String typeName)Gets the named type from the schema or null if it's not present.java.util.Map<java.lang.String,GraphQLNamedType>getTypeMap()<T extends GraphQLType>
java.util.List<T>getTypes(java.util.Collection<java.lang.String> typeNames)All types with the provided names.booleanisPossibleType(GraphQLNamedType abstractType, GraphQLObjectType concreteType)Returns true if a specified concrete type is a possible type of a provided abstract type.booleanisSupportingMutations()booleanisSupportingSubscriptions()static GraphQLSchema.BuildernewSchema()static GraphQLSchema.BuildernewSchema(GraphQLSchema existingSchema)This allows you to build a schema from an existing schema.GraphQLSchematransform(java.util.function.Consumer<GraphQLSchema.Builder> builderConsumer)This helps you transform the current GraphQLSchema object into another one by starting a builder with all the current values and allows you to transform it how you want.GraphQLSchematransformWithoutTypes(java.util.function.Consumer<GraphQLSchema.BuilderWithoutTypes> builderConsumer)This helps you transform the current GraphQLSchema object into another one by using a builder that only allows you to change simple values and does not involve changing the complex schema type graph.
-
-
-
Constructor Detail
-
GraphQLSchema
public GraphQLSchema(GraphQLSchema existingSchema, GraphQLCodeRegistry codeRegistry, com.google.common.collect.ImmutableMap<java.lang.String,GraphQLNamedType> typeMap, com.google.common.collect.ImmutableMap<java.lang.String,com.google.common.collect.ImmutableList<GraphQLObjectType>> interfaceNameToObjectTypes)
-
GraphQLSchema
public GraphQLSchema(GraphQLSchema.BuilderWithoutTypes builder)
-
-
Method Detail
-
getCodeRegistry
public GraphQLCodeRegistry getCodeRegistry()
-
getIntrospectionSchemaFieldDefinition
public GraphQLFieldDefinition getIntrospectionSchemaFieldDefinition()
- Returns:
- the special system field called "__schema"
-
getIntrospectionTypeFieldDefinition
public GraphQLFieldDefinition getIntrospectionTypeFieldDefinition()
- Returns:
- the special system field called "__type"
-
getIntrospectionTypenameFieldDefinition
public GraphQLFieldDefinition getIntrospectionTypenameFieldDefinition()
- Returns:
- the special system field called "__typename"
-
getIntrospectionSchemaType
public GraphQLObjectType getIntrospectionSchemaType()
-
getAdditionalTypes
public java.util.Set<GraphQLType> getAdditionalTypes()
-
getType
@Nullable public @Nullable GraphQLType getType(@NotNull @NotNull java.lang.String typeName)
Gets the named type from the schema or null if it's not present- Parameters:
typeName- the name of the type to retrieve- Returns:
- the type
-
getTypes
public <T extends GraphQLType> java.util.List<T> getTypes(java.util.Collection<java.lang.String> typeNames)
All types with the provided names. throwsAssertExceptionwhen a type name could not be resolved- Type Parameters:
T- for two- Parameters:
typeNames- the type names to get- Returns:
- The List of resolved types.
-
getTypeAs
public <T extends GraphQLType> T getTypeAs(java.lang.String typeName)
Gets the named type from the schema or null if it's not present.Warning - you are inviting class cast errors if the types are not what you expect.
- Type Parameters:
T- for two- Parameters:
typeName- the name of the type to retrieve- Returns:
- the type cast to the target type.
-
containsType
public boolean containsType(java.lang.String typeName)
Returns true if the schema contains a type with the specified name- Parameters:
typeName- the name of the type to check- Returns:
- true if there is a type with the specified name
-
getObjectType
public GraphQLObjectType getObjectType(java.lang.String typeName)
Called to return a namedGraphQLObjectTypefrom the schema- Parameters:
typeName- the name of the type- Returns:
- a graphql object type or null if there is one
- Throws:
GraphQLException- if the type is NOT an object type
-
getFieldDefinition
public GraphQLFieldDefinition getFieldDefinition(FieldCoordinates fieldCoordinates)
Returns aGraphQLFieldDefinitionas the specified co-ordinates or null if it does not exist- Parameters:
fieldCoordinates- the field co-ordinates- Returns:
- the field or null if it does not exist
-
getTypeMap
public java.util.Map<java.lang.String,GraphQLNamedType> getTypeMap()
- Returns:
- all the named types in the scheme as a map from name to named type
-
getAllTypesAsList
public java.util.List<GraphQLNamedType> getAllTypesAsList()
This returns all theGraphQLNamedTypenamed types in th schema- Returns:
- all the
GraphQLNamedTypetypes in the schema
-
getAllElementsAsList
public java.util.List<GraphQLNamedSchemaElement> getAllElementsAsList()
This returns all the top levelGraphQLNamedSchemaElementnamed types and directives in the schema- Returns:
- all the top level
GraphQLNamedSchemaElementtypes and directives in the schema
-
getImplementations
public java.util.List<GraphQLObjectType> getImplementations(GraphQLInterfaceType type)
This will return the list ofGraphQLObjectTypetypes that implement the given interface type.- Parameters:
type- interface type to obtain implementations of.- Returns:
- list of types implementing provided interface
-
isPossibleType
public boolean isPossibleType(GraphQLNamedType abstractType, GraphQLObjectType concreteType)
Returns true if a specified concrete type is a possible type of a provided abstract type. If the provided abstract type is: - an interface, it checks whether the concrete type is one of its implementations. - a union, it checks whether the concrete type is one of its possible types.- Parameters:
abstractType- abstract type either interface or unionconcreteType- concrete type- Returns:
- true if possible type, false otherwise.
-
getQueryType
public GraphQLObjectType getQueryType()
- Returns:
- the Query type of the schema
-
getMutationType
public GraphQLObjectType getMutationType()
- Returns:
- the Mutation type of the schema of null if there is not one
-
getSubscriptionType
public GraphQLObjectType getSubscriptionType()
- Returns:
- the Subscription type of the schema of null if there is not one
-
getFieldVisibility
@Deprecated(since="2018-12-03") public GraphqlFieldVisibility getFieldVisibility()
Deprecated.useGraphQLCodeRegistry.getFieldVisibility()instead- Returns:
- the field visibility
-
getDirectives
public java.util.List<GraphQLDirective> getDirectives()
This returns the list of directives definitions that are associated with this schema object including built in ones.- Returns:
- a list of directives
-
getDirectivesByName
public java.util.Map<java.lang.String,GraphQLDirective> getDirectivesByName()
- Returns:
- a map of non-repeatable directives by directive name
-
getDirective
public GraphQLDirective getDirective(java.lang.String directiveName)
Returns a named directive that (for legacy reasons) will be only in the set of non-repeatable directives- Parameters:
directiveName- the name of the directive to retrieve- Returns:
- the directive or null if there is not one with that name
-
getSchemaDirectives
@Deprecated(since="2022-02-24") public java.util.List<GraphQLDirective> getSchemaDirectives()
Deprecated.Use theGraphQLAppliedDirectivemethods insteadThis returns the list of directives that have been explicitly applied to the schema object. Note thatgetDirectives()will return directives for all schema elements, whereas this is just for the schema element itself- Returns:
- a list of directives
-
getSchemaDirectiveByName
@Deprecated(since="2022-02-24") public java.util.Map<java.lang.String,GraphQLDirective> getSchemaDirectiveByName()
Deprecated.Use theGraphQLAppliedDirectivemethods insteadThis returns a map of non-repeatable directives that have been explicitly applied to the schema object. Note thatgetDirectives()will return directives for all schema elements, whereas this is just for the schema element itself- Returns:
- a map of directives
-
getAllSchemaDirectivesByName
@Deprecated(since="2022-02-24") public java.util.Map<java.lang.String,java.util.List<GraphQLDirective>> getAllSchemaDirectivesByName()
Deprecated.Use theGraphQLAppliedDirectivemethods insteadThis returns a map of non-repeatable and repeatable directives that have been explicitly applied to the schema object. Note thatgetDirectives()will return directives for all schema elements, whereas this is just for the schema element itself- Returns:
- a map of directives
-
getSchemaDirective
@Deprecated(since="2022-02-24") public GraphQLDirective getSchemaDirective(java.lang.String directiveName)
Deprecated.Use theGraphQLAppliedDirectivemethods insteadThis returns the named directive that have been explicitly applied to the schema object. Note thatGraphQLDirectiveContainer.getDirective(String)will return directives for all schema elements, whereas this is just for the schema element itself- Parameters:
directiveName- the name of the directive- Returns:
- a named directive
-
getSchemaDirectives
@Deprecated(since="2022-02-24") public java.util.List<GraphQLDirective> getSchemaDirectives(java.lang.String directiveName)
Deprecated.Use theGraphQLAppliedDirectivemethods insteadThis returns the named directives that have been explicitly applied to the schema object.- Parameters:
directiveName- the name of the directive- Returns:
- A list of repeated applied directives
-
getSchemaAppliedDirectives
public java.util.List<GraphQLAppliedDirective> getSchemaAppliedDirectives()
This returns the list of directives that have been explicitly applied to the schema object. Note thatgetDirectives()will return directives for all schema elements, whereas this is just for the schema element itself- Returns:
- a list of directives
-
getAllSchemaAppliedDirectivesByName
public java.util.Map<java.lang.String,java.util.List<GraphQLAppliedDirective>> getAllSchemaAppliedDirectivesByName()
This returns a map of non-repeatable and repeatable directives that have been explicitly applied to the schema object. Note thatgetDirectives()will return directives for all schema elements, whereas this is just for the schema element itself- Returns:
- a map of all schema directives by directive name
-
getSchemaAppliedDirective
public GraphQLAppliedDirective getSchemaAppliedDirective(java.lang.String directiveName)
This returns the named directive that have been explicitly applied to the schema object. Note thatGraphQLDirectiveContainer.getDirective(String)will return directives for all schema elements, whereas this is just for the schema element itself- Parameters:
directiveName- the name of the directive- Returns:
- a named directive
-
getSchemaAppliedDirectives
public java.util.List<GraphQLAppliedDirective> getSchemaAppliedDirectives(java.lang.String directiveName)
-
getDefinition
@Nullable public @Nullable SchemaDefinition getDefinition()
-
getExtensionDefinitions
public java.util.List<SchemaExtensionDefinition> getExtensionDefinitions()
-
isSupportingMutations
public boolean isSupportingMutations()
-
isSupportingSubscriptions
public boolean isSupportingSubscriptions()
-
getDescription
@Nullable public @Nullable java.lang.String getDescription()
-
transform
public GraphQLSchema transform(java.util.function.Consumer<GraphQLSchema.Builder> builderConsumer)
This helps you transform the current GraphQLSchema object into another one by starting a builder with all the current values and allows you to transform it how you want.- Parameters:
builderConsumer- the consumer code that will be given a builder to transform- Returns:
- a new GraphQLSchema object based on calling built on that builder
-
transformWithoutTypes
public GraphQLSchema transformWithoutTypes(java.util.function.Consumer<GraphQLSchema.BuilderWithoutTypes> builderConsumer)
This helps you transform the current GraphQLSchema object into another one by using a builder that only allows you to change simple values and does not involve changing the complex schema type graph.- Parameters:
builderConsumer- the consumer code that will be given a builder to transform- Returns:
- a new GraphQLSchema object based on calling built on that builder
-
newSchema
public static GraphQLSchema.Builder newSchema()
- Returns:
- a new schema builder
-
newSchema
public static GraphQLSchema.Builder newSchema(GraphQLSchema existingSchema)
This allows you to build a schema from an existing schema. It copies everything from the existing schema and then allows you to replace them.- Parameters:
existingSchema- the existing schema- Returns:
- a new schema builder
-
-