GraphQ...:Union(3pm)
β¨ 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
- 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