line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package GraphQL::Role::FieldsEither; |
2
|
|
|
|
|
|
|
|
3
|
18
|
|
|
18
|
|
11272
|
use 5.014; |
|
18
|
|
|
|
|
88
|
|
4
|
18
|
|
|
18
|
|
106
|
use strict; |
|
18
|
|
|
|
|
74
|
|
|
18
|
|
|
|
|
411
|
|
5
|
18
|
|
|
18
|
|
91
|
use warnings; |
|
18
|
|
|
|
|
38
|
|
|
18
|
|
|
|
|
443
|
|
6
|
18
|
|
|
18
|
|
93
|
use Moo::Role; |
|
18
|
|
|
|
|
35
|
|
|
18
|
|
|
|
|
150
|
|
7
|
18
|
|
|
18
|
|
6781
|
use GraphQL::Debug qw(_debug); |
|
18
|
|
|
|
|
56
|
|
|
18
|
|
|
|
|
1069
|
|
8
|
18
|
|
|
18
|
|
116
|
use GraphQL::MaybeTypeCheck; |
|
18
|
|
|
|
|
57
|
|
|
18
|
|
|
|
|
137
|
|
9
|
18
|
|
|
18
|
|
107
|
use Types::Standard -all; |
|
18
|
|
|
|
|
38
|
|
|
18
|
|
|
|
|
129
|
|
10
|
18
|
|
|
18
|
|
854576
|
use JSON::MaybeXS; |
|
18
|
|
|
|
|
47
|
|
|
18
|
|
|
|
|
2022
|
|
11
|
|
|
|
|
|
|
with qw(GraphQL::Role::FieldDeprecation); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
14
|
18
|
|
|
18
|
|
130
|
use constant DEBUG => $ENV{GRAPHQL_DEBUG}; |
|
18
|
|
|
|
|
39
|
|
|
18
|
|
|
|
|
1978
|
|
15
|
|
|
|
|
|
|
my $JSON_noutf8 = JSON::MaybeXS->new->utf8(0)->allow_nonref; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
GraphQL::Role::FieldsEither - GraphQL object role with code common to all fields |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
with qw(GraphQL::Role::FieldsEither); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# or runtime |
26
|
|
|
|
|
|
|
Role::Tiny->apply_roles_to_object($foo, qw(GraphQL::Role::FieldsEither)); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 DESCRIPTION |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Provides code useful to either type of fields. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
method _make_field_def( |
35
|
|
|
|
|
|
|
HashRef $name2type, |
36
|
|
|
|
|
|
|
Str $field_name, |
37
|
|
|
|
|
|
|
HashRef $field_def, |
38
|
127
|
50
|
|
127
|
|
372
|
) { |
|
127
|
50
|
|
|
|
279
|
|
|
127
|
50
|
|
|
|
191
|
|
|
127
|
50
|
|
|
|
263
|
|
|
127
|
50
|
|
|
|
332
|
|
|
127
|
|
|
|
|
1170
|
|
|
127
|
|
|
|
|
1275
|
|
|
127
|
|
|
|
|
803
|
|
39
|
127
|
|
|
|
|
163
|
DEBUG and _debug('FieldsEither._make_field_def', $field_def); |
40
|
127
|
|
|
|
|
564
|
require GraphQL::Schema; |
41
|
127
|
|
|
|
|
192
|
my %args; |
42
|
|
|
|
|
|
|
%args = (args => +{ |
43
|
|
|
|
|
|
|
map $self->_make_field_def($name2type, $_, $field_def->{args}{$_}), |
44
|
22
|
|
|
|
|
137
|
keys %{$field_def->{args}} |
45
|
127
|
100
|
|
|
|
317
|
}) if $field_def->{args}; |
46
|
127
|
|
|
|
|
1047
|
($_ => { |
47
|
|
|
|
|
|
|
%$field_def, |
48
|
|
|
|
|
|
|
type => GraphQL::Schema::lookup_type($field_def, $name2type), |
49
|
|
|
|
|
|
|
%args, |
50
|
|
|
|
|
|
|
}); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
method _from_ast_fields( |
54
|
|
|
|
|
|
|
HashRef $name2type, |
55
|
|
|
|
|
|
|
HashRef $ast_node, |
56
|
|
|
|
|
|
|
Str $key, |
57
|
87
|
50
|
|
87
|
|
245
|
) { |
|
87
|
50
|
|
|
|
188
|
|
|
87
|
50
|
|
|
|
149
|
|
|
87
|
50
|
|
|
|
192
|
|
|
87
|
50
|
|
|
|
186
|
|
|
87
|
|
|
|
|
611
|
|
|
87
|
|
|
|
|
592
|
|
|
87
|
|
|
|
|
776
|
|
58
|
87
|
|
|
|
|
177
|
my $fields = $ast_node->{$key}; |
59
|
87
|
|
|
|
|
449
|
$fields = $self->_from_ast_field_deprecate($_, $fields) for keys %$fields; |
60
|
|
|
|
|
|
|
( |
61
|
|
|
|
|
|
|
$key => sub { +{ |
62
|
|
|
|
|
|
|
map { |
63
|
74
|
|
|
74
|
|
8486
|
my @pair = eval { |
|
99
|
|
|
|
|
168
|
|
64
|
99
|
|
|
|
|
320
|
$self->_make_field_def($name2type, $_, $fields->{$_}) |
65
|
|
|
|
|
|
|
}; |
66
|
99
|
100
|
|
|
|
2507
|
die "Error in field '$_': $@" if $@; |
67
|
97
|
|
|
|
|
1785
|
@pair; |
68
|
|
|
|
|
|
|
} keys %$fields |
69
|
|
|
|
|
|
|
} }, |
70
|
87
|
|
|
|
|
2454
|
); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
method _description_doc_lines( |
74
|
|
|
|
|
|
|
Maybe[Str] $description, |
75
|
153
|
50
|
|
153
|
|
362
|
) { |
|
153
|
50
|
|
|
|
284
|
|
|
153
|
50
|
|
|
|
212
|
|
|
153
|
|
|
|
|
308
|
|
|
153
|
|
|
|
|
313
|
|
|
153
|
|
|
|
|
1254
|
|
76
|
153
|
|
|
|
|
178
|
DEBUG and _debug('FieldsEither._description_doc_lines', $description); |
77
|
153
|
100
|
|
|
|
643
|
return if !$description; |
78
|
8
|
50
|
|
|
|
45
|
my @lines = $description ? split /\n/, $description : (); |
79
|
8
|
50
|
|
|
|
23
|
return if !@lines; |
80
|
8
|
100
|
|
|
|
33
|
if (@lines == 1) { |
|
|
50
|
|
|
|
|
|
81
|
7
|
|
|
|
|
51
|
return '"' . ($lines[0] =~ s#"#\\"#gr) . '"'; |
82
|
|
|
|
|
|
|
} elsif (@lines > 1) { |
83
|
|
|
|
|
|
|
return ( |
84
|
1
|
|
|
|
|
15
|
'"""', |
85
|
|
|
|
|
|
|
(map s#"""#\\"""#gr, @lines), |
86
|
|
|
|
|
|
|
'"""', |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
method _make_fieldtuples( |
92
|
|
|
|
|
|
|
HashRef $fields, |
93
|
134
|
50
|
|
134
|
|
1075
|
) { |
|
134
|
50
|
|
|
|
255
|
|
|
134
|
50
|
|
|
|
182
|
|
|
134
|
|
|
|
|
212
|
|
|
134
|
|
|
|
|
293
|
|
|
134
|
|
|
|
|
958
|
|
94
|
134
|
|
|
|
|
180
|
DEBUG and _debug('FieldsEither._make_fieldtuples', $fields); |
95
|
|
|
|
|
|
|
map { |
96
|
134
|
|
|
|
|
399
|
my $field = $fields->{$_}; |
|
88
|
|
|
|
|
154
|
|
97
|
|
|
|
|
|
|
my @argtuples = map $_->[0], |
98
|
88
|
|
100
|
|
|
464
|
$self->_make_fieldtuples($field->{args} || {}); |
99
|
88
|
|
|
|
|
205
|
my $type = $field->{type}; |
100
|
88
|
|
|
|
|
159
|
my $line = $_; |
101
|
88
|
100
|
|
|
|
577
|
$line .= '('.join(', ', @argtuples).')' if @argtuples; |
102
|
88
|
|
|
|
|
1632
|
$line .= ': ' . $type->to_string; |
103
|
|
|
|
|
|
|
$line .= ' = ' . $JSON_noutf8->encode( |
104
|
|
|
|
|
|
|
$type->perl_to_graphql($field->{default_value}) |
105
|
88
|
100
|
|
|
|
1608
|
) if exists $field->{default_value}; |
106
|
|
|
|
|
|
|
my @directives = map { |
107
|
4
|
|
|
|
|
9
|
my $args = $_->{arguments}; |
108
|
4
|
|
|
|
|
11
|
my @argtuples = map { "$_: " . $JSON_noutf8->encode($args->{$_}) } keys %$args; |
|
1
|
|
|
|
|
12
|
|
109
|
4
|
100
|
|
|
|
24
|
'@' . $_->{name} . (@argtuples ? '(' . join(', ', @argtuples) . ')' : ''); |
110
|
88
|
100
|
|
|
|
138
|
} @{ $field->{directives} || [] }; |
|
88
|
|
|
|
|
381
|
|
111
|
88
|
100
|
|
|
|
206
|
$line .= join(' ', ('', @directives)) if @directives; |
112
|
|
|
|
|
|
|
[ |
113
|
|
|
|
|
|
|
$self->_to_doc_field_deprecate($line, $field), |
114
|
88
|
|
|
|
|
312
|
$self->_description_doc_lines($field->{description}), |
115
|
|
|
|
|
|
|
] |
116
|
|
|
|
|
|
|
} sort keys %$fields; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |