Sign in

    moonbitstack/moongql/exec does not have a README file

    FromGql

    pub(open) trait FromGql {
    fn from_gql(Json) -> Self raise ResolverError
    }

    A MoonBit value read from an argument or a parent value: async-graphql's InputType. A refusal is a ResolverError saying what was expected.
    impl FromGql for Bool
    impl FromGql for Int
    impl FromGql for Int64
    impl FromGql for Double
    impl FromGql for String
    impl FromGql for Option[T]
    impl FromGql for Array[T]
    impl FromGql for Json

    ToGql

    pub(open) trait ToGql {
    fn to_gql(Self) -> Json
    }

    A MoonBit value as a GraphQL result: async-graphql's OutputType. Implemented for the built-in scalars, Int64 (written as a string, since GraphQL's Int is 32-bit), Json, T? and Array[T]; the #gql generator writes it for each annotated type.
    impl ToGql for Bool
    impl ToGql for Int
    impl ToGql for Int64
    impl ToGql for Double
    impl ToGql for String
    impl ToGql for Option[T]
    impl ToGql for Array[T]
    impl ToGql for Json

    ResolverError

    pub(all) suberror ResolverError {
    ResolverError(String)
    ResolverErrorExt(String, Map[String, Json])
    }

    An error raised by a field resolver; its message is reported in the response errors list with the field's response path.

    ResolverError::expected

    fn ResolverError::expected(want : String, got : Json) -> ResolverError

    The refusal of a value that is not a want, as every [FromGql] here writes it: expected Int, got "x".

    ResolveInfo

    pub(all) struct ResolveInfo {
    parent : Json
    args : Map[String, Json]
    ctx : Json
    field_name : String
    }

    The information a field resolver receives: the resolved parent object (as JSON), the coerced arguments, the shared context value, and the field's name. A resolver returns the field's value as JSON (an object for composite types, whose sub-fields are then resolved against it) and may raise ResolverError to surface a field error.

    ResolveInfo::arg

    fn ResolveInfo::arg(self : ResolveInfo, name : String) -> Json

    Read a named argument as JSON, or Json::null() when it was not supplied.

    ResolveInfo::read

    fn[T : FromGql] ResolveInfo::read(self : ResolveInfo, name : String) -> T raise ResolverError

    The argument name as any [FromGql] type; a missing argument reads as null, so it is None for a T?. A refusal names the argument.

    Resolvers

    pub struct Resolvers {
    map : Map[String, (ResolveInfo) -> Json raise ResolverError]
    }

    A registry of field resolvers, keyed by "TypeName.fieldName". Fields with no registered resolver fall back to the default resolver, which reads the field's name off the parent JSON object (matching graphql-core's default_field_resolver).

    Resolvers::field

    fn Resolvers::field(self : Resolvers, type_name : String, field_name : String, resolver : (ResolveInfo) -> Json raise ResolverError) -> Unit

    Register resolver for field field_name on type type_name.

    Resolvers::new

    fn Resolvers::new() -> Resolvers

    Create an empty resolver registry.

    Subscribers

    pub struct Subscribers {
    map : Map[String, (ResolveInfo) -> Array[Json] raise ResolverError]
    }

    A registry of subscription source resolvers, keyed by "TypeName.fieldName" on the subscription root type. A source returns the ordered stream of event payloads; each payload is the resolved value of the root field for one event, and its sub-selection is resolved against it like any object value.

    Subscribers::field

    fn Subscribers::field(self : Subscribers, type_name : String, field_name : String, source : (ResolveInfo) -> Array[Json] raise ResolverError) -> Unit

    Register a source stream for the root subscription field field_name on type_name. The source is called once per operation and yields the ordered events to deliver.

    Subscribers::new

    Create an empty subscription source registry.

    SubscriptionResult

    pub(all) enum SubscriptionResult {
    RequestError(Array[
    GqlError
    ])
    EventStream(Array[Json])
    }

    The outcome of establishing a subscription (GraphQL spec §6.2.3 CreateSourceEventStream + MapSourceToResponseEvent): either the request failed before any event could be produced — a parse, validation, or source-resolution error the client should receive instead of a stream — or the source yielded its ordered { data, errors } response payloads. Keeping the two apart lets a transport (the graphql-transport-ws handler) send a single error message for the former and a run of next messages for the latter, which the flat "one error response in the payload list" shape cannot distinguish.

    build_response

    fn build_response(data : Json?, errors : Array[
    GqlError
    ], extensions? : Map[String, Json]) -> Json

    Assemble the final { errors?, data?, extensions? } response object. data is omitted for request-level failures (no execution began) and included (possibly null) once execution starts; errors is omitted when empty, and so is the server's extensions map (§7.1, the entry reserved for whatever a server wants to say alongside the result — timings, a trace id, a cache hint).

    create_source_event_stream

    fn create_source_event_stream(schema :
    Schema
    , resolvers : Resolvers, subscribers : Subscribers, query : String, variables? : Map[String, Json], operation_name? : String, root_value? : Json, context? : Json) -> SubscriptionResult

    Establish a subscription and materialise its event payloads. Parses and validates query, requires a single-root-field subscription operation, invokes the registered source, and maps every event through execute_subscription_event. Any failure before the first event — parse/validation error, a non-subscription operation, more than one root field, an introspection root, a missing source, or a source ResolverError — is a RequestError; success is an EventStream of ordered response payloads.

    execute

    fn execute(schema :
    Schema
    , resolvers : Resolvers, query : String, variables? : Map[String, Json], operation_name? : String, root_value? : Json, context? : Json, extensions? : Map[String, Json]) -> Json

    Execute a GraphQL request end to end: parse query, validate it against schema, select the operation, coerce variables, then walk the selection set with resolvers — returning the { data, errors } response as JSON.

    variables supplies operation variable values, operation_name picks an operation when the document has several, root_value seeds the root object, context is threaded to every resolver, and extensions is the server's own extensions entry on the response (§7.1), emitted when non-empty. The function never raises: parse and validation failures yield an errors-only response, and field errors are collected alongside partial data.

    execute_subscription

    fn execute_subscription(schema :
    Schema
    , resolvers : Resolvers, subscribers : Subscribers, query : String, variables? : Map[String, Json], operation_name? : String, root_value? : Json, context? : Json) -> Array[Json]

    Run a subscription operation and collect its ordered response payloads.

    A thin wrapper over create_source_event_stream: a RequestError collapses to a single { errors } response (the flat shape callers without a streaming transport expect), and an EventStream is returned as-is. variables, operation_name, root_value and context mirror execute.

    field_error

    fn field_error(e : Error) -> ResolverError

    Any error a resolver raised, as the field error it becomes; a ResolverError passes through unchanged.

    operation_type

    Which kind of operation a request would run, chosen the way execute chooses it. The server needs this before running anything: a subscription goes over a socket, and GraphQL over HTTP refuses a mutation sent by GET.

    read

    fn[T : FromGql] read(value : Json, key : String) -> T raise ResolverError

    The member key of an object value as any [FromGql] type, the way a generated input type reads its fields; a missing member reads as null. A refusal names the member.