GraphQ...ription(3pm)

πŸ“¦
version 0.54 Β· 2 versions
  • 0.54 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.53 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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::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. 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