Class ExecutableNormalizedField
- java.lang.Object
-
- graphql.normalized.ExecutableNormalizedField
-
@PublicApi public class ExecutableNormalizedField extends java.lang.Object
AnExecutableNormalizedFieldrepresents a field in an executable graphql operation. Its models what could be executed during a given operation.This class is intentionally mutable for performance reasons since building immutable parent child objects is too expensive.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classExecutableNormalizedField.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChild(ExecutableNormalizedField executableNormalizedField)voidaddDeferredExecutions(java.util.Collection<NormalizedDeferredExecution> deferredExecutions)voidaddObjectTypeNames(java.util.Collection<java.lang.String> objectTypeNames)voidclearChildren()voidforEachFieldDefinition(GraphQLSchema schema, java.util.function.Consumer<GraphQLFieldDefinition> consumer)java.lang.StringgetAlias()com.google.common.collect.ImmutableList<Argument>getAstArguments()java.util.List<ExecutableNormalizedField>getChildren()java.util.List<ExecutableNormalizedField>getChildren(int includingRelativeLevel)java.util.List<ExecutableNormalizedField>getChildren(java.lang.String objectTypeName)This returns the child fields that can be used if the object is of the specified object typejava.util.List<ExecutableNormalizedField>getChildrenWithSameResultKey(java.lang.String resultKey)Returns the list of child fields that would have the same result keyjava.util.LinkedHashSet<NormalizedDeferredExecution>getDeferredExecutions()java.util.List<GraphQLFieldDefinition>getFieldDefinitions(GraphQLSchema schema)java.lang.StringgetFieldName()intgetLevel()the level of theExecutableNormalizedFieldin the operation hierarchy with top level fields starting at 1java.util.List<java.lang.String>getListOfResultKeys()This returns the list of the result keys (seegetResultKey()that lead from this field upwards to its parent fieldjava.lang.StringgetName()All merged fields have the same name so this is the name of theExecutableNormalizedField.NormalizedInputValuegetNormalizedArgument(java.lang.String name)Returns an argument value as aNormalizedInputValuewhich contains its type name and its current valuecom.google.common.collect.ImmutableMap<java.lang.String,NormalizedInputValue>getNormalizedArguments()java.util.Set<java.lang.String>getObjectTypeNames()AExecutableNormalizedFieldcan sometimes (for non-concrete types like interfaces and unions) have more than one object type it could be when executed.ExecutableNormalizedFieldgetParent()java.util.LinkedHashMap<java.lang.String,java.lang.Object>getResolvedArguments()java.lang.StringgetResultKey()Returns the result key of thisExecutableNormalizedFieldwithin the overall result.java.lang.StringgetSingleObjectTypeName()This returns the first entry ingetObjectTypeNames().GraphQLOutputTypegetType(GraphQLSchema schema)java.util.List<GraphQLOutputType>getTypes(GraphQLSchema schema)booleanhasChildren()booleanisConditional(@NonNull GraphQLSchema schema)Determines whether thisExecutableNormalizedFieldneeds a fragment to select the field.static ExecutableNormalizedField.BuildernewNormalizedField()java.lang.StringobjectTypeNamesToString()java.lang.StringprintDetails()voidreplaceParent(ExecutableNormalizedField newParent)voidsetDeferredExecutions(java.util.Collection<NormalizedDeferredExecution> deferredExecutions)voidsetObjectTypeNames(java.util.Collection<java.lang.String> objectTypeNames)java.lang.StringtoString()ExecutableNormalizedFieldtransform(java.util.function.Consumer<ExecutableNormalizedField.Builder> builderConsumer)Allows thisExecutableNormalizedFieldto be transformed via aExecutableNormalizedField.Builderconsumer callbackvoidtraverseSubTree(java.util.function.Consumer<ExecutableNormalizedField> consumer)Traverse from thisExecutableNormalizedFielddown into itself and all of its children
-
-
-
Method Detail
-
isConditional
public boolean isConditional(@NonNull GraphQLSchema schema)
Determines whether thisExecutableNormalizedFieldneeds a fragment to select the field. However, it considers the parent output type when determining whether it needs a fragment.Consider the following schema
interface Animal { name: String parent: Animal } type Cat implements Animal { name: String parent: Cat } type Dog implements Animal { name: String parent: Dog isGoodBoy: Boolean } type Query { animal: Animal }and the following query
{ animal { parent { name } } }Then we would get the following
ExecutableNormalizedOperation-Query.animal: Animal --[Cat, Dog].parent: Cat, Dog ---[Cat, Dog].name: String
If we simply checked the
parent'sgetFieldDefinitions(GraphQLSchema)that would point us toCat.parentandDog.parentwhose output types would incorrectly answer our question whether this is conditional?We MUST consider that the output type of the
parentfield isAnimaland NOTCatorDogas their respective implementations would say.- Parameters:
schema- - the graphql schema in play- Returns:
- true if the field is conditional
-
hasChildren
public boolean hasChildren()
-
getType
public GraphQLOutputType getType(GraphQLSchema schema)
-
getTypes
public java.util.List<GraphQLOutputType> getTypes(GraphQLSchema schema)
-
forEachFieldDefinition
public void forEachFieldDefinition(GraphQLSchema schema, java.util.function.Consumer<GraphQLFieldDefinition> consumer)
-
getFieldDefinitions
public java.util.List<GraphQLFieldDefinition> getFieldDefinitions(GraphQLSchema schema)
-
addObjectTypeNames
public void addObjectTypeNames(java.util.Collection<java.lang.String> objectTypeNames)
-
setObjectTypeNames
public void setObjectTypeNames(java.util.Collection<java.lang.String> objectTypeNames)
-
addChild
public void addChild(ExecutableNormalizedField executableNormalizedField)
-
clearChildren
public void clearChildren()
-
setDeferredExecutions
public void setDeferredExecutions(java.util.Collection<NormalizedDeferredExecution> deferredExecutions)
-
addDeferredExecutions
public void addDeferredExecutions(java.util.Collection<NormalizedDeferredExecution> deferredExecutions)
-
getName
public java.lang.String getName()
All merged fields have the same name so this is the name of theExecutableNormalizedField.WARNING: This is not always the key in the execution result, because of possible field aliases.
- Returns:
- the name of this
ExecutableNormalizedField - See Also:
getResultKey(),getAlias()
-
getFieldName
public java.lang.String getFieldName()
- Returns:
- the same value as
getName() - See Also:
getResultKey(),getAlias()
-
getResultKey
public java.lang.String getResultKey()
Returns the result key of thisExecutableNormalizedFieldwithin the overall result. This is either a field alias or the value ofgetName()- Returns:
- the result key for this
ExecutableNormalizedField. - See Also:
getName()
-
getAlias
public java.lang.String getAlias()
- Returns:
- the field alias used or null if there is none
- See Also:
getResultKey(),getName()
-
getAstArguments
public com.google.common.collect.ImmutableList<Argument> getAstArguments()
- Returns:
- a list of the
Arguments on the field
-
getNormalizedArgument
public NormalizedInputValue getNormalizedArgument(java.lang.String name)
Returns an argument value as aNormalizedInputValuewhich contains its type name and its current value- Parameters:
name- the name of the argument- Returns:
- an argument value
-
getNormalizedArguments
public com.google.common.collect.ImmutableMap<java.lang.String,NormalizedInputValue> getNormalizedArguments()
- Returns:
- a map of all the arguments in
NormalizedInputValueform
-
getResolvedArguments
public java.util.LinkedHashMap<java.lang.String,java.lang.Object> getResolvedArguments()
- Returns:
- a map of the resolved argument values
-
getObjectTypeNames
public java.util.Set<java.lang.String> getObjectTypeNames()
AExecutableNormalizedFieldcan sometimes (for non-concrete types like interfaces and unions) have more than one object type it could be when executed. There is no way to know what it will be until the field is executed over data and the type is resolved via aTypeResolver.This method returns all the possible types a field can be which is one or more
GraphQLObjectTypenames.Warning: This returns a Mutable Set. No defensive copy is made for performance reasons.
- Returns:
- a set of the possible type names this field could be.
-
getSingleObjectTypeName
public java.lang.String getSingleObjectTypeName()
This returns the first entry ingetObjectTypeNames(). Sometimes you know a field cant be more than one type and this method is a shortcut one to help you.- Returns:
- the first entry from
-
printDetails
public java.lang.String printDetails()
- Returns:
- a helper method show field details
-
objectTypeNamesToString
public java.lang.String objectTypeNamesToString()
- Returns:
- a helper method to show the object types names as a string
-
getListOfResultKeys
public java.util.List<java.lang.String> getListOfResultKeys()
This returns the list of the result keys (seegetResultKey()that lead from this field upwards to its parent field- Returns:
- a list of the result keys from this
ExecutableNormalizedFieldto the top of the operation via parent fields
-
getChildren
public java.util.List<ExecutableNormalizedField> getChildren()
- Returns:
- the children of the
ExecutableNormalizedField
-
getChildrenWithSameResultKey
public java.util.List<ExecutableNormalizedField> getChildrenWithSameResultKey(java.lang.String resultKey)
Returns the list of child fields that would have the same result key- Parameters:
resultKey- the result key to check- Returns:
- a list of all direct
ExecutableNormalizedFieldchildren with the specified result key
-
getChildren
public java.util.List<ExecutableNormalizedField> getChildren(int includingRelativeLevel)
-
getChildren
public java.util.List<ExecutableNormalizedField> getChildren(java.lang.String objectTypeName)
This returns the child fields that can be used if the object is of the specified object type- Parameters:
objectTypeName- the object type- Returns:
- a list of child fields that would apply to that object type
-
getLevel
public int getLevel()
the level of theExecutableNormalizedFieldin the operation hierarchy with top level fields starting at 1- Returns:
- the level of the
ExecutableNormalizedFieldin the operation hierarchy
-
getParent
public ExecutableNormalizedField getParent()
- Returns:
- the parent of this
ExecutableNormalizedFieldor null if it's a top level field
-
getDeferredExecutions
@ExperimentalApi public java.util.LinkedHashSet<NormalizedDeferredExecution> getDeferredExecutions()
- Returns:
- the
NormalizedDeferredExecutions associated with thisExecutableNormalizedField. - See Also:
NormalizedDeferredExecution
-
replaceParent
public void replaceParent(ExecutableNormalizedField newParent)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
traverseSubTree
public void traverseSubTree(java.util.function.Consumer<ExecutableNormalizedField> consumer)
Traverse from thisExecutableNormalizedFielddown into itself and all of its children- Parameters:
consumer- the callback for eachExecutableNormalizedFieldin the hierarchy.
-
newNormalizedField
public static ExecutableNormalizedField.Builder newNormalizedField()
- Returns:
- a
ExecutableNormalizedField.BuilderofExecutableNormalizedFields
-
transform
public ExecutableNormalizedField transform(java.util.function.Consumer<ExecutableNormalizedField.Builder> builderConsumer)
Allows thisExecutableNormalizedFieldto be transformed via aExecutableNormalizedField.Builderconsumer callback- Parameters:
builderConsumer- the consumer given a builder- Returns:
- a new transformed
ExecutableNormalizedField
-
-