Record Class GraphQLResponse

java.lang.Object
java.lang.Record
codes.grow.packages.skywalking.GraphQLResponse
Record Components:
data - the data object, or empty when absent or null
errors - the GraphQL errors, empty on success

public record GraphQLResponse(Optional<com.fasterxml.jackson.databind.JsonNode> data, List<GraphQLErrorInfo> errors) extends Record
Result of a raw GraphQL call (SkyWalkingClient.graphql(java.lang.String, java.util.Map<java.lang.String, ?>)): partial data is possible next to errors.
  • Constructor Details

    • GraphQLResponse

      public GraphQLResponse(Optional<com.fasterxml.jackson.databind.JsonNode> data, List<GraphQLErrorInfo> errors)
      Normalises nulls.
      Parameters:
      data - data
      errors - errors
  • Method Details

    • fromBody

      public static GraphQLResponse fromBody(com.fasterxml.jackson.databind.JsonNode body)
      Decodes a response body.
      Parameters:
      body - the JSON body
      Returns:
      the response
    • hasErrors

      public boolean hasErrors()
      Whether the server reported errors.
      Returns:
      true when errors() is not empty
    • field

      public Optional<com.fasterxml.jackson.databind.JsonNode> field(String name)
      Returns one field of data.
      Parameters:
      name - field name
      Returns:
      the field, or empty when absent or null
    • throwIfErrors

      public void throwIfErrors(String operation)
      Throws the SDK error for errors() (nothing when there are none).
      Parameters:
      operation - operation name for the message
      Throws:
      SkyWalkingException - see toException(java.lang.String, java.util.List<codes.grow.packages.skywalking.GraphQLErrorInfo>, java.util.function.UnaryOperator<java.lang.String>)
    • toException

      public static SkyWalkingException toException(String operation, List<GraphQLErrorInfo> errors, UnaryOperator<String> redact)
      Maps GraphQL errors to an SDK error: an UnsupportedOperationException on the server → UnsupportedException, anything else → ValidationException (bad input caught by the resolver). The message is redacted and truncated to 300 characters.
      Parameters:
      operation - operation name
      errors - the errors (not empty)
      redact - redaction of known secrets
      Returns:
      the exception
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • data

      public Optional<com.fasterxml.jackson.databind.JsonNode> data()
      Returns the value of the data record component.
      Returns:
      the value of the data record component
    • errors

      public List<GraphQLErrorInfo> errors()
      Returns the value of the errors record component.
      Returns:
      the value of the errors record component