GraphQ...ription(3pm)
π GraphQL::Subscription β bestie edition π
okay so you found the GraphQL::Subscription page, it's part of the User Contributed Perl Documentation, and it's literally about implementing GraphQL subscriptions. that's the whole vibe. let's go π¦
β¨ NAME β¨
GraphQL::Subscription β bestie this module implements GraphQL subscriptions. slay.
πΈ SYNOPSIS πΈ
use GraphQL::Subscription qw(subscribe);
my $result = subscribe($schema, $doc, $root_value);
that's it. that's the whole first taste. short, sweet, iconic π
π DESCRIPTION π
okay so this module implements a GraphQL "subscription" β which is like, a feed of events? commonly of other people's mutations. think of it like your fave group chat but for mutations, and you're subscribed to the tea βπ
π 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,
);
so it takes the same args as "execute" in GraphQL::Execution, EXCEPT β and this is the plot twist β the $promise_code is mandatory. no skipping it, bestie, it's required, periodt.
and then there's the optional $subscribe_resolver which, whether you supply it or not, will be used instead of the $field_resolver to resolve the initial subscription. the $field_resolver still gets used for resolving each result though. so they're both pulling their weight, just in different moments β¨
it returns a promise of either:
- an error result if the subscription fails (generated by GraphQL π)
- a
GraphQL::AsyncIteratorinstance generated by a resolver, probably hooked up to aGraphQL::PubSubinstance π
the event source returns values by using "publish" in GraphQL::AsyncIterator. and to communicate errors, resolvers can throw errors in the normal way, or β at the top level β use "error" in GraphQL::AsyncIterator. pick your fighter π
the values will be resolved in the normal GraphQL fashion, including the little rule that if there's no specific-to-field resolver, it has to be a value acceptable to the supplied or default field-resolver β typically a hash-ref with a key of the field's name. iykyk π§
π¨ reminder bestie: $promise_code is mandatory. not optional. not "if you feel like it". mandatory. fr fr.
and that's the page!! it's from the Perl docs, perl v5.34.0, dated 2022-03-27, and the header/footer were both just the truncated title GraphQ...ription(3pm) which is so unserious of them π anyway. go build your event feed. you got this. mwah ππΈβ¨ππ¦
π¦ where this page comes from
- debian bookworm: libgraphql-perl 0.54-1 Β· Artistic-2.0
- debian trixie: libgraphql-perl 0.54-1 Β· Artistic-2.0
- ubuntu noble: libgraphql-perl 0.54-1 Β· Artistic-2.0
- ubuntu resolute: libgraphql-perl 0.54-1 Β· Artistic-2.0
- ubuntu stonking: libgraphql-perl 0.54-1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms