Class ExecutableNormalizedField


  • @PublicApi
    public class ExecutableNormalizedField
    extends java.lang.Object
    An 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.

    • Method Detail

      • isConditional

        public boolean isConditional​(@NotNull
                                     @NotNull GraphQLSchema schema)
        Determines whether this ExecutableNormalizedField 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's getFieldDefinitions(GraphQLSchema) that would point us to Cat.parent and Dog.parent whose output types would incorrectly answer our question whether this is conditional?

        We MUST consider that the output type of the parent field is Animal and NOT Cat or Dog as their respective implementations would say.

        Parameters:
        schema - - the graphql schema in play
        Returns:
        true if the field is conditional
      • hasChildren

        public boolean hasChildren()
      • addObjectTypeNames

        public void addObjectTypeNames​(java.util.Collection<java.lang.String> objectTypeNames)
      • setObjectTypeNames

        public void setObjectTypeNames​(java.util.Collection<java.lang.String> objectTypeNames)
      • clearChildren

        public void clearChildren()
      • 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 a NormalizedInputValue which 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 NormalizedInputValue form
      • 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()
        A ExecutableNormalizedField 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 a TypeResolver.

        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

        public java.lang.String getSingleObjectTypeName()
        This returns the first entry in getObjectTypeNames(). 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 (see getResultKey() 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
      • 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 ExecutableNormalizedField children with the specified result key
      • 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
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object