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
GraphQLDirectiveandGraphQLArgumentclasses to do both purposes. This was a modelling mistake. NewGraphQLAppliedDirectiveandGraphQLAppliedDirectiveArgumentclasses 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 classGraphQLDirective.Builder
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCHILD_ARGUMENTS
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description TraversalControlaccept(TraverserContext<GraphQLSchemaElement> context, GraphQLTypeVisitor visitor)GraphQLSchemaElementcopy()Each GraphQLSchemaElement should make a copy of itself when this is called.booleanequals(java.lang.Object o)No GraphQLSchemaElement implements `equals` because we need object identity to treat a GraphQLSchema as an abstract graph.GraphQLArgumentgetArgument(java.lang.String name)java.util.List<GraphQLArgument>getArguments()java.util.List<GraphQLSchemaElement>getChildren()SchemaElementChildrenContainergetChildrenWithTypeReferences()DirectiveDefinitiongetDefinition()The ASTNodethis schema element is based on.java.lang.StringgetDescription()java.lang.StringgetName()inthashCode()No GraphQLSchemaElement implements `equals/hashCode` because we need object identity to treat a GraphQLSchema as an abstract graph.booleanisNonRepeatable()booleanisRepeatable()static GraphQLDirective.BuildernewDirective()static GraphQLDirective.BuildernewDirective(GraphQLDirective existing)GraphQLAppliedDirectivetoAppliedDirective()This method can be used to turn a directive that was being use as an applied directive into one.java.lang.StringtoString()GraphQLDirectivetransform(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()GraphQLDirectivewithNewChildren(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:
getNamein 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:
getDescriptionin interfaceGraphQLNamedSchemaElement- Returns:
- the description of this element. This can be null
-
getDefinition
public DirectiveDefinition getDefinition()
Description copied from interface:GraphQLNamedSchemaElementThe ASTNodethis 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:
getDefinitionin interfaceGraphQLNamedSchemaElement- Returns:
- Node which this element is based on. Can be null.
-
toString
public java.lang.String toString()
- Overrides:
toStringin 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:GraphQLSchemaElementEach 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:
copyin interfaceGraphQLSchemaElement- Returns:
- a copy of this element
-
accept
public TraversalControl accept(TraverserContext<GraphQLSchemaElement> context, GraphQLTypeVisitor visitor)
- Specified by:
acceptin interfaceGraphQLSchemaElement
-
getChildren
public java.util.List<GraphQLSchemaElement> getChildren()
- Specified by:
getChildrenin interfaceGraphQLSchemaElement
-
getChildrenWithTypeReferences
public SchemaElementChildrenContainer getChildrenWithTypeReferences()
- Specified by:
getChildrenWithTypeReferencesin interfaceGraphQLSchemaElement
-
withNewChildren
public GraphQLDirective withNewChildren(SchemaElementChildrenContainer newChildren)
- Specified by:
withNewChildrenin 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:
equalsin interfaceGraphQLSchemaElement- Overrides:
equalsin classjava.lang.Object- Parameters:
o- the reference object with which to compare.- Returns:
trueif this object is the same as the obj argument;falseotherwise.
-
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:
hashCodein interfaceGraphQLSchemaElement- Overrides:
hashCodein 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)
-
-