Interface ResponseField

All Known Subinterfaces:
ClientResponseField

public interface ResponseField
Representation for a field in a GraphQL response, with options to examine the field value and errors.
Since:
1.0.0
Author:
Rossen Stoyanchev
  • Method Summary

    Modifier and Type
    Method
    Description
    Return the error that provides the reason for a failed field.
    Return all field errors including errors above, at, and below this field.
    Return a parsed representation of the field path, in the format described for error paths in Section 7.1.2, "Response Format" of the GraphQL spec.
    Return a String representation of the field path as described in ClientGraphQlResponse.field(String).
    <T> T
    Return the raw field value, e.g.
    boolean
    Whether the field has a value.
  • Method Details

    • hasValue

      boolean hasValue()
      Whether the field has a value.
      • "true" means the field is not null, and therefore valid, although it may be partial with nested field errors.
      • "false" means the field is null or doesn't exist; use getError() to check if the field is null due to an error.
    • getPath

      String getPath()
      Return a String representation of the field path as described in ClientGraphQlResponse.field(String).
    • getParsedPath

      List<Object> getParsedPath()
      Return a parsed representation of the field path, in the format described for error paths in Section 7.1.2, "Response Format" of the GraphQL spec.
      See Also:
    • getValue

      @Nullable <T> T getValue()
      Return the raw field value, e.g. Map, List, or a scalar type.
      Type Parameters:
      T - the expected value type to cast to
      Returns:
      the value
    • getError

      Return the error that provides the reason for a failed field.

      When the field does not have a value, this method looks for the first field error. According to the GraphQL spec, section 6.4.4, "Handling Field Errors", there should be only one error per field. The returned field error may be:

      • on the field
      • on a parent field, when the field is not present
      • on a nested field, when a non-null nested field error bubbles up

      As a fallback, this method also checks "request errors" in case the entire response is not valid. If there are no errors at all, null is returned, and it implies the field value was set to null by its DataFetcher.

      When the field does have a value, it is considered valid and this method returns null, although the field may be partial and contain errors on nested fields.

      Returns:
      return the error for this field, or null if there is no error with the same path as the field path
    • getErrors

      List<ResponseError> getErrors()
      Return all field errors including errors above, at, and below this field.

      In practice, when the field does have a value, it is considered valid but possibly partial with nested field errors. When the field does not have a value, there should be only one field error, and in that case it is better to use getError().