line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use 5.014; |
3
|
18
|
|
|
18
|
|
9747
|
use strict; |
|
18
|
|
|
|
|
60
|
|
4
|
18
|
|
|
18
|
|
91
|
use warnings; |
|
18
|
|
|
|
|
54
|
|
|
18
|
|
|
|
|
394
|
|
5
|
18
|
|
|
18
|
|
77
|
use Moo::Role; |
|
18
|
|
|
|
|
33
|
|
|
18
|
|
|
|
|
402
|
|
6
|
18
|
|
|
18
|
|
82
|
use GraphQL::Debug qw(_debug); |
|
18
|
|
|
|
|
33
|
|
|
18
|
|
|
|
|
123
|
|
7
|
18
|
|
|
18
|
|
5929
|
use GraphQL::MaybeTypeCheck; |
|
18
|
|
|
|
|
36
|
|
|
18
|
|
|
|
|
852
|
|
8
|
18
|
|
|
18
|
|
98
|
use Types::Standard -all; |
|
18
|
|
|
|
|
35
|
|
|
18
|
|
|
|
|
103
|
|
9
|
18
|
|
|
18
|
|
85
|
use JSON::MaybeXS; |
|
18
|
|
|
|
|
38
|
|
|
18
|
|
|
|
|
129
|
|
10
|
18
|
|
|
18
|
|
714046
|
with qw(GraphQL::Role::FieldDeprecation); |
|
18
|
|
|
|
|
45
|
|
|
18
|
|
|
|
|
1922
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
13
|
|
|
|
|
|
|
use constant DEBUG => $ENV{GRAPHQL_DEBUG}; |
14
|
18
|
|
|
18
|
|
112
|
my $JSON_noutf8 = JSON::MaybeXS->new->utf8(0)->allow_nonref; |
|
18
|
|
|
|
|
34
|
|
|
18
|
|
|
|
|
1848
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 NAME |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
GraphQL::Role::FieldsEither - GraphQL object role with code common to all fields |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
with qw(GraphQL::Role::FieldsEither); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# or runtime |
25
|
|
|
|
|
|
|
Role::Tiny->apply_roles_to_object($foo, qw(GraphQL::Role::FieldsEither)); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Provides code useful to either type of fields. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
method _make_field_def( |
34
|
|
|
|
|
|
|
HashRef $name2type, |
35
|
|
|
|
|
|
|
Str $field_name, |
36
|
|
|
|
|
|
|
HashRef $field_def, |
37
|
|
|
|
|
|
|
) { |
38
|
127
|
50
|
|
127
|
|
388
|
DEBUG and _debug('FieldsEither._make_field_def', $field_def); |
|
127
|
50
|
|
|
|
269
|
|
|
127
|
50
|
|
|
|
182
|
|
|
127
|
50
|
|
|
|
241
|
|
|
127
|
50
|
|
|
|
332
|
|
|
127
|
|
|
|
|
1103
|
|
|
127
|
|
|
|
|
1200
|
|
|
127
|
|
|
|
|
744
|
|
39
|
127
|
|
|
|
|
157
|
require GraphQL::Schema; |
40
|
127
|
|
|
|
|
543
|
my %args; |
41
|
127
|
|
|
|
|
194
|
%args = (args => +{ |
42
|
|
|
|
|
|
|
map $self->_make_field_def($name2type, $_, $field_def->{args}{$_}), |
43
|
|
|
|
|
|
|
keys %{$field_def->{args}} |
44
|
22
|
|
|
|
|
122
|
}) if $field_def->{args}; |
45
|
127
|
100
|
|
|
|
312
|
($_ => { |
46
|
127
|
|
|
|
|
983
|
%$field_def, |
47
|
|
|
|
|
|
|
type => GraphQL::Schema::lookup_type($field_def, $name2type), |
48
|
|
|
|
|
|
|
%args, |
49
|
|
|
|
|
|
|
}); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
method _from_ast_fields( |
53
|
|
|
|
|
|
|
HashRef $name2type, |
54
|
|
|
|
|
|
|
HashRef $ast_node, |
55
|
|
|
|
|
|
|
Str $key, |
56
|
|
|
|
|
|
|
) { |
57
|
87
|
50
|
|
87
|
|
215
|
my $fields = $ast_node->{$key}; |
|
87
|
50
|
|
|
|
200
|
|
|
87
|
50
|
|
|
|
154
|
|
|
87
|
50
|
|
|
|
185
|
|
|
87
|
50
|
|
|
|
190
|
|
|
87
|
|
|
|
|
605
|
|
|
87
|
|
|
|
|
578
|
|
|
87
|
|
|
|
|
669
|
|
58
|
87
|
|
|
|
|
184
|
$fields = $self->_from_ast_field_deprecate($_, $fields) for keys %$fields; |
59
|
87
|
|
|
|
|
570
|
( |
60
|
|
|
|
|
|
|
$key => sub { +{ |
61
|
|
|
|
|
|
|
map { |
62
|
|
|
|
|
|
|
my @pair = eval { |
63
|
74
|
|
|
74
|
|
7576
|
$self->_make_field_def($name2type, $_, $fields->{$_}) |
|
99
|
|
|
|
|
166
|
|
64
|
99
|
|
|
|
|
352
|
}; |
65
|
|
|
|
|
|
|
die "Error in field '$_': $@" if $@; |
66
|
99
|
100
|
|
|
|
1998
|
@pair; |
67
|
97
|
|
|
|
|
1932
|
} keys %$fields |
68
|
|
|
|
|
|
|
} }, |
69
|
|
|
|
|
|
|
); |
70
|
87
|
|
|
|
|
2952
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
method _description_doc_lines( |
73
|
|
|
|
|
|
|
Maybe[Str] $description, |
74
|
|
|
|
|
|
|
) { |
75
|
153
|
50
|
|
153
|
|
309
|
DEBUG and _debug('FieldsEither._description_doc_lines', $description); |
|
153
|
50
|
|
|
|
590
|
|
|
153
|
50
|
|
|
|
199
|
|
|
153
|
|
|
|
|
290
|
|
|
153
|
|
|
|
|
298
|
|
|
153
|
|
|
|
|
1115
|
|
76
|
153
|
|
|
|
|
157
|
return if !$description; |
77
|
153
|
100
|
|
|
|
568
|
my @lines = $description ? split /\n/, $description : (); |
78
|
8
|
50
|
|
|
|
31
|
return if !@lines; |
79
|
8
|
50
|
|
|
|
17
|
if (@lines == 1) { |
80
|
8
|
100
|
|
|
|
21
|
return '"' . ($lines[0] =~ s#"#\\"#gr) . '"'; |
|
|
50
|
|
|
|
|
|
81
|
7
|
|
|
|
|
35
|
} elsif (@lines > 1) { |
82
|
|
|
|
|
|
|
return ( |
83
|
|
|
|
|
|
|
'"""', |
84
|
1
|
|
|
|
|
10
|
(map s#"""#\\"""#gr, @lines), |
85
|
|
|
|
|
|
|
'"""', |
86
|
|
|
|
|
|
|
); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
method _make_fieldtuples( |
91
|
|
|
|
|
|
|
HashRef $fields, |
92
|
|
|
|
|
|
|
) { |
93
|
134
|
50
|
|
134
|
|
1003
|
DEBUG and _debug('FieldsEither._make_fieldtuples', $fields); |
|
134
|
50
|
|
|
|
265
|
|
|
134
|
50
|
|
|
|
160
|
|
|
134
|
|
|
|
|
185
|
|
|
134
|
|
|
|
|
290
|
|
|
134
|
|
|
|
|
879
|
|
94
|
134
|
|
|
|
|
153
|
map { |
95
|
|
|
|
|
|
|
my $field = $fields->{$_}; |
96
|
134
|
|
|
|
|
384
|
my @argtuples = map $_->[0], |
|
88
|
|
|
|
|
147
|
|
97
|
|
|
|
|
|
|
$self->_make_fieldtuples($field->{args} || {}); |
98
|
88
|
|
100
|
|
|
447
|
my $type = $field->{type}; |
99
|
88
|
|
|
|
|
222
|
my $line = $_; |
100
|
88
|
|
|
|
|
128
|
$line .= '('.join(', ', @argtuples).')' if @argtuples; |
101
|
88
|
100
|
|
|
|
208
|
$line .= ': ' . $type->to_string; |
102
|
88
|
|
|
|
|
1458
|
$line .= ' = ' . $JSON_noutf8->encode( |
103
|
|
|
|
|
|
|
$type->perl_to_graphql($field->{default_value}) |
104
|
|
|
|
|
|
|
) if exists $field->{default_value}; |
105
|
88
|
100
|
|
|
|
1425
|
my @directives = map { |
106
|
|
|
|
|
|
|
my $args = $_->{arguments}; |
107
|
4
|
|
|
|
|
8
|
my @argtuples = map { "$_: " . $JSON_noutf8->encode($args->{$_}) } keys %$args; |
108
|
4
|
|
|
|
|
8
|
'@' . $_->{name} . (@argtuples ? '(' . join(', ', @argtuples) . ')' : ''); |
|
1
|
|
|
|
|
14
|
|
109
|
4
|
100
|
|
|
|
36
|
} @{ $field->{directives} || [] }; |
110
|
88
|
100
|
|
|
|
126
|
$line .= join(' ', ('', @directives)) if @directives; |
|
88
|
|
|
|
|
318
|
|
111
|
88
|
100
|
|
|
|
196
|
[ |
112
|
|
|
|
|
|
|
$self->_to_doc_field_deprecate($line, $field), |
113
|
|
|
|
|
|
|
$self->_description_doc_lines($field->{description}), |
114
|
88
|
|
|
|
|
269
|
] |
115
|
|
|
|
|
|
|
} sort keys %$fields; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |