Package graphql.schema
Class GraphQLDirective
- java.lang.Object
-
- graphql.schema.GraphQLDirective
-
- All Implemented Interfaces:
GraphQLNamedSchemaElement
,GraphQLSchemaElement
@PublicApi public class GraphQLDirective extends java.lang.Object implements GraphQLNamedSchemaElement
A directive can be used to modify the behavior of a graphql field or type.See https://graphql.org/learn/queries/#directives for more details on the concept.
A directive has a definition, that is what arguments it takes, and it can also be applied to other schema elements. Originally graphql-java re-used the
GraphQLDirective
andGraphQLArgument
classes to do both purposes. This was a modelling mistake. NewGraphQLAppliedDirective
andGraphQLAppliedDirectiveArgument
classes have been introduced to better model when a directive is applied to a schema element, as opposed to its schema definition itself.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GraphQLDirective.Builder
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CHILD_ARGUMENTS
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description TraversalControl
accept(TraverserContext<GraphQLSchemaElement> context, GraphQLTypeVisitor visitor)
GraphQLSchemaElement
copy()
Each GraphQLSchemaElement should make a copy of itself when this is called.boolean
equals(java.lang.Object o)
No GraphQLSchemaElement implements `equals` because we need object identity to treat a GraphQLSchema as an abstract graph.GraphQLArgument
getArgument(java.lang.String name)
java.util.List<GraphQLArgument>
getArguments()
java.util.List<GraphQLSchemaElement>
getChildren()
SchemaElementChildrenContainer
getChildrenWithTypeReferences()
DirectiveDefinition
getDefinition()
The ASTNode
this schema element is based on.java.lang.String
getDescription()
java.lang.String
getName()
int
hashCode()
No GraphQLSchemaElement implements `equals/hashCode` because we need object identity to treat a GraphQLSchema as an abstract graph.boolean
isNonRepeatable()
boolean
isRepeatable()
static GraphQLDirective.Builder
newDirective()
static GraphQLDirective.Builder
newDirective(GraphQLDirective existing)
GraphQLAppliedDirective
toAppliedDirective()
This method can be used to turn a directive that was being use as an applied directive into one.java.lang.String
toString()
GraphQLDirective
transform(java.util.function.Consumer<GraphQLDirective.Builder> builderConsumer)
This helps you transform the current GraphQLDirective into another one by starting a builder with all the current values and allows you to transform it how you want.java.util.EnumSet<Introspection.DirectiveLocation>
validLocations()
GraphQLDirective
withNewChildren(SchemaElementChildrenContainer newChildren)
-
-
-
Field Detail
-
CHILD_ARGUMENTS
public static final java.lang.String CHILD_ARGUMENTS
- See Also:
- Constant Field Values
-
-
Method Detail
-
getName
public java.lang.String getName()
- Specified by:
getName
in interfaceGraphQLNamedSchemaElement
- Returns:
- the name of this element. This cant be null
-
isRepeatable
public boolean isRepeatable()
-
isNonRepeatable
public boolean isNonRepeatable()
-
getArguments
public java.util.List<GraphQLArgument> getArguments()
-
getArgument
public GraphQLArgument getArgument(java.lang.String name)
-
validLocations
public java.util.EnumSet<Introspection.DirectiveLocation> validLocations()
-
getDescription
public java.lang.String getDescription()
- Specified by:
getDescription
in interfaceGraphQLNamedSchemaElement
- Returns:
- the description of this element. This can be null
-
getDefinition
public DirectiveDefinition getDefinition()
Description copied from interface:GraphQLNamedSchemaElement
The ASTNode
this schema element is based on. Is null if the GraphQLSchema is not based on a SDL document. Some elements also have additional extension Nodes. See for exampleGraphQLObjectType.getExtensionDefinitions()
- Specified by:
getDefinition
in interfaceGraphQLNamedSchemaElement
- Returns:
- Node which this element is based on. Can be null.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
transform
public GraphQLDirective transform(java.util.function.Consumer<GraphQLDirective.Builder> builderConsumer)
This helps you transform the current GraphQLDirective 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 field based on calling build on that builder
-
copy
public GraphQLSchemaElement copy()
Description copied from interface:GraphQLSchemaElement
Each GraphQLSchemaElement should make a copy of itself when this is called. The copy should be included its current contents as they currently exist into a new object.- Specified by:
copy
in interfaceGraphQLSchemaElement
- Returns:
- a copy of this element
-
accept
public TraversalControl accept(TraverserContext<GraphQLSchemaElement> context, GraphQLTypeVisitor visitor)
- Specified by:
accept
in interfaceGraphQLSchemaElement
-
getChildren
public java.util.List<GraphQLSchemaElement> getChildren()
- Specified by:
getChildren
in interfaceGraphQLSchemaElement
-
getChildrenWithTypeReferences
public SchemaElementChildrenContainer getChildrenWithTypeReferences()
- Specified by:
getChildrenWithTypeReferences
in interfaceGraphQLSchemaElement
-
withNewChildren
public GraphQLDirective withNewChildren(SchemaElementChildrenContainer newChildren)
- Specified by:
withNewChildren
in interfaceGraphQLSchemaElement
-
toAppliedDirective
public GraphQLAppliedDirective toAppliedDirective()
This method can be used to turn a directive that was being use as an applied directive into one.- Returns:
- an
GraphQLAppliedDirective
-
equals
public final boolean equals(java.lang.Object o)
No GraphQLSchemaElement implements `equals` because we need object identity to treat a GraphQLSchema as an abstract graph.- Specified by:
equals
in interfaceGraphQLSchemaElement
- Overrides:
equals
in classjava.lang.Object
- Parameters:
o
- the reference object with which to compare.- Returns:
true
if this object is the same as the obj argument;false
otherwise.
-
hashCode
public final int hashCode()
No GraphQLSchemaElement implements `equals/hashCode` because we need object identity to treat a GraphQLSchema as an abstract graph.- Specified by:
hashCode
in interfaceGraphQLSchemaElement
- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- a hash code value for this object.
-
newDirective
public static GraphQLDirective.Builder newDirective()
-
newDirective
public static GraphQLDirective.Builder newDirective(GraphQLDirective existing)
-
-