Class ExecutableNormalizedField
ExecutableNormalizedField
represents 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 -
Method Summary
Modifier and TypeMethodDescriptionvoid
addChild
(ExecutableNormalizedField executableNormalizedField) void
addDeferredExecutions
(Collection<NormalizedDeferredExecution> deferredExecutions) void
addObjectTypeNames
(Collection<String> objectTypeNames) void
void
forEachFieldDefinition
(GraphQLSchema schema, Consumer<GraphQLFieldDefinition> consumer) getAlias()
com.google.common.collect.ImmutableList
<Argument> getChildren
(int includingRelativeLevel) getChildren
(String objectTypeName) This returns the child fields that can be used if the object is of the specified object typegetChildrenWithSameResultKey
(String resultKey) Returns the list of child fields that would have the same result keygetFieldDefinitions
(GraphQLSchema schema) int
getLevel()
the level of theExecutableNormalizedField
in the operation hierarchy with top level fields starting at 1This returns the list of the result keys (seegetResultKey()
that lead from this field upwards to its parent fieldgetName()
All merged fields have the same name so this is the name of theExecutableNormalizedField
.getNormalizedArgument
(String name) Returns an argument value as aNormalizedInputValue
which contains its type name and its current valuecom.google.common.collect.ImmutableMap
<String, NormalizedInputValue> AExecutableNormalizedField
can sometimes (for non-concrete types like interfaces and unions) have more than one object type it could be when executed.Returns the result key of thisExecutableNormalizedField
within the overall result.This returns the first entry ingetObjectTypeNames()
.getType
(GraphQLSchema schema) getTypes
(GraphQLSchema schema) boolean
boolean
isConditional
(@NonNull GraphQLSchema schema) Determines whether thisExecutableNormalizedField
needs a fragment to select the field.void
replaceParent
(ExecutableNormalizedField newParent) void
setDeferredExecutions
(Collection<NormalizedDeferredExecution> deferredExecutions) void
setObjectTypeNames
(Collection<String> objectTypeNames) toString()
transform
(Consumer<ExecutableNormalizedField.Builder> builderConsumer) Allows thisExecutableNormalizedField
to be transformed via aExecutableNormalizedField.Builder
consumer callbackvoid
traverseSubTree
(Consumer<ExecutableNormalizedField> consumer) Traverse from thisExecutableNormalizedField
down into itself and all of its children
-
Method Details
-
isConditional
Determines whether thisExecutableNormalizedField
needs 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.parent
andDog.parent
whose output types would incorrectly answer our question whether this is conditional?We MUST consider that the output type of the
parent
field isAnimal
and NOTCat
orDog
as their respective implementations would say.- Parameters:
schema
- - the graphql schema in play- Returns:
- true if the field is conditional
-
hasChildren
public boolean hasChildren() -
getType
-
getTypes
-
forEachFieldDefinition
-
getFieldDefinitions
-
addObjectTypeNames
-
setObjectTypeNames
-
addChild
-
clearChildren
public void clearChildren() -
setDeferredExecutions
-
addDeferredExecutions
-
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:
-
getFieldName
- Returns:
- the same value as
getName()
- See Also:
-
getResultKey
Returns the result key of thisExecutableNormalizedField
within the overall result. This is either a field alias or the value ofgetName()
- Returns:
- the result key for this
ExecutableNormalizedField
. - See Also:
-
getAlias
- Returns:
- the field alias used or null if there is none
- See Also:
-
getAstArguments
- Returns:
- a list of the
Argument
s on the field
-
getNormalizedArgument
Returns an argument value as aNormalizedInputValue
which contains its type name and its current value- Parameters:
name
- the name of the argument- Returns:
- an argument value
-
getNormalizedArguments
- Returns:
- a map of all the arguments in
NormalizedInputValue
form
-
getResolvedArguments
- Returns:
- a map of the resolved argument values
-
getObjectTypeNames
AExecutableNormalizedField
can 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
GraphQLObjectType
names.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
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
- Returns:
- a helper method show field details
-
objectTypeNamesToString
- Returns:
- a helper method to show the object types names as a 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
ExecutableNormalizedField
to the top of the operation via parent fields
-
getChildren
- Returns:
- the children of the
ExecutableNormalizedField
-
getChildrenWithSameResultKey
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
ExecutableNormalizedField
children with the specified result key
-
getChildren
-
getChildren
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 theExecutableNormalizedField
in the operation hierarchy with top level fields starting at 1- Returns:
- the level of the
ExecutableNormalizedField
in the operation hierarchy
-
getParent
- Returns:
- the parent of this
ExecutableNormalizedField
or null if it's a top level field
-
getDeferredExecutions
- Returns:
- the
NormalizedDeferredExecution
s associated with thisExecutableNormalizedField
. - See Also:
-
replaceParent
-
toString
-
traverseSubTree
Traverse from thisExecutableNormalizedField
down into itself and all of its children- Parameters:
consumer
- the callback for eachExecutableNormalizedField
in the hierarchy.
-
newNormalizedField
- Returns:
- a
ExecutableNormalizedField.Builder
ofExecutableNormalizedField
s
-
transform
public ExecutableNormalizedField transform(Consumer<ExecutableNormalizedField.Builder> builderConsumer) Allows thisExecutableNormalizedField
to be transformed via aExecutableNormalizedField.Builder
consumer callback- Parameters:
builderConsumer
- the consumer given a builder- Returns:
- a new transformed
ExecutableNormalizedField
-