mochi/response
Types
pub type DeferredPatchResponse {
DeferredPatchResponse(
path: List(String),
data: option.Option(dynamic.Dynamic),
errors: option.Option(List(error.GraphQLError)),
label: option.Option(String),
has_next: Bool,
)
}
Constructors
-
DeferredPatchResponse( path: List(String), data: option.Option(dynamic.Dynamic), errors: option.Option(List(error.GraphQLError)), label: option.Option(String), has_next: Bool, )
A complete GraphQL response
pub type GraphQLResponse {
GraphQLResponse(
data: option.Option(dynamic.Dynamic),
errors: option.Option(List(error.GraphQLError)),
extensions: option.Option(dict.Dict(String, dynamic.Dynamic)),
has_next: option.Option(Bool),
)
}
Constructors
-
GraphQLResponse( data: option.Option(dynamic.Dynamic), errors: option.Option(List(error.GraphQLError)), extensions: option.Option(dict.Dict(String, dynamic.Dynamic)), has_next: option.Option(Bool), )Arguments
- data
-
The data returned from executing the requested operation
- errors
-
Errors that occurred during execution
- extensions
-
Additional metadata from extensions
- has_next
-
For incremental delivery: top-level hasNext flag
pub type IncrementalResponse {
IncrementalResponse(
initial: GraphQLResponse,
patches: List(DeferredPatchResponse),
)
}
Constructors
-
IncrementalResponse( initial: GraphQLResponse, patches: List(DeferredPatchResponse), )
Values
pub fn deferred_patch_to_dynamic(
patch: DeferredPatchResponse,
) -> dynamic.Dynamic
Serialize an incremental response patch to Dynamic
pub fn execution_error_to_graphql_error(
err: executor.ExecutionError,
) -> error.GraphQLError
pub fn failure(
errors: List(error.GraphQLError),
) -> GraphQLResponse
Create an error-only response
pub fn from_execution_result(
result: executor.ExecutionResult,
) -> GraphQLResponse
Create a response from an ExecutionResult
pub fn from_execution_result_incremental(
result: executor.ExecutionResult,
) -> IncrementalResponse
Build an incremental response from an ExecutionResult that contains deferred patches
pub fn incremental_envelope_to_dynamic(
patches: List(DeferredPatchResponse),
has_next: Bool,
) -> dynamic.Dynamic
Serialize an incremental delivery envelope to Dynamic Shape: {“incremental”: […patches], “hasNext”: bool}
pub fn is_partial(response: GraphQLResponse) -> Bool
Check if response is partial (has data and errors)
pub fn is_success(response: GraphQLResponse) -> Bool
Check if response is successful (has data, no errors)
pub fn partial(
data: dynamic.Dynamic,
errors: List(error.GraphQLError),
) -> GraphQLResponse
Create a partial response with data and errors
pub fn serialize(response: GraphQLResponse) -> dynamic.Dynamic
Serialize response to JSON string (requires external JSON encoder) This returns the Dynamic representation - use with a JSON library
pub fn success(data: dynamic.Dynamic) -> GraphQLResponse
Create a successful response with data
pub fn to_dynamic(response: GraphQLResponse) -> dynamic.Dynamic
Convert a GraphQLResponse to a Dynamic representation for JSON serialization
pub fn to_json(response: GraphQLResponse) -> String
Convert a GraphQLResponse to a JSON string.
If the response data contains a runtime shape that can’t be encoded as
JSON (e.g. a resolver returned a tuple or function), fall back to a
spec-compliant error response describing the failure rather than
silently emitting null for the offending value.
pub fn to_json_pretty(response: GraphQLResponse) -> String
Convert a GraphQLResponse to a pretty-printed JSON string. Same fallback
behaviour as to_json on encoding failure.
pub fn with_extension(
response: GraphQLResponse,
key: String,
value: dynamic.Dynamic,
) -> GraphQLResponse
Add a single extension value
pub fn with_extensions(
response: GraphQLResponse,
extensions: dict.Dict(String, dynamic.Dynamic),
) -> GraphQLResponse
Add extensions to a response
pub fn with_tracing(
response: GraphQLResponse,
start_time: Int,
end_time: Int,
) -> GraphQLResponse
Add tracing data to response extensions