Sign in

    moonbitstack/moongql/server does not have a README file

    GqlWs

    pub struct GqlWs {
    schema :
    Schema

    resolvers :
    Resolvers

    subscribers :
    Subscribers

    root_value : Json
    context : Json
    init_timeout : Int64
    ping_interval : Int64
    initialized : Bool
    params : Json
    opened : Int64?
    pinged : Int64
    active : Map[String, Unit]
    }

    One graphql-transport-ws connection: the schema it serves plus the protocol state a connection carries — whether connection_init has arrived, the parameters it brought, the operation ids currently running, and the two timers the protocol defines.

    This package has no async runtime and no clock of its own, so the timers are state plus a transition and nothing more: a server drives them by calling tick with a millisecond reading of a monotonic clock, as often as it likes (once a second is plenty), and sending whatever frames come back. Nothing else starts the connection-init countdown or emits a keep-alive ping.

    GqlWs::claim

    fn GqlWs::claim(self : GqlWs, id : String) -> Bool

    Claim operation id for an operation that is starting, answering false when the id is already running — the caller must then close the socket with 4409.

    recv claims and releases an id itself, because a pull source is drained before it returns. A server streaming a live source claims the id when it starts the task and calls release when the task sends its last frame; that is what keeps 4409 meaning "still running" rather than "used once".

    GqlWs::handler

    The connection as a moonasgi WebSocketHandler, negotiating the graphql-transport-ws subprotocol when the client offers it.

    GqlWs::new

    fn GqlWs::new(schema :
    Schema
    , resolvers :
    Resolvers
    , subscribers :
    Subscribers
    , root_value? : Json, context? : Json, init_timeout? : Int64, ping_interval? : Int64) -> GqlWs

    Open a connection's protocol state for schema / resolvers / subscribers. root_value and context are threaded to every operation the way execute threads them.

    init_timeout is how long a client may take to send connection_init before tick closes the socket with 4408, and ping_interval how long the server waits between keep-alive ping frames; both are milliseconds, and either is switched off by passing zero.

    GqlWs::recv

    Handle one inbound message, returning the frames to send back.

    GqlWs::release

    fn GqlWs::release(self : GqlWs, id : String) -> Unit

    Release operation id, freeing it for reuse. Called after the operation's terminating complete or error has been sent.

    GqlWs::tick

    fn GqlWs::tick(self : GqlWs, now : Int64) -> Array[
    WsSend
    ]

    Drive the connection's timers from a monotonic clock reading in milliseconds, returning the frames the elapsed time calls for: the 4408 close when connection_init did not arrive in time, or a keep-alive ping.

    The first call starts the clock, so a server should tick as soon as it has accepted the socket and keep ticking for as long as it holds it.

    graphiql_html

    fn graphiql_html(endpoint? : String) -> String

    The GraphiQL IDE page, wired to fetch against endpoint. This is the same standalone GraphiQL build strawberry serves: React and GraphiQL load from a CDN via an import map, and a fetcher points at the GraphQL endpoint. Splitting the template around the endpoint keeps it a plain string with no interpolation machinery.

    graphql_app

    Lift the GraphQL handler onto the load-bearing AsgiApp a server binds to. This is what mooncat (or any moonasgi server) mounts to serve the schema over real HTTP; the request→response logic is shared with graphql_handler, which TestClient exercises without a socket.

    graphql_handler

    Build the moonasgi request handler for a schema and its resolvers, following the GraphQL-over-HTTP specification.

    A POST on path executes an application/json body — one request object, or an array of them for a batch. A GET with a ?query= executes a query operation (only a query: a mutation there is a 405); a GET without one serves the GraphiQL IDE when graphiql is true. The response media type is negotiated from Accept: a client asking for application/graphql-response+json gets it, and with it the status codes that separate a request error (400) from a field error (200); anything else gets application/json and a 200. Lift it onto an AsgiApp with graphql_app, or drive it directly with moonasgi's TestClient.

    graphql_ws_handler

    Build a graphql-transport-ws WebSocket handler for schema / resolvers / subscribers. root_value and context are threaded to every operation the way execute threads them. Negotiates the graphql-transport-ws subprotocol when the client offers it.

    The handler owns its connection state, so nothing can drive the protocol's timers: build a GqlWs and take its handler when the server can tick.