GraphQ...n::Type(3pm)
π 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:registerreally does just π if you hand it something that isn't aGraphQL::Typesubclass. 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
- 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