GraphQ...:Union(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

✨ NAME ✨

GraphQL::Type::Union β€” bestie, it's literally the GraphQL union type πŸ’… this is the GraphQL::Type::Union page from your friendly neighbourhood User Contributed Perl Documentation, and we're gonna make unions make sense, no cap 🫢


🌸 SYNOPSIS 🌸

okay so here's the whole vibe, copy-paste ready:

use GraphQL::Type::Union;
my $union_type = GraphQL::Type::Union->new(
  name => 'Union',
  types => [ $type1, $type2 ],
  resolve_type => sub {
    return $type1 if ref $_[0] eq 'Type1';
    return $type2 if ref $_[0] eq 'Type2';
  },
);

see how she eats? πŸ”₯ you hand her a name, a lil types array, and a resolve_type sub that looks at a value and decides which type it belongs to. iconic behaviour honestly.


πŸŽ€ ATTRIBUTES πŸŽ€

she inherits name and description straight from GraphQL::Type β€” those are the family genes πŸ’–

πŸ’œ types

a thunked array-ref of GraphQL::Type::Object objects. yes bestie, thunked β€” she'll call it when she's good and ready, not a second sooner ⭐

πŸ’œ resolve_type

optional code-ref, lowkey the main character here πŸ‘‘ you feed her a value, she hands back a GraphQL type object for it. simple as.

but β€” and listen β€” if you don't give her one? she falls back on her possible type objects having a provided is_type_of. so like, either bring your own resolver or make sure your types can identify themselves. pick a lane, both work πŸ¦‹


🌈 METHODS 🌈

πŸ“ get_types

returns a list of GraphQL::Type::Objects of which the object is a union β€” and yeah, she runs validation while she's at it, because she's not about to let you ship something broken, fr fr πŸ’€


ngl bestie, if you're reaching for this module you're already doing great. go build something slay πŸ’…βœ¨

perl v5.34.0 🌸 2022-03-27 β€” that's the version and the date, mwah, sending you off with a kiss and a GraphQL::Type::Union(3pm) πŸ«ΆπŸŽ€

πŸ“¦ where this page comes from