Class GraphQLArgument
- java.lang.Object
-
- graphql.schema.GraphQLArgument
-
- All Implemented Interfaces:
GraphQLDirectiveContainer,GraphQLInputSchemaElement,GraphQLInputValueDefinition,GraphQLNamedSchemaElement,GraphQLSchemaElement
@PublicApi public class GraphQLArgument extends java.lang.Object implements GraphQLNamedSchemaElement, GraphQLInputValueDefinition
This defines an argument that can be supplied to a graphql field (viaGraphQLFieldDefinition.Fields can be thought of as "functions" that take arguments and return a value.
See https://graphql.org/learn/queries/#arguments for more details on the concept.
GraphQLArgumentis used in two contexts, one context is graphql queries where it represents the arguments that can be set on a field and the other is in Schema Definition Language (SDL) where it can be used to represent the argument value instances that have been supplied on aGraphQLDirective.The difference is the 'value' and 'defaultValue' properties. In a query argument, the 'value' is never in the GraphQLArgument object but rather in the AST direct or in the query variables map and the 'defaultValue' represents a value to use if both of these are not present. You can think of them like a descriptor of what shape an argument might have.
However, with directives on SDL elements, the value is specified in AST only and transferred into the GraphQLArgument object and the 'defaultValue' comes instead from the directive definition elsewhere in the SDL. You can think of them as 'instances' of arguments, their shape and their specific value on that directive.
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 classGraphQLArgument.Builder
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCHILD_TYPE-
Fields inherited from interface graphql.schema.GraphQLDirectiveContainer
CHILD_APPLIED_DIRECTIVES, CHILD_DIRECTIVES
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated 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.java.util.Map<java.lang.String,java.util.List<GraphQLAppliedDirective>>getAllAppliedDirectivesByName()This will return a Map of the all directives that are associated with aGraphQLNamedSchemaElement, including both repeatable and non-repeatable directives.java.util.Map<java.lang.String,java.util.List<GraphQLDirective>>getAllDirectivesByName()This will return a Map of the all directives that are associated with aGraphQLNamedSchemaElement, including both repeatable and non repeatable directives.GraphQLAppliedDirectivegetAppliedDirective(java.lang.String directiveName)Returns a non-repeatable directive with the provided name.java.util.List<GraphQLAppliedDirective>getAppliedDirectives()This will return a list of all the directives that have been put onGraphQLNamedSchemaElementas a flat list, which may contain repeatable and non-repeatable directives.@NotNull InputValueWithStategetArgumentDefaultValue()The default value of this argument.static <T> TgetArgumentDefaultValue(GraphQLArgument argument)This static helper method will give out a java value based on the semantics captured in theInputValueWithStatefromgetArgumentDefaultValue()Note : You MUST only call this on aGraphQLArgumentthat is part of a fully formed schema.@NotNull InputValueWithStategetArgumentValue()Deprecated.useGraphQLAppliedDirectiveArgumentinsteadstatic <T> TgetArgumentValue(GraphQLArgument argument)Deprecated.useGraphQLAppliedDirectiveArgumentinsteadjava.util.List<GraphQLSchemaElement>getChildren()SchemaElementChildrenContainergetChildrenWithTypeReferences()InputValueDefinitiongetDefinition()The ASTNodethis schema element is based on.java.lang.StringgetDeprecationReason()java.lang.StringgetDescription()GraphQLDirectivegetDirective(java.lang.String directiveName)Returns a non-repeatable directive with the provided name.java.util.List<GraphQLDirective>getDirectives()This will return a list of all the directives that have been put onGraphQLNamedSchemaElementas a flat list, which may contain repeatable and non-repeatable directives.java.util.Map<java.lang.String,GraphQLDirective>getDirectivesByName()This will return a Map of the non repeatable directives that are associated with aGraphQLNamedSchemaElement.java.lang.StringgetName()GraphQLInputTypegetType()inthashCode()No GraphQLSchemaElement implements `equals/hashCode` because we need object identity to treat a GraphQLSchema as an abstract graph.booleanhasSetDefaultValue()booleanhasSetValue()booleanisDeprecated()static GraphQLArgument.BuildernewArgument()static GraphQLArgument.BuildernewArgument(GraphQLArgument existing)GraphQLAppliedDirectiveArgumenttoAppliedArgument()This method can be used to turn an argument that was being use as an applied argument into one.java.lang.StringtoString()GraphQLArgumenttransform(java.util.function.Consumer<GraphQLArgument.Builder> builderConsumer)This helps you transform the current GraphQLArgument into another one by starting a builder with all the current values and allows you to transform it how you want.GraphQLArgumentwithNewChildren(SchemaElementChildrenContainer newChildren)-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface graphql.schema.GraphQLDirectiveContainer
getAppliedDirectives, getDirectives, hasAppliedDirective, hasDirective
-
-
-
-
Field Detail
-
CHILD_TYPE
public static final java.lang.String CHILD_TYPE
- 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
-
getType
public GraphQLInputType getType()
- Specified by:
getTypein interfaceGraphQLInputValueDefinition
-
getArgumentDefaultValue
@NotNull public @NotNull InputValueWithState getArgumentDefaultValue()
The default value of this argument.- Returns:
- a
InputValueWithStatethat represents the arguments default value
-
hasSetDefaultValue
public boolean hasSetDefaultValue()
-
hasSetValue
public boolean hasSetValue()
-
getArgumentValue
@Deprecated @NotNull public @NotNull InputValueWithState getArgumentValue()
Deprecated.useGraphQLAppliedDirectiveArgumentinsteadThis is only used for applied directives, that is when this argument is on aGraphQLDirectiveapplied to a schema or query element- Returns:
- an input value with state for an applied directive
-
getArgumentValue
@Deprecated public static <T> T getArgumentValue(GraphQLArgument argument)
Deprecated.useGraphQLAppliedDirectiveArgumentinsteadThis static helper method will give out a java value based on the semantics captured in theInputValueWithStatefromgetArgumentValue()Note : You MUST only call this on aGraphQLArgumentthat is part of a fully formed schema. We need all of the types to be resolved in order for this work correctly. Note: This method will return null if the value is not set or explicitly set to null. If you you to know the difference when "not set" and "set to null" then you cant use this method. Rather you should usegetArgumentValue()and use theInputValueWithState.isNotSet()methods to decide how to handle those values.- Type Parameters:
T- the type you want it cast as- Parameters:
argument- the fully formedGraphQLArgument- Returns:
- a value of type T which is the java value of the argument
-
getArgumentDefaultValue
public static <T> T getArgumentDefaultValue(GraphQLArgument argument)
This static helper method will give out a java value based on the semantics captured in theInputValueWithStatefromgetArgumentDefaultValue()Note : You MUST only call this on aGraphQLArgumentthat is part of a fully formed schema. We need all of the types to be resolved in order for this work correctly. Note: This method will return null if the value is not set or explicitly set to null. If you you to know the difference when "not set" and "set to null" then you cant use this method. Rather you should usegetArgumentDefaultValue()and use theInputValueWithState.isNotSet()methods to decide how to handle those values.- Type Parameters:
T- the type you want it cast as- Parameters:
argument- the fully formedGraphQLArgument- Returns:
- a value of type T which is the java value of the argument default
-
getDescription
public java.lang.String getDescription()
- Specified by:
getDescriptionin interfaceGraphQLNamedSchemaElement- Returns:
- the description of this element. This can be null
-
getDeprecationReason
public java.lang.String getDeprecationReason()
-
isDeprecated
public boolean isDeprecated()
-
getDefinition
public InputValueDefinition 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.
-
getDirectives
public java.util.List<GraphQLDirective> getDirectives()
Description copied from interface:GraphQLDirectiveContainerThis will return a list of all the directives that have been put onGraphQLNamedSchemaElementas a flat list, which may contain repeatable and non-repeatable directives.- Specified by:
getDirectivesin interfaceGraphQLDirectiveContainer- Returns:
- a list of all the directives associated with this named schema element
-
getDirectivesByName
public java.util.Map<java.lang.String,GraphQLDirective> getDirectivesByName()
Description copied from interface:GraphQLDirectiveContainerThis will return a Map of the non repeatable directives that are associated with aGraphQLNamedSchemaElement. Any repeatable directives will be filtered out of this map.- Specified by:
getDirectivesByNamein interfaceGraphQLDirectiveContainer- Returns:
- a map of non repeatable directives by directive name.
-
getAllDirectivesByName
public java.util.Map<java.lang.String,java.util.List<GraphQLDirective>> getAllDirectivesByName()
Description copied from interface:GraphQLDirectiveContainerThis will return a Map of the all directives that are associated with aGraphQLNamedSchemaElement, including both repeatable and non repeatable directives.- Specified by:
getAllDirectivesByNamein interfaceGraphQLDirectiveContainer- Returns:
- a map of all directives by directive name
-
getDirective
public GraphQLDirective getDirective(java.lang.String directiveName)
Description copied from interface:GraphQLDirectiveContainerReturns a non-repeatable directive with the provided name. This will throw aAssertExceptionif the directive is a repeatable directive that has more then one instance.- Specified by:
getDirectivein interfaceGraphQLDirectiveContainer- Parameters:
directiveName- the name of the directive to retrieve- Returns:
- the directive or null if there is not one with that name
-
getAppliedDirectives
public java.util.List<GraphQLAppliedDirective> getAppliedDirectives()
Description copied from interface:GraphQLDirectiveContainerThis will return a list of all the directives that have been put onGraphQLNamedSchemaElementas a flat list, which may contain repeatable and non-repeatable directives.- Specified by:
getAppliedDirectivesin interfaceGraphQLDirectiveContainer- Returns:
- a list of all the directives associated with this named schema element
-
getAllAppliedDirectivesByName
public java.util.Map<java.lang.String,java.util.List<GraphQLAppliedDirective>> getAllAppliedDirectivesByName()
Description copied from interface:GraphQLDirectiveContainerThis will return a Map of the all directives that are associated with aGraphQLNamedSchemaElement, including both repeatable and non-repeatable directives.- Specified by:
getAllAppliedDirectivesByNamein interfaceGraphQLDirectiveContainer- Returns:
- a map of all directives by directive name
-
getAppliedDirective
public GraphQLAppliedDirective getAppliedDirective(java.lang.String directiveName)
Description copied from interface:GraphQLDirectiveContainerReturns a non-repeatable directive with the provided name.- Specified by:
getAppliedDirectivein interfaceGraphQLDirectiveContainer- Parameters:
directiveName- the name of the directive to retrieve- Returns:
- the directive or null if there is not one with that name
-
getChildren
public java.util.List<GraphQLSchemaElement> getChildren()
- Specified by:
getChildrenin interfaceGraphQLSchemaElement
-
getChildrenWithTypeReferences
public SchemaElementChildrenContainer getChildrenWithTypeReferences()
- Specified by:
getChildrenWithTypeReferencesin interfaceGraphQLSchemaElement
-
withNewChildren
public GraphQLArgument withNewChildren(SchemaElementChildrenContainer newChildren)
- Specified by:
withNewChildrenin interfaceGraphQLSchemaElement
-
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
-
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.
-
transform
public GraphQLArgument transform(java.util.function.Consumer<GraphQLArgument.Builder> builderConsumer)
This helps you transform the current GraphQLArgument 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
-
newArgument
public static GraphQLArgument.Builder newArgument()
-
newArgument
public static GraphQLArgument.Builder newArgument(GraphQLArgument existing)
-
accept
public TraversalControl accept(TraverserContext<GraphQLSchemaElement> context, GraphQLTypeVisitor visitor)
- Specified by:
acceptin interfaceGraphQLSchemaElement
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toAppliedArgument
public GraphQLAppliedDirectiveArgument toAppliedArgument()
This method can be used to turn an argument that was being use as an applied argument into one.- Returns:
- an
GraphQLAppliedDirectiveArgument
-
-