blib/lib/GraphQL/Houtou/Introspection.pm

filter: Statementstmt 99.3% 143 / 144 Branchbran 85.7% 36 / 42 Conditioncond 60.0% 6 / 10 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 97.6% 42 / 43 Podpod n/a totaltotal 93.4% 228 / 244 CC 27 SCAR 7.6
CC
27
Cov
94%
__ANON__
4.0
__ANON__
3.1
__ANON__
3.0
CRAP 2.1
« blib/lib/GraphQL/Houtou/Type.pm ↑ Summary blib/lib/GraphQL/Houtou/Runtime/SchemaBlock.pm »
1 package GraphQL::Houtou::Introspection;
2  
3 62 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 62 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 62 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 62 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 62 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 62 ▶use GraphQL::Houtou::Type::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 62 ▶use GraphQL::Houtou::Type::Enum;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 62 ▶use GraphQL::Houtou::Type::Scalar qw($String $Boolean);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 62 our @EXPORT_OK = qw(
15 $QUERY
16 $TYPE_KIND_META_TYPE
17 $DIRECTIVE_LOCATION_META_TYPE
18 $ENUM_VALUE_META_TYPE
19 $INPUT_VALUE_META_TYPE
20 $FIELD_META_TYPE
21 $DIRECTIVE_META_TYPE
22 $TYPE_META_TYPE
23 $SCHEMA_META_TYPE
24 $SCHEMA_META_FIELD_DEF
25 $TYPE_META_FIELD_DEF
26 $TYPE_NAME_META_FIELD_DEF
27 );
28  
29 # Responsibility: own Houtou's introspection surface without depending on the
30 # upstream GraphQL::Introspection package name.
31  
32 62 my $JSON_noutf8 = JSON::MaybeXS->new->utf8(0)->allow_nonref;
33  
34 62 our $QUERY = '
35 query IntrospectionQuery {
36 __schema {
37 description
38 queryType { name }
39 mutationType { name }
40 subscriptionType { name }
41 types {
42 ...FullType
43 }
44 directives {
45 name
46 description
47 isRepeatable
48 locations
49 args(includeDeprecated: true) {
50 ...InputValue
51 }
52 }
53 }
54 }
55 fragment FullType on __Type {
56 kind
57 name
58 description
59 fields(includeDeprecated: true) {
60 name
61 description
62 args(includeDeprecated: true) {
63 ...InputValue
64 }
65 type {
66 ...TypeRef
67 }
68 isDeprecated
69 deprecationReason
70 }
71 inputFields(includeDeprecated: true) {
72 ...InputValue
73 }
74 interfaces {
75 ...TypeRef
76 }
77 enumValues(includeDeprecated: true) {
78 name
79 description
80 isDeprecated
81 deprecationReason
82 }
83 possibleTypes {
84 ...TypeRef
85 }
86 specifiedByURL
87 isOneOf
88 }
89 fragment InputValue on __InputValue {
90 name
91 description
92 type { ...TypeRef }
93 defaultValue
94 isDeprecated
95 deprecationReason
96 }
97 fragment TypeRef on __Type {
98 kind
99 name
100 ofType {
101 kind
102 name
103 ofType {
104 kind
105 name
106 ofType {
107 kind
108 name
109 ofType {
110 kind
111 name
112 ofType {
113 kind
114 name
115 ofType {
116 kind
117 name
118 ofType {
119 kind
120 name
121 }
122 }
123 }
124 }
125 }
126 }
127 }
128 }
129 ';
130  
131 298 ▶sub _make_moo_field {
Subroutine _make_moo_field: called CC=1 SCAR=0.1
132 298 my ($field_name, $type) = @_;
133 return (
134 $field_name => {
135 122 ▶ resolve => sub {
Subroutine __ANON__: called CC=3 SCAR=11.4
136 122 my ($root_value, $args) = @_;
137 122 ▶ return undef unless $root_value->can($field_name);
Branch: 1 branch
BranchTrueFalseTotal
unless $root_value->can($field_name) 0 122 122
138 122 ▶ my @passon = %$args ? ($args) : ();
Branch: 1 branch
BranchTrueFalseTotal
%$args ? : 0 122 122
139 122 return $root_value->$field_name(@passon);
140 },
141 298 type => $type,
142 }
143 );
144 }
145  
146 162 ▶sub _make_hash_bool_field {
Subroutine _make_hash_bool_field: called CC=1 SCAR=0.0
147 162 my ($field_name, $type, $real) = @_;
148 return (
149 $field_name => {
150 187 ▶ resolve => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
151 187 my ($root_value) = @_;
152 187 return !!$root_value->{$real};
153 },
154 162 type => $type,
155 }
156 );
157 }
158  
159 162 ▶sub _make_hash_field {
Subroutine _make_hash_field: called CC=1 SCAR=0.0
160 162 my ($field_name, $type, $real) = @_;
161 return (
162 $field_name => {
163 187 ▶ resolve => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
164 187 my ($root_value) = @_;
165 187 return $root_value->{$real};
166 },
167 162 type => $type,
168 }
169 );
170 }
171  
172 125 ▶sub _hash2array {
Subroutine _hash2array: called CC=1 SCAR=0.0
173 125 my ($hash) = @_;
174 125 return [ map { +{ name => $_, %{ $hash->{$_} } } } sort keys %$hash ];
175 }
176  
177 154 ▶sub _isa_any {
Subroutine _isa_any: called CC=1 SCAR=0.0
178 154 my ($value, @classes) = @_;
179 154 return !!grep { $value->isa($_) } @classes;
180 }
181  
182 71 ▶sub _does_any {
Subroutine _does_any: called CC=1 SCAR=0.0
183 71 my ($value, @roles) = @_;
184 71 return !!grep { $value->DOES($_) } @roles;
185 }
186  
187 62 ▶use constant CLASS2KIND => {
Subroutine BEGIN: called CC=1 SCAR=0.0
188 'GraphQL::Type::Enum' => 'ENUM',
189 'GraphQL::Type::Interface' => 'INTERFACE',
190 'GraphQL::Type::List' => 'LIST',
191 'GraphQL::Type::Object' => 'OBJECT',
192 'GraphQL::Type::Union' => 'UNION',
193 'GraphQL::Type::InputObject' => 'INPUT_OBJECT',
194 'GraphQL::Type::NonNull' => 'NON_NULL',
195 'GraphQL::Type::Scalar' => 'SCALAR',
196 'GraphQL::Houtou::Type::Enum' => 'ENUM',
197 'GraphQL::Houtou::Type::Interface' => 'INTERFACE',
198 'GraphQL::Houtou::Type::List' => 'LIST',
199 'GraphQL::Houtou::Type::Object' => 'OBJECT',
200 'GraphQL::Houtou::Type::Union' => 'UNION',
201 'GraphQL::Houtou::Type::InputObject' => 'INPUT_OBJECT',
202 'GraphQL::Houtou::Type::NonNull' => 'NON_NULL',
203 'GraphQL::Houtou::Type::Scalar' => 'SCALAR',
204 62 };
205  
206 62 our $TYPE_KIND_META_TYPE = GraphQL::Houtou::Type::Enum->new(
207 name => '__TypeKind',
208 is_introspection => 1,
209 description => 'An enum describing what kind of type a given `__Type` is.',
210 values => {
211 SCALAR => { description => 'Indicates this type is a scalar.' },
212 OBJECT => { description => 'Indicates this type is an object. `fields` and `interfaces` are valid fields.' },
213 INTERFACE => { description => 'Indicates this type is an interface. `fields` and `possibleTypes` are valid fields.' },
214 UNION => { description => 'Indicates this type is a union. `possibleTypes` is a valid field.' },
215 ENUM => { description => 'Indicates this type is an enum. `enumValues` is a valid field.' },
216 INPUT_OBJECT => { description => 'Indicates this type is an input object. `inputFields` is a valid field.' },
217 LIST => { description => 'Indicates this type is a list. `ofType` is a valid field.' },
218 NON_NULL => { description => 'Indicates this type is a non-null. `ofType` is a valid field.' },
219 },
220 );
221  
222 62 our $DIRECTIVE_LOCATION_META_TYPE = GraphQL::Houtou::Type::Enum->new(
223 name => '__DirectiveLocation',
224 is_introspection => 1,
225 description =>
226 'A Directive can be adjacent to many parts of the GraphQL language, a ' .
227 '__DirectiveLocation describes one such possible adjacencies.',
228 values => {
229 QUERY => { description => 'Location adjacent to a query operation.' },
230 MUTATION => { description => 'Location adjacent to a mutation operation.' },
231 SUBSCRIPTION => { description => 'Location adjacent to a subscription operation.' },
232 FIELD => { description => 'Location adjacent to a field.' },
233 FRAGMENT_DEFINITION => { description => 'Location adjacent to a fragment definition.' },
234 FRAGMENT_SPREAD => { description => 'Location adjacent to a fragment spread.' },
235 INLINE_FRAGMENT => { description => 'Location adjacent to an inline fragment.' },
236 VARIABLE_DEFINITION => { description => 'Location adjacent to a variable definition.' },
237 SCHEMA => { description => 'Location adjacent to a schema definition.' },
238 SCALAR => { description => 'Location adjacent to a scalar definition.' },
239 OBJECT => { description => 'Location adjacent to an object type definition.' },
240 FIELD_DEFINITION => { description => 'Location adjacent to a field definition.' },
241 ARGUMENT_DEFINITION => { description => 'Location adjacent to an argument definition.' },
242 INTERFACE => { description => 'Location adjacent to an interface definition.' },
243 UNION => { description => 'Location adjacent to a union definition.' },
244 ENUM => { description => 'Location adjacent to an enum definition.' },
245 ENUM_VALUE => { description => 'Location adjacent to an enum value definition.' },
246 INPUT_OBJECT => { description => 'Location adjacent to an input object type definition.' },
247 INPUT_FIELD_DEFINITION => { description => 'Location adjacent to an input object field definition.' },
248 },
249 );
250  
251 62 our $ENUM_VALUE_META_TYPE = GraphQL::Houtou::Type::Object->new(
252 name => '__EnumValue',
253 is_introspection => 1,
254 description =>
255 'One possible value for a given Enum. Enum values are unique values, not ' .
256 'a placeholder for a string or numeric value. However an Enum value is ' .
257 'returned in a JSON response as a string.',
258 fields => {
259 name => { type => $String->non_null },
260 description => { type => $String },
261 _make_hash_bool_field(isDeprecated => $Boolean->non_null, 'isDeprecated'),
262 _make_hash_field(deprecationReason => $String, 'deprecationReason'),
263 },
264 );
265  
266 62 our $TYPE_META_TYPE;
267  
268 our $INPUT_VALUE_META_TYPE = GraphQL::Houtou::Type::Object->new(
269 name => '__InputValue',
270 is_introspection => 1,
271 description =>
272 'Arguments provided to Fields or Directives and the input fields of an ' .
273 'InputObject are represented as Input Values which describe their type ' .
274 'and optionally a default value.',
275 50 ▶ fields => sub { {
Subroutine __ANON__: called CC=1 SCAR=0.0
276 name => { type => $String->non_null },
277 description => { type => $String },
278 type => { type => $TYPE_META_TYPE->non_null },
279 defaultValue => {
280 type => $String,
281 description =>
282 'A GraphQL-formatted string representing the default value for this ' .
283 'input value.',
284 26 ▶ resolve => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
285 26 ▶ return unless defined(my $value = $_[0]->{default_value});
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $value = $_[0]{"default_value"}) 14 12 26
286 12 my $gql = $_[0]->{type}->perl_to_graphql($value);
287 12 ▶ return $gql if _isa_any($_[0]->{type}, 'GraphQL::Houtou::Type::Enum', 'GraphQL::Type::Enum');
Branch: 1 branch
BranchTrueFalseTotal
if _isa_any($_[0]{"type"}, "GraphQL::Houtou::Type::Enum", "GraphQL::Type::Enum") 0 12 12
288 12 return $JSON_noutf8->encode($gql);
289 },
290 },
291 50 _make_hash_bool_field(isDeprecated => $Boolean->non_null, 'is_deprecated'),
292 _make_hash_field(deprecationReason => $String, 'deprecation_reason'),
293 } },
294 62 );
295  
296 our $FIELD_META_TYPE = GraphQL::Houtou::Type::Object->new(
297 name => '__Field',
298 is_introspection => 1,
299 description =>
300 'Object and Interface types are described by a list of Fields, each of ' .
301 'which has a name, potentially a list of arguments, and a return type.',
302 50 ▶ fields => sub { {
Subroutine __ANON__: called CC=1 SCAR=0.0
303 name => { type => $String->non_null },
304 description => { type => $String },
305 args => {
306 type => $INPUT_VALUE_META_TYPE->non_null->list->non_null,
307 args => { includeDeprecated => { type => $Boolean, default_value => 0 } },
308 97 ▶ resolve => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
309 97 my ($field, $args) = @_;
310 97 ▶ my $field_args = $field->{args} || {};
Condition100%2/2
$field->{'args'} || {}
l!l
1879
MC/DC100%1/1
$field->{'args'} || {}
$field->{'args'}
Truth table100%2/2
A
A= $field->{'args'}
Aresult
11
00
311 97 ▶ if (!$args->{includeDeprecated}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args->{"includeDeprecated"}) 2 95 97
312 2 $field_args = { map { ($_ => $field_args->{$_}) }
313 2 grep { !$field_args->{$_}{is_deprecated} } keys %$field_args };
314 }
315 97 return _hash2array($field_args);
316 },
317 },
318 50 type => { type => $TYPE_META_TYPE->non_null },
319 _make_hash_bool_field(isDeprecated => $Boolean->non_null, 'isDeprecated'),
320 _make_hash_field(deprecationReason => $String, 'deprecationReason'),
321 } },
322 62 );
323  
324 our $DIRECTIVE_META_TYPE = GraphQL::Houtou::Type::Object->new(
325 name => '__Directive',
326 is_introspection => 1,
327 description =>
328 'A Directive provides a way to describe alternate runtime execution and ' .
329 'type validation behavior in a GraphQL document.' .
330 "\n\nIn some cases, you need to provide options to alter GraphQL's " .
331 'execution behavior in ways field arguments will not suffice, such as ' .
332 'conditionally including or skipping a field. Directives provide this by ' .
333 'describing additional information to the executor.',
334 fields => {
335 _make_moo_field(name => $String->non_null),
336 _make_moo_field(description => $String),
337 isRepeatable => {
338 type => $Boolean->non_null,
339 33 ▶ resolve => sub { $_[0]->can('repeatable') ? !!$_[0]->repeatable : 0 },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->can('repeatable') ? : 33 0 33
340 },
341 _make_moo_field(locations => $DIRECTIVE_LOCATION_META_TYPE->non_null->list->non_null),
342 args => {
343 type => $INPUT_VALUE_META_TYPE->non_null->list->non_null,
344 args => { includeDeprecated => { type => $Boolean, default_value => 0 } },
345 23 ▶ resolve => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
346 23 my ($directive, $args) = @_;
347 23 ▶ my $directive_args = $directive->args || {};
Condition50%1/2
$directive->args || {}
l!l
230
MC/DC0%0/1
$directive->args || {}
$directive->args
Truth table50%1/2
A
A= $directive->args
Aresult
11
00
348 23 ▶ if (!$args->{includeDeprecated}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args->{"includeDeprecated"}) 6 17 23
349 5 $directive_args = { map { ($_ => $directive_args->{$_}) }
350 6 grep { !$directive_args->{$_}{is_deprecated} } keys %$directive_args };
351 }
352 23 return _hash2array($directive_args);
353 },
354 },
355 },
356 62 );
357  
358 $TYPE_META_TYPE = GraphQL::Houtou::Type::Object->new(
359 name => '__Type',
360 is_introspection => 1,
361 description =>
362 'The fundamental unit of any GraphQL Schema is the type. There are ' .
363 'many kinds of types in GraphQL as represented by the `__TypeKind` enum.' .
364 "\n\nDepending on the kind of a type, certain fields describe " .
365 'information about that type. Scalar types provide no information ' .
366 'beyond a name and description, while Enum types provide their values. ' .
367 'Object and Interface types provide the fields they describe. Abstract ' .
368 'types, Union and Interface, provide the Object types possible ' .
369 'at runtime. List and NonNull types compose other types.',
370 50 ▶ fields => sub { {
Subroutine __ANON__: called CC=1 SCAR=0.0
371 kind => {
372 type => $TYPE_KIND_META_TYPE->non_null,
373 235 ▶ resolve => sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
374 235 my $class = ref $_[0];
375 235 $class =~ s#__.*##;
376 235 ▶ return CLASS2KIND->{$class} // die "Unknown kind of type => " . ref $_[0];
Condition50%1/2
{"GraphQL::Houtou::Type::Enum" => "ENUM","GraphQL::Houtou::Type::InputObject" => "INPUT_OBJECT","GraphQL::Houtou::Type::Interface" => "INTERFACE","GraphQL::Houtou::Type::List" => "LIST","GraphQL::Houtou::Type::NonNull" => "NON_NULL","GraphQL::Houtou::Type::Object" => "OBJECT","GraphQL::Houtou::Type::Scalar" => "SCALAR","GraphQL::Houtou::Type::Union" => "UNION","GraphQL::Type::Enum" => "ENUM","GraphQL::Type::InputObject" => "INPUT_OBJECT","GraphQL::Type::Interface" => "INTERFACE","GraphQL::Type::List" => "LIST","GraphQL::Type::NonNull" => "NON_NULL","GraphQL::Type::Object" => "OBJECT","GraphQL::Type::Scalar" => "SCALAR","GraphQL::Type::Union" => "UNION"}->{$class} // die('Unknown kind of type => ' . ref($_[0]))
l!l
2350
MC/DC0%0/1
{"GraphQL::Houtou::Type::Enum" => "ENUM","GraphQL::Houtou::Type::InputObject" => "INPUT_OBJECT","GraphQL::Houtou::Type::Interface" => "INTERFACE","GraphQL::Houtou::Type::List" => "LIST","GraphQL::Houtou::Type::NonNull" => "NON_NULL","GraphQL::Houtou::Type::Object" => "OBJECT","GraphQL::Houtou::Type::Scalar" => "SCALAR","GraphQL::Houtou::Type::Union" => "UNION","GraphQL::Type::Enum" => "ENUM","GraphQL::Type::InputObject" => "INPUT_OBJECT","GraphQL::Type::Interface" => "INTERFACE","GraphQL::Type::List" => "LIST","GraphQL::Type::NonNull" => "NON_NULL","GraphQL::Type::Object" => "OBJECT","GraphQL::Type::Scalar" => "SCALAR","GraphQL::Type::Union" => "UNION"}->{$class} // die('Unknown kind of type => ' . ref($_[0]))
{"GraphQL::Houtou::Type::Enum" => "ENUM","GraphQL::Houtou::Type::InputObject" => "INPUT_OBJECT","GraphQL::Houtou::Type::Interface" => "INTERFACE","GraphQL::Houtou::Type::List" => "LIST","GraphQL::Houtou::Type::NonNull" => "NON_NULL","GraphQL::Houtou::Type::Object" => "OBJECT","GraphQL::Houtou::Type::Scalar" => "SCALAR","GraphQL::Houtou::Type::Union" => "UNION","GraphQL::Type::Enum" => "ENUM","GraphQL::Type::InputObject" => "INPUT_OBJECT","GraphQL::Type::Interface" => "INTERFACE","GraphQL::Type::List" => "LIST","GraphQL::Type::NonNull" => "NON_NULL","GraphQL::Type::Object" => "OBJECT","GraphQL::Type::Scalar" => "SCALAR","GraphQL::Type::Union" => "UNION"}->{$class}
Truth table50%1/2
A
A= {"GraphQL::Houtou::Type::Enum" => "ENUM","GraphQL::Houtou::Type::InputObject" => "INPUT_OBJECT","GraphQL::Houtou::Type::Interface" => "INTERFACE","GraphQL::Houtou::Type::List" => "LIST","GraphQL::Houtou::Type::NonNull" => "NON_NULL","GraphQL::Houtou::Type::Object" => "OBJECT","GraphQL::Houtou::Type::Scalar" => "SCALAR","GraphQL::Houtou::Type::Union" => "UNION","GraphQL::Type::Enum" => "ENUM","GraphQL::Type::InputObject" => "INPUT_OBJECT","GraphQL::Type::Interface" => "INTERFACE","GraphQL::Type::List" => "LIST","GraphQL::Type::NonNull" => "NON_NULL","GraphQL::Type::Object" => "OBJECT","GraphQL::Type::Scalar" => "SCALAR","GraphQL::Type::Union" => "UNION"}->{$class}
Aresult
11
00
377 },
378 },
379 name => {
380 245 ▶ resolve => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
381 245 my ($root_value, $args) = @_;
382 245 ▶ return undef if $root_value->can('of');
Branch: 1 branch
BranchTrueFalseTotal
if $root_value->can("of") 83 162 245
383 162 ▶ my @passon = %$args ? ($args) : ();
Branch: 1 branch
BranchTrueFalseTotal
%$args ? : 0 162 162
384 162 return $root_value->name(@passon);
385 },
386 type => $String,
387 },
388 _make_moo_field(description => $String),
389 fields => {
390 type => $FIELD_META_TYPE->non_null->list,
391 args => { includeDeprecated => { type => $Boolean, default_value => 0 } },
392 38 ▶ resolve => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
393 38 my ($type, $args) = @_;
394 38 my $map;
395 38 ▶ return undef if !_does_any($type,
Branch: 1 branch
BranchTrueFalseTotal
unless _does_any($type, "GraphQL::Houtou::Role::FieldsOutput", "GraphQL::Role::FieldsOutput") 18 20 38
396 'GraphQL::Houtou::Role::FieldsOutput',
397 'GraphQL::Role::FieldsOutput',
398 );
399 20 $map = $type->fields;
400 20 ▶ if (!$args->{includeDeprecated}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args->{"includeDeprecated"}) 5 15 20
401 5 $map = { map { ($_ => $map->{$_}) } grep { !$map->{$_}{deprecation_reason} } keys %$map };
402 }
403 return [
404 map {
405 20 +{
406 name => $_,
407 description => $map->{$_}{description},
408 args => $map->{$_}{args},
409 type => $map->{$_}{type},
410 isDeprecated => $map->{$_}{is_deprecated},
411 deprecationReason => $map->{$_}{deprecation_reason},
412 }
413 112 } sort keys %$map
414 ];
415 },
416 },
417 interfaces => {
418 type => $TYPE_META_TYPE->non_null->list,
419 34 ▶ resolve => sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
420 34 my ($type) = @_;
421 34 ▶ return if !_isa_any($type, 'GraphQL::Houtou::Type::Object', 'GraphQL::Type::Object');
Branch: 1 branch
BranchTrueFalseTotal
unless _isa_any($type, "GraphQL::Houtou::Type::Object", "GraphQL::Type::Object") 18 16 34
422 16 ▶ return $type->interfaces || [];
Condition50%1/2
$type->interfaces || []
l!l
160
MC/DC0%0/1
$type->interfaces || []
$type->interfaces
Truth table50%1/2
A
A= $type->interfaces
Aresult
11
00
423 },
424 },
425 possibleTypes => {
426 type => $TYPE_META_TYPE->non_null->list,
427 33 ▶ resolve => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
428 33 ▶ return if !_does_any($_[0], 'GraphQL::Houtou::Role::Abstract', 'GraphQL::Role::Abstract');
Branch: 1 branch
BranchTrueFalseTotal
unless _does_any($_[0], "GraphQL::Houtou::Role::Abstract", "GraphQL::Role::Abstract") 32 1 33
429 1 return $_[3]->{schema}->get_possible_types($_[0]);
430 },
431 },
432 enumValues => {
433 type => $ENUM_VALUE_META_TYPE->non_null->list,
434 args => { includeDeprecated => { type => $Boolean, default_value => 0 } },
435 34 ▶ resolve => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
436 34 my ($type, $args) = @_;
437 34 my $values;
438 34 ▶ return if !_isa_any($type, 'GraphQL::Houtou::Type::Enum', 'GraphQL::Type::Enum');
Branch: 1 branch
BranchTrueFalseTotal
unless _isa_any($type, "GraphQL::Houtou::Type::Enum", "GraphQL::Type::Enum") 29 5 34
439 5 $values = $type->values;
440 5 ▶ if (!$args->{includeDeprecated}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args->{"includeDeprecated"}) 1 4 5
441 1 $values = { map { ($_ => $values->{$_}) } grep { !$values->{$_}{is_deprecated} } keys %$values };
442 }
443 return [
444 map {
445 5 +{
446 name => $_,
447 description => $values->{$_}{description},
448 isDeprecated => $values->{$_}{is_deprecated},
449 deprecationReason => $values->{$_}{deprecation_reason},
450 }
451 55 } sort keys %$values
452 ];
453 },
454 },
455 inputFields => {
456 type => $INPUT_VALUE_META_TYPE->non_null->list,
457 args => { includeDeprecated => { type => $Boolean, default_value => 0 } },
458 36 ▶ resolve => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
459 36 my ($type, $args) = @_;
460 36 ▶ return if !_isa_any($type, 'GraphQL::Houtou::Type::InputObject', 'GraphQL::Type::InputObject');
Branch: 1 branch
BranchTrueFalseTotal
unless _isa_any($type, "GraphQL::Houtou::Type::InputObject", "GraphQL::Type::InputObject") 31 5 36
461 5 ▶ my $fields = $type->fields || {};
Condition50%1/2
$type->fields || {}
l!l
50
MC/DC0%0/1
$type->fields || {}
$type->fields
Truth table50%1/2
A
A= $type->fields
Aresult
11
00
462 5 ▶ if (!$args->{includeDeprecated}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args->{"includeDeprecated"}) 1 4 5
463 1 $fields = { map { ($_ => $fields->{$_}) }
464 1 grep { !$fields->{$_}{is_deprecated} } keys %$fields };
465 }
466 5 return _hash2array($fields);
467 },
468 },
469 ofType => {
470 type => $TYPE_META_TYPE,
471 201 ▶ resolve => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
472 201 ▶ return unless $_[0]->can('of');
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->can("of") 118 83 201
473 83 return $_[0]->of;
474 },
475 },
476 specifiedByURL => {
477 type => $String,
478 36 ▶ resolve => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
479 36 ▶ return unless $_[0]->can('specified_by_url');
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->can("specified_by_url") 22 14 36
480 14 return $_[0]->specified_by_url;
481 },
482 },
483 isOneOf => {
484 type => $Boolean,
485 38 ▶ resolve => sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
486 38 ▶ return if !_isa_any($_[0], 'GraphQL::Houtou::Type::InputObject', 'GraphQL::Type::InputObject');
Branch: 1 branch
BranchTrueFalseTotal
unless _isa_any($_[0], "GraphQL::Houtou::Type::InputObject", "GraphQL::Type::InputObject") 32 6 38
487 6 ▶ return $_[0]->can('is_one_of') ? !!$_[0]->is_one_of : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->can('is_one_of') ? : 6 0 6
488 },
489 },
490 50 } },
491 62 );
492  
493 our $SCHEMA_META_TYPE = GraphQL::Houtou::Type::Object->new(
494 name => '__Schema',
495 is_introspection => 1,
496 description =>
497 'A GraphQL Schema defines the capabilities of a GraphQL server. It ' .
498 'exposes all available types and directives on the server, as well as ' .
499 'the entry points for query, mutation, and subscription operations.',
500 fields => {
501 _make_moo_field(description => $String),
502 types => {
503 description => 'A list of all types supported by this server.',
504 type => $TYPE_META_TYPE->non_null->list->non_null,
505 2 ▶ resolve => sub { [ sort { $a->name cmp $b->name } values %{ $_[0]->name2type } ] },
Subroutine __ANON__: called CC=1 SCAR=0.0
506 },
507 queryType => {
508 description => 'The type that query operations will be rooted at.',
509 type => $TYPE_META_TYPE->non_null,
510 6 ▶ resolve => sub { $_[0]->query },
Subroutine __ANON__: called CC=1 SCAR=0.0
511 },
512 mutationType => {
513 description => 'If this server supports mutation, the type that mutation operations will be rooted at.',
514 type => $TYPE_META_TYPE,
515 2 ▶ resolve => sub { $_[0]->mutation },
Subroutine __ANON__: called CC=1 SCAR=0.0
516 },
517 subscriptionType => {
518 description => 'If this server support subscription, the type that subscription operations will be rooted at.',
519 type => $TYPE_META_TYPE,
520 2 ▶ resolve => sub { $_[0]->subscription },
Subroutine __ANON__: called CC=1 SCAR=0.0
521 },
522 directives => {
523 description => 'A list of all directives supported by this server.',
524 type => $DIRECTIVE_META_TYPE->non_null->list->non_null,
525 8 ▶ resolve => sub { $_[0]->directives },
Subroutine __ANON__: called CC=1 SCAR=0.0
526 },
527 },
528 62 );
529  
530 our $SCHEMA_META_FIELD_DEF = {
531 name => '__schema',
532 type => $SCHEMA_META_TYPE->non_null,
533 description => 'Access the current type schema of this server.',
534 13 ▶ resolve => sub { $_[3]->{schema} },
Subroutine __ANON__: called CC=1 SCAR=0.0
535 62 };
536  
537 our $TYPE_META_FIELD_DEF = {
538 name => '__type',
539 type => $TYPE_META_TYPE,
540 description => 'Request the type information of a single type.',
541 args => { name => { type => $String->non_null } },
542 21 ▶ resolve => sub { $_[3]->{schema}->name2type->{ $_[1]->{name} } },
Subroutine __ANON__: called CC=1 SCAR=0.0
543 62 };
544  
545 our $TYPE_NAME_META_FIELD_DEF = {
546 name => '__typename',
547 type => $String->non_null,
548 description => 'The name of the current Object type at runtime.',
549 0 ▶ resolve => sub { $_[3]->{parent_type}->name },
Subroutine __ANON__: not called CC=1 SCAR=6.9
550 62 };
551  
552 62 1;
553  
554 __END__
« blib/lib/GraphQL/Houtou/Type.pm ↑ Summary blib/lib/GraphQL/Houtou/Runtime/SchemaBlock.pm »