Class DefaultExecutionGraphQlResponse

java.lang.Object
org.springframework.graphql.support.AbstractGraphQlResponse
org.springframework.graphql.support.DefaultExecutionGraphQlResponse
All Implemented Interfaces:
ExecutionGraphQlResponse, GraphQlResponse
Direct Known Subclasses:
RSocketGraphQlResponse, WebGraphQlResponse

public class DefaultExecutionGraphQlResponse extends AbstractGraphQlResponse implements ExecutionGraphQlResponse
GraphQlResponse for server use that wraps the ExecutionResult returned from GraphQL and also exposes the actual ExecutionInput instance passed into it.
Since:
1.0.0
Author:
Rossen Stoyanchev
  • Constructor Details

    • DefaultExecutionGraphQlResponse

      public DefaultExecutionGraphQlResponse(graphql.ExecutionInput input, graphql.ExecutionResult result)
      Constructor to create initial instance.
      Parameters:
      input - the execution input for this graphql operation
      result - the execution result for this graphql operation
    • DefaultExecutionGraphQlResponse

      protected DefaultExecutionGraphQlResponse(ExecutionGraphQlResponse response)
      Constructor to re-wrap from transport specific subclass.
      Parameters:
      response - the execution response
  • Method Details

    • getExecutionInput

      public graphql.ExecutionInput getExecutionInput()
      Description copied from interface: ExecutionGraphQlResponse
      Return the ExecutionInput that was prepared through the ExecutionGraphQlRequest and passed to GraphQL.
      Specified by:
      getExecutionInput in interface ExecutionGraphQlResponse
    • getExecutionResult

      public graphql.ExecutionResult getExecutionResult()
      Description copied from interface: ExecutionGraphQlResponse
      Return the ExecutionResult that was returned from the invocation to GraphQL.
      Specified by:
      getExecutionResult in interface ExecutionGraphQlResponse
    • isValid

      public boolean isValid()
      Description copied from interface: GraphQlResponse
      Whether the response is valid. A response is invalid in one of the following two cases:
      • the response map has no "data" entry indicating errors before execution, e.g. grammar parse and validation
      • the "data" entry has a null value indicating errors during execution that prevented a valid response

      A valid response has a "data" key with a non-null value, but it may still be partial and have some fields set to null due to field errors.

      For more details, see section 7 "Response" in the GraphQL spec.

      Specified by:
      isValid in interface GraphQlResponse
    • getData

      public <T> @Nullable T getData()
      Description copied from interface: GraphQlResponse
      Return the data part of the response, or null when the response is not valid.
      Specified by:
      getData in interface GraphQlResponse
      Type Parameters:
      T - a map or a list
    • getErrors

      public List<ResponseError> getErrors()
      Description copied from interface: GraphQlResponse
      Return errors included in the response.

      A response that is not valid contains "request errors". Those are errors that apply to the request as a whole, and have an empty error path.

      A response that is valid may still be partial and contain "field errors". Those are errors associated with a specific field through their error path.

      Specified by:
      getErrors in interface GraphQlResponse
    • getExtensions

      public Map<Object,Object> getExtensions()
      Description copied from interface: GraphQlResponse
      Return implementor specific, protocol extensions, if any.
      Specified by:
      getExtensions in interface GraphQlResponse
    • toMap

      public Map<String,Object> toMap()
      Description copied from interface: GraphQlResponse
      Return a map representation of the response, formatted as required in the "Response" section of the GraphQL spec.
      Specified by:
      toMap in interface GraphQlResponse
    • toString

      public String toString()
      Overrides:
      toString in class Object