interface SubscriptionResolver
Since 0.3.0

A subscription field's resolver pair.

subscribe returns the async iterable the field streams from and is attached to the schema field's subscribe slot; the optional resolve maps each emitted payload to the field value, exactly as graphql defines it.

Without this arm a subscription is unexpressible in the schema-first map: an entry has to be a function, and assigning { subscribe } to a field's resolve leaves subscribe unset, which makes graphql.subscribe() throw "Subscription field must return Async Iterable".

Type Parameters

TSource = unknown
TContext = unknown
TArgs = Record<string, unknown>

Properties

subscribe: (
source: TSource,
args: TArgs,
context: TContext,
info: unknown
) => AsyncIterable<unknown> | Promise<AsyncIterable<unknown>>

Produces the event source for this subscription field.

Maps each emitted payload to the field value. Optional.

Usage

import { type SubscriptionResolver } from "graphql-plugin/src/index.ts";