GraphQL::Plugin::Type(3pm)

GraphQL::Plugin::Type3pm

Graphql plugins implementing types

Usage

  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,
    );
  };

Overview

Class implementing the scheme by which additional GraphQL type classes can be implemented.

The author considers this is only worth doing for scalars, and indeed this scheme is (now) how the non-standard "DateTime" is implemented in graphql-perl. If one wants to create other types (GraphQL::Type::Object, GraphQL::Type::InputObject, etc), then the Schema Definition Language is already available. However, any type can be registered with the "register" method, and will be automatically available to GraphQL::Schema objects with no additional code.

Methods

register($graphql_type)

When called with a GraphQL::Type subclass, will register it, otherwise dies.

registered

Returns a list of registered classes.

Releases

Unchanged in 2 releases since Debian 12 (Bookworm).

  1. 12–13

From libgraphql-perl 0.54-1 in Debian 13 (Trixie). Parsed by carta from the page's man source.