| 1 | package GraphQL::Plugin::Type::DateTime; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 3 | ▶ | use GraphQL::Type::Scalar; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 3 | ▶ | use GraphQL::Plugin::Type; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 3 | ▶ | use DateTime::Format::ISO8601; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | =head1 NAME | ||||||||||
| 10 | |||||||||||
| 11 | GraphQL::Plugin::Type::DateTime - GraphQL DateTime scalar type | ||||||||||
| 12 | |||||||||||
| 13 | =head1 SYNOPSIS | ||||||||||
| 14 | |||||||||||
| 15 | use GraphQL::Schema; | ||||||||||
| 16 | use GraphQL::Plugin::Type::DateTime; | ||||||||||
| 17 | use GraphQL::Execution qw(execute); | ||||||||||
| 18 | my $schema = GraphQL::Schema->from_doc(<<'EOF'); | ||||||||||
| 19 | type Query { dateTimeNow: DateTime } | ||||||||||
| 20 | EOF | ||||||||||
| 21 | post '/graphql' => sub { | ||||||||||
| 22 | send_as JSON => execute( | ||||||||||
| 23 | $schema, | ||||||||||
| 24 | body_parameters->{query}, | ||||||||||
| 25 | { dateTimeNow => sub { DateTime->now } }, | ||||||||||
| 26 | undef, | ||||||||||
| 27 | body_parameters->{variables}, | ||||||||||
| 28 | body_parameters->{operationName}, | ||||||||||
| 29 | undef, | ||||||||||
| 30 | ); | ||||||||||
| 31 | }; | ||||||||||
| 32 | |||||||||||
| 33 | =head1 DESCRIPTION | ||||||||||
| 34 | |||||||||||
| 35 | Implements a non-standard GraphQL scalar type that represents | ||||||||||
| 36 | a point in time, canonically represented in ISO 8601 format, | ||||||||||
| 37 | e.g. C<20171114T07:41:10>. | ||||||||||
| 38 | |||||||||||
| 39 | =cut | ||||||||||
| 40 | |||||||||||
| 41 | 3 | my $iso8601 = DateTime::Format::ISO8601->new; | |||||||||
| 42 | GraphQL::Plugin::Type->register( | ||||||||||
| 43 | GraphQL::Type::Scalar->new( | ||||||||||
| 44 | name => 'DateTime', | ||||||||||
| 45 | description => | ||||||||||
| 46 | 'The `DateTime` scalar type represents a point in time. ' . | ||||||||||
| 47 | 'Canonically represented using ISO 8601 format, e.g. 20171114T07:41:10, '. | ||||||||||
| 48 | 'which is 14 November 2017 at 07:41am.', | ||||||||||
| 49 | 1 | ▶ | serialize => sub { return if !defined $_[0]; $_[0].'' }, | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||
| 50 | 0 | ▶ | parse_value => sub { return if !defined $_[0]; $iso8601->parse_datetime(@_); }, | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||
| 51 | ) | ||||||||||
| 52 | 3 | ); | |||||||||
| 53 | |||||||||||
| 54 | 3 | 1; | |||||||||