line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package GraphQL::Plugin::Type::DateTime; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
92155
|
use strict; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
126
|
|
4
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
99
|
|
5
|
3
|
|
|
3
|
|
748
|
use GraphQL::Type::Scalar; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
167
|
|
6
|
3
|
|
|
3
|
|
20
|
use GraphQL::Plugin::Type; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
20
|
|
7
|
3
|
|
|
3
|
|
1995
|
use DateTime::Format::ISO8601; |
|
3
|
|
|
|
|
1858277
|
|
|
3
|
|
|
|
|
682
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
serialize => sub { return if !defined $_[0]; $_[0].'' }, |
50
|
|
|
|
|
|
|
parse_value => sub { return if !defined $_[0]; $iso8601->parse_datetime(@_); }, |
51
|
|
|
|
|
|
|
) |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |