Class ResultPath

java.lang.Object
graphql.execution.ResultPath

@PublicApi public class ResultPath extends Object
As a graphql query is executed, each field forms a hierarchical path from parent field to child field and this class represents that path as a series of segments.
  • Method Details

    • rootPath

      public static ResultPath rootPath()
      All paths start from here
      Returns:
      the root path
    • getLevel

      public int getLevel()
    • getPathWithoutListEnd

      public ResultPath getPathWithoutListEnd()
    • isListSegment

      public boolean isListSegment()
      Returns:
      true if the end of the path has a list style segment eg 'a/b[2]'
    • isNamedSegment

      public boolean isNamedSegment()
      Returns:
      true if the end of the path has a named style segment eg 'a/b[2]/c'
    • getSegmentName

      public String getSegmentName()
    • getSegmentIndex

      public int getSegmentIndex()
    • getSegmentValue

      public Object getSegmentValue()
    • getParent

      public ResultPath getParent()
    • parse

      public static ResultPath parse(String pathString)
      Parses an execution path from the provided path string in the format /segment1/segment2[index]/segmentN
      Parameters:
      pathString - the path string
      Returns:
      a parsed execution path
    • fromList

      public static ResultPath fromList(List<?> objects)
      This will create an execution path from the list of objects
      Parameters:
      objects - the path objects
      Returns:
      a new execution path
    • segment

      public ResultPath segment(String segment)
      Takes the current path and adds a new segment to it, returning a new path
      Parameters:
      segment - the string path segment to add
      Returns:
      a new path containing that segment
    • segment

      public ResultPath segment(int segment)
      Takes the current path and adds a new segment to it, returning a new path
      Parameters:
      segment - the int path segment to add
      Returns:
      a new path containing that segment
    • dropSegment

      public ResultPath dropSegment()
      Drops the last segment off the path
      Returns:
      a new path with the last segment dropped off
    • replaceSegment

      public ResultPath replaceSegment(int segment)
      Replaces the last segment on the path eg ResultPath.parse("/a/b[1]").replaceSegment(9) equals "/a/b[9]"
      Parameters:
      segment - the integer segment to use
      Returns:
      a new path with the last segment replaced
    • replaceSegment

      public ResultPath replaceSegment(String segment)
      Replaces the last segment on the path eg ResultPath.parse("/a/b[1]").replaceSegment("x") equals "/a/b/x"
      Parameters:
      segment - the string segment to use
      Returns:
      a new path with the last segment replaced
    • isRootPath

      public boolean isRootPath()
      Returns:
      true if the path is the rootPath()
    • append

      public ResultPath append(ResultPath path)
      Appends the provided path to the current one
      Parameters:
      path - the path to append
      Returns:
      a new path
    • sibling

      public ResultPath sibling(String siblingField)
    • sibling

      public ResultPath sibling(int siblingField)
    • toList

      public List<Object> toList()
      Returns:
      converts the path into a list of segments
    • getKeysOnly

      public List<String> getKeysOnly()
      Returns:
      this path as a list of result keys, without any indices
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      the path as a string which represents the call hierarchy
    • segmentToString

      public String segmentToString()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object