line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package GraphQL::Plugin::Type::DateTime; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
91944
|
use strict; |
|
3
|
|
|
|
|
16
|
|
|
3
|
|
|
|
|
84
|
|
4
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
72
|
|
5
|
3
|
|
|
3
|
|
713
|
use GraphQL::Type::Scalar; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
143
|
|
6
|
3
|
|
|
3
|
|
21
|
use GraphQL::Plugin::Type; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
19
|
|
7
|
3
|
|
|
3
|
|
2381
|
use DateTime::Format::ISO8601; |
|
3
|
|
|
|
|
1569298
|
|
|
3
|
|
|
|
|
547
|
|
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; |