GraphQL::Subscription(3pm)

GraphQL::Subscription3pm

Implement graphql subscriptions

Usage

  use GraphQL::Subscription qw(subscribe);
  my $result = subscribe($schema, $doc, $root_value);

Overview

Implements a GraphQL "subscription" - a feed of events, commonly of others' mutations.

Methods

subscribe

  my $result = subscribe(
    $schema,
    $doc, # can also be AST
    $root_value,
    $context_value,
    $variable_values,
    $operation_name,
    $field_resolver,
    $promise_code,
    $subscribe_resolver,
  );

Takes the same args as "execute" in GraphQL::Execution, except that the $promise_code is mandatory, and there is the optional $subscribe_resolver which, supplied or not, will be used instead of the $field_resolver to resolve the initial subscription. The $field_resolver will still be used for resolving each result.

Returns a promise of either:

•

an error result if the subscription fails (generated by GraphQL)

•

a GraphQL::AsyncIterator instance generated by a resolver, probably hooked up to a GraphQL::PubSub instance

The event source returns values by using "publish" in GraphQL::AsyncIterator. To communicate errors, resolvers can throw errors in the normal way, or at the top level, use "error" in GraphQL::AsyncIterator.

The values will be resolved in the normal GraphQL fashion, including that if there is no specific-to-field resolver, it must be a value acceptable to the supplied or default field-resolver, typically a hash-ref with a key of the field's name.

Releases

Unchanged in 2 releases since Debian 12 (Bookworm).

  1. 12–13

From libgraphql-perl 0.54-1 in Debian 13 (Trixie). Parsed by carta from the page's man source.