GraphQ...n::Type(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::Plugin::Type πŸ’–

okay bestie, welcome to the manual page for GraphQL::Plugin::Type (it lives in the Perl user-contributed docs, section 3pm, and honestly? she's iconic). this is where GraphQL plugins that implement types hang out. pull up a chair, grab a boba, let's get into it πŸ§‹βœ¨


🌸 NAME 🌸

GraphQL::Plugin::Type β€” GraphQL plugins implementing types πŸ¦‹


✨ SYNOPSIS ✨

like, here's the whole vibe in code form. every character preserved, no cap:

package GraphQL::Plugin::Type::DateTime;
use Moo;
extends qw(GraphQL::Plugin::Type);
my $iso8601 = DateTime::Format::ISO8601->new;
GraphQL::Plugin::Type->register(
  GraphQL::Type::Scalar->new(
    name => 'DateTime',
    serialize => sub { return if !defined $_[0]; $_[0].'' },
    parse_value => sub { return if !defined $_[0]; $iso8601->parse_datetime(@_); },
  )
);
1;

package main;
use GraphQL::Schema;
use GraphQL::Plugin::Type::DateTime;
use GraphQL::Execution qw(execute);
my $schema = GraphQL::Schema->from_doc(<<'EOF');
type Query { dateTimeNow: DateTime }
EOF
post '/graphql' => sub {
  send_as JSON => execute(
    $schema,
    body_parameters->{query},
    { dateTimeNow => sub { DateTime->now } },
    undef,
    body_parameters->{variables},
    body_parameters->{operationName},
    undef,
  );
};

πŸ’… DESCRIPTION πŸ’…

so this is the class that implements the whole scheme by which you can add extra GraphQL type classes. it's giving framework energy. πŸ‘‘

fr fr, the author's take is that this is only worth doing for scalars β€” and honestly? that checks out, because this scheme is (now) literally how the non-standard "DateTime" is implemented in graphql-perl. 🌈

but say you wanna make other types β€” like GraphQL::Type::Object, GraphQL::Type::InputObject, etc. β€” well bestie, the Schema Definition Language is already right there, available, no need to do the plugin thing. πŸ™ˆ

however, any type can be registered with the "register" method, and once you do, it will be automatically available to GraphQL::Schema objects with no additional code. slay. ✨


πŸŽ€ METHODS πŸŽ€

πŸ’œ register($graphql_type)

when you call this with a GraphQL::Type subclass, it registers it. easy. cute. 🫢

but if you call it with anything that isn't a GraphQL::Type subclass? it dies. πŸ’€ so maybe don't do that.

πŸ’œ registered

returns a list of the registered classes. that's it, that's the whole method. simple queen behavior. πŸ‘‘


reminder bestie: register really does just πŸ’€ if you hand it something that isn't a GraphQL::Type subclass. not me warning you twice. πŸ™ˆ

and that's the whole page, mwah πŸ’‹ β€” this was the GraphQ...n::Type(3pm) page from the User Contributed Perl Documentation, generated with perl v5.34.0, dated 2022-03-27. periodt. πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from