blib/lib/GraphQL/Houtou/Federation.pm

filter: Statementstmt 97.0% 166 / 171 Branchbran 67.3% 62 / 92 Conditioncond 48.8% 44 / 90 MC/DCmcdc 16.3% 8 / 49 Subroutinesub 95.8% 23 / 24 Podpod 0.0% 0 / 1 totaltotal 70.9% 303 / 427 CC 89 SCAR 28.5
CC
89
Cov
77%
_validate_fieldset_selections
33.1
_subgraph_shape
28.6
build_subgraph_schema
21.7
CRAP 17.4
« blib/lib/GraphQL/Houtou/Runtime/SchemaGraph.pm ↑ Summary blib/lib/GraphQL/Houtou/Role/HashMappable.pm »
1 package GraphQL::Houtou::Federation;
2  
3 1 ▶use 5.024;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use GraphQL::Houtou ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use GraphQL::Houtou::Async::Adapter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use GraphQL::Houtou::Promise::PromiseXS qw(is_promise_xs_value);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use GraphQL::Houtou::Schema ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 our $VERSION = $GraphQL::Houtou::VERSION;
14 1 our @EXPORT_OK = qw(build_subgraph_schema);
15  
16 1 my $FEDERATION_SDL = <<'SDL';
17 scalar _Any
18 scalar federation__FieldSet
19 scalar federation__Scope
20 scalar federation__Policy
21 scalar federation__ContextFieldValue
22 scalar link__Import
23  
24 enum link__Purpose {
25 SECURITY
26 EXECUTION
27 }
28  
29 directive @link(
30 url: String!
31 as: String
32 for: link__Purpose
33 import: [link__Import]
34 ) repeatable on SCHEMA
35 directive @key(fields: federation__FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE
36 directive @external on FIELD_DEFINITION | OBJECT
37 directive @requires(fields: federation__FieldSet!) on FIELD_DEFINITION
38 directive @provides(fields: federation__FieldSet!) on FIELD_DEFINITION
39 directive @shareable repeatable on OBJECT | FIELD_DEFINITION
40 directive @inaccessible on FIELD_DEFINITION | OBJECT | INTERFACE | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
41 directive @tag(name: String!) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
42 directive @override(from: String!) on FIELD_DEFINITION
43 directive @composeDirective(name: String!) repeatable on SCHEMA
44 directive @interfaceObject on OBJECT
45 directive @authenticated on FIELD_DEFINITION | OBJECT | INTERFACE | SCALAR | ENUM
46 directive @requiresScopes(scopes: [[federation__Scope!]!]!) on FIELD_DEFINITION | OBJECT | INTERFACE | SCALAR | ENUM
47 directive @policy(policies: [[federation__Policy!]!]!) on FIELD_DEFINITION | OBJECT | INTERFACE | SCALAR | ENUM
48 directive @context(name: String!) repeatable on INTERFACE | OBJECT | UNION
49 directive @fromContext(field: federation__ContextFieldValue) on ARGUMENT_DEFINITION
50  
51 type _Service {
52 sdl: String!
53 }
54 SDL
55  
56 8 ▶sub build_subgraph_schema {
Subroutine build_subgraph_schema: called CC=20 SCAR=30.8
Pod undocumented
57 8 my ($document, %opts) = @_;
58 8 ▶ die "build_subgraph_schema requires an SDL document\n"
Branch: 1 branch
BranchTrueFalseTotal
if not defined $document or ref $document or not $document =~ /\S/u 0 8 8
Condition33%2/6
not defined $document or ref $document or not $document =~ /\S/u
l!l&&r!l&&!r
008
not defined $document or ref $document
l!l&&r!l&&!r
008
MC/DC0%0/3
not defined $document or ref $document or not $document =~ /\S/u
not defined $document ref $document not $document =~ /\S/u
Truth table25%1/4
not(A) or B or not(C)
A= not defined $documentB= ref $documentC= not $document =~ /\S/u
ABCresult
1XX1
01X1
0011
0000
59 if !defined($document) || ref($document) || $document !~ /\S/;
60  
61 8 ▶ my $entity_resolvers = delete($opts{entity_resolvers}) || {};
Condition100%2/2
delete $opts{'entity_resolvers'} || {}
l!l
62
MC/DC100%1/1
delete $opts{'entity_resolvers'} || {}
delete $opts{'entity_resolvers'}
Truth table100%2/2
A
A= delete $opts{'entity_resolvers'}
Aresult
11
00
62 8 my $has_async_adapter = exists $opts{async_adapter};
63 my $async_adapter = GraphQL::Houtou::Async::Adapter->coerce(
64 delete $opts{async_adapter},
65 8 );
66 8 my $builtin_async = $async_adapter->is_builtin;
67 my $max_representations = exists($opts{max_representations})
68 8 ▶ ? delete($opts{max_representations}) : 100;
Branch: 1 branch
BranchTrueFalseTotal
exists $opts{'max_representations'} ? : 1 7 8
69 8 ▶ die "max_representations must be a positive integer\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $max_representations and $max_representations =~ /\A[1-9][0-9]*\z/u 0 8 8
Condition33%1/3
defined $max_representations and $max_representations =~ /\A[1-9][0-9]*\z/u
!ll&&!rl&&r
008
MC/DC0%0/2
defined $max_representations and $max_representations =~ /\A[1-9][0-9]*\z/u
defined $max_representations $max_representations =~ /\A[1-9][0-9]*\z/u
Truth table33%1/3
A and B
A= defined $max_representationsB= $max_representations =~ /\A[1-9][0-9]*\z/u
ABresult
0X0
100
111
70 if !defined($max_representations)
71 || $max_representations !~ /\A[1-9][0-9]*\z/;
72 8 ▶ die "entity_resolvers must be a hash reference\n"
Branch: 1 branch
BranchTrueFalseTotal
if ref $entity_resolvers ne "HASH" 0 8 8
73 if ref($entity_resolvers) ne 'HASH';
74  
75 8 my $ast = GraphQL::Houtou::parse($document);
76 8 my ($query_name, $entities) = _subgraph_shape($ast);
77 8 my @entity_names = sort keys %$entities;
78  
79 8 my $entity_sdl = '';
80 8 ▶ if (@entity_names) {
Branch: 1 branch
BranchTrueFalseTotal
if (@entity_names) 7 1 8
81 7 $entity_sdl .= "union _Entity = " . join(' | ', @entity_names) . "\n\n";
82 }
83 8 $entity_sdl .= "extend type $query_name {\n _service: _Service!\n";
84 8 ▶ $entity_sdl .= " _entities(representations: [_Any!]!): [_Entity]!\n"
Branch: 1 branch
BranchTrueFalseTotal
if @entity_names 7 1 8
85 if @entity_names;
86 8 $entity_sdl .= "}\n";
87  
88 8 ▶ my $user_resolvers = delete($opts{resolvers}) || {};
Condition100%2/2
delete $opts{'resolvers'} || {}
l!l
26
MC/DC100%1/1
delete $opts{'resolvers'} || {}
delete $opts{'resolvers'}
Truth table100%2/2
A
A= delete $opts{'resolvers'}
Aresult
11
00
89 8 ▶ die "resolvers must be a hash reference\n"
Branch: 1 branch
BranchTrueFalseTotal
if ref $user_resolvers ne "HASH" 0 8 8
90 if ref($user_resolvers) ne 'HASH';
91 my %resolvers = map {
92 8 my $spec = $user_resolvers->{$_};
93 2 ▶ ($_ => ref($spec) eq 'HASH' ? { %$spec } : $spec)
Branch: 1 branch
BranchTrueFalseTotal
ref $spec eq 'HASH' ? : 2 0 2
94 } keys %$user_resolvers;
95 _reserve_resolver(
96 \%resolvers, '_Any', 'parse_value',
97 9 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
98 9 my ($value) = @_;
99 9 ▶ die "Federation representation must be an object\n"
Branch: 1 branch
BranchTrueFalseTotal
if ref $value ne "HASH" 0 9 9
100 if ref($value) ne 'HASH';
101 9 return $value;
102 },
103 8 );
104 0 ▶ _reserve_resolver(\%resolvers, '_Any', 'serialize', sub { $_[0] });
Subroutine __ANON__: not called CC=1 SCAR=1.2
105 _reserve_resolver(
106 2 ▶ \%resolvers, '_Service', 'sdl', sub { return $document },
Subroutine __ANON__: called CC=1 SCAR=0.0
107 8 );
108 _reserve_resolver(
109 2 ▶ \%resolvers, $query_name, '_service', sub { return {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
110 8 );
111  
112 8 ▶ if (@entity_names) {
Branch: 1 branch
BranchTrueFalseTotal
if (@entity_names) 7 1 8
113 7 for my $name (@entity_names) {
114 die "Missing entity resolver for '$name'\n"
115 7 ▶ if ref($entity_resolvers->{$name}) ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $entity_resolvers->{$name} ne "CODE" 1 6 7
116 }
117 6 for my $name (sort keys %$entity_resolvers) {
118 die "Entity resolver provided for non-entity type '$name'\n"
119 6 ▶ if !$entities->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless $entities->{$name} 0 6 6
120 }
121 _reserve_resolver(
122 \%resolvers, '_Entity', 'resolve_type',
123 4 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
124 4 my ($value) = @_;
125 4 ▶ return ref($value) eq 'HASH' ? $value->{__typename} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'HASH' ? : 4 0 4
126 },
127 6 );
128 _reserve_resolver(
129 \%resolvers, $query_name, '_entities',
130 6 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
131 6 my (undef, $args, $context) = @_;
132 6 my $representations = $args->{representations};
133 6 ▶ die "Federation representations must be an array\n"
Branch: 1 branch
BranchTrueFalseTotal
if ref $representations ne "ARRAY" 0 6 6
134 if ref($representations) ne 'ARRAY';
135 6 ▶ die "Federation representations exceed max_representations ($max_representations)\n"
Branch: 1 branch
BranchTrueFalseTotal
if @$representations > $max_representations 1 5 6
136 if @$representations > $max_representations;
137 return [ map {
138 5 _resolve_representation(
139 $_, $context, $entities, $entity_resolvers,
140 $async_adapter, $builtin_async,
141 )
142 } @$representations ];
143 },
144 6 );
145 }
146  
147 7 my $schema = GraphQL::Houtou::Schema->from_doc(
148 "$FEDERATION_SDL\n$document\n$entity_sdl",
149 %opts,
150 resolvers => \%resolvers,
151 );
152 7 $entities = _validate_entity_keys($schema, $entities);
153 5 $schema->{_federation_subgraph_sdl} = $document;
154 5 $schema->{_federation_max_representations} = 0 + $max_representations;
155 5 ▶ $schema->{_default_async_adapter} = $async_adapter if $has_async_adapter;
Branch: 1 branch
BranchTrueFalseTotal
if $has_async_adapter 1 4 5
156 5 return $schema;
157 }
158  
159 44 ▶sub _reserve_resolver {
Subroutine _reserve_resolver: called CC=5 SCAR=16.7
160 44 my ($resolvers, $type, $field, $callback) = @_;
161 44 my $spec = $resolvers->{$type};
162 44 ▶ die "Resolvers for '$type' must be a hash reference\n"
Branch: 1 branch
BranchTrueFalseTotal
if defined $spec and ref $spec ne "HASH" 0 44 44
Condition66%2/3
defined $spec and ref $spec ne "HASH"
!ll&&!rl&&r
28160
MC/DC0%0/2
defined $spec and ref $spec ne "HASH"
defined $spec ref $spec ne "HASH"
Truth table66%2/3
A and B
A= defined $specB= ref $spec ne "HASH"
ABresult
0X0
100
111
163 if defined($spec) && ref($spec) ne 'HASH';
164 44 ▶ $spec ||= ($resolvers->{$type} = {});
Condition66%2/3
$spec ||= ($resolvers->{$type} = {})
l!l&&r!l&&!r
16280
MC/DC0%0/2
$spec ||= ($resolvers->{$type} = {})
$spec ($resolvers->{$type} = {})
Truth table66%2/3
A ||= B
A= $specB= ($resolvers->{$type} = {})
ABresult
1X1
011
000
165 die "Resolver '$type.$field' is reserved by Federation\n"
166 44 ▶ if exists $spec->{$field};
Branch: 1 branch
BranchTrueFalseTotal
if exists $spec->{$field} 0 44 44
167 44 $spec->{$field} = $callback;
168 44 return;
169 }
170  
171 8 ▶sub _subgraph_shape {
Subroutine _subgraph_shape: called CC=19 SCAR=33.5
172 8 my ($ast) = @_;
173 8 my $query_name = 'Query';
174 8 my %types;
175 my %entities;
176 8 for my $node (@$ast) {
177 21 ▶ my $kind = $node->{kind} || '';
Condition50%1/2
$node->{'kind'} || ''
l!l
210
MC/DC0%0/1
$node->{'kind'} || ''
$node->{'kind'}
Truth table50%1/2
A
A= $node->{'kind'}
Aresult
11
00
178 $query_name = $node->{query}
179 21 ▶ if $kind eq 'schema' && defined $node->{query};
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "schema" and defined $node->{"query"} 0 21 21
Condition66%2/3
$kind eq "schema" and defined $node->{"query"}
!ll&&!rl&&r
1650
MC/DC0%0/2
$kind eq "schema" and defined $node->{"query"}
$kind eq "schema" defined $node->{"query"}
Truth table66%2/3
A and B
A= $kind eq "schema"B= defined $node->{"query"}
ABresult
0X0
100
111
180 21 ▶ next if $kind ne 'type' && $kind ne 'interface';
Branch: 1 branch
BranchTrueFalseTotal
if $kind ne "type" and $kind ne "interface" 5 16 21
Condition66%2/3
$kind ne "type" and $kind ne "interface"
!ll&&!rl&&r
1605
MC/DC50%1/2
$kind ne "type" and $kind ne "interface"
$kind ne "type" $kind ne "interface"
Truth table66%2/3
A and B
A= $kind ne "type"B= $kind ne "interface"
ABresult
0X0
100
111
181 16 ▶ $types{ $node->{name} } = 1 if !$node->{extension};
Branch: 1 branch
BranchTrueFalseTotal
unless $node->{"extension"} 16 0 16
182 16 ▶ next if $kind ne 'type';
Branch: 1 branch
BranchTrueFalseTotal
if $kind ne "type" 0 16 16
183 16 ▶ for my $directive (@{ $node->{directives} || [] }) {
Condition100%2/2
$node->{'directives'} || []
l!l
79
MC/DC100%1/1
$node->{'directives'} || []
$node->{'directives'}
Truth table100%2/2
A
A= $node->{'directives'}
Aresult
11
00
184 7 ▶ next if ($directive->{name} || '') ne 'key';
Branch: 1 branch
BranchTrueFalseTotal
if ($directive->{"name"} || "") ne "key" 0 7 7
Condition50%1/2
$directive->{'name'} || ''
l!l
70
MC/DC0%0/1
$directive->{'name'} || ''
$directive->{'name'}
Truth table50%1/2
A
A= $directive->{'name'}
Aresult
11
00
185 7 my $resolvable = $directive->{arguments}{resolvable};
186 7 ▶ next if defined($resolvable) && !$resolvable;
Branch: 1 branch
BranchTrueFalseTotal
if defined $resolvable and not $resolvable 0 7 7
Condition33%1/3
defined $resolvable and not $resolvable
!ll&&!rl&&r
700
MC/DC0%0/2
defined $resolvable and not $resolvable
defined $resolvable not $resolvable
Truth table33%1/3
A and not(B)
A= defined $resolvableB= not $resolvable
ABresult
0X0
100
111
187 7 my $fields = $directive->{arguments}{fields};
188 7 ▶ die "Federation \@key on '$node->{name}' requires a string fields argument\n"
Branch: 1 branch
BranchTrueFalseTotal
if not defined $fields or ref $fields or $fields eq "" 0 7 7
Condition33%2/6
not defined $fields or ref $fields or $fields eq ""
l!l&&r!l&&!r
007
not defined $fields or ref $fields
l!l&&r!l&&!r
007
MC/DC0%0/3
not defined $fields or ref $fields or $fields eq ""
not defined $fields ref $fields $fields eq ""
Truth table25%1/4
not(A) or B or C
A= not defined $fieldsB= ref $fieldsC= $fields eq ""
ABCresult
1XX1
01X1
0011
0000
189 if !defined($fields) || ref($fields) || $fields eq '';
190 7 push @{ $entities{ $node->{name} } }, $fields;
191 }
192 }
193 die "Federation query root type '$query_name' is not defined\n"
194 8 ▶ if !$types{$query_name};
Branch: 1 branch
BranchTrueFalseTotal
unless $types{$query_name} 0 8 8
195 8 return ($query_name, \%entities);
196 }
197  
198 7 ▶sub _validate_entity_keys {
Subroutine _validate_entity_keys: called CC=8 SCAR=24.1
199 7 my ($schema, $entities) = @_;
200 7 my $name2type = $schema->name2type;
201 7 my %compiled;
202 7 for my $entity_name (sort keys %$entities) {
203 6 my $entity_type = $name2type->{$entity_name};
204 6 for my $fieldset (@{ $entities->{$entity_name} }) {
205 6 my $document = eval { GraphQL::Houtou::parse("{ $fieldset }") };
206 6 my $error = $@;
207 6 ▶ if ($error || ref($document) ne 'ARRAY' || @$document != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error or ref $document ne "ARRAY" or @$document != 1) 0 6 6
Condition33%2/6
$error or ref $document ne "ARRAY" or @$document != 1
l!l&&r!l&&!r
006
$error or ref $document ne "ARRAY"
l!l&&r!l&&!r
006
MC/DC0%0/3
$error or ref $document ne "ARRAY" or @$document != 1
$error ref $document ne "ARRAY" @$document != 1
Truth table25%1/4
A or B or C
A= $errorB= ref $document ne "ARRAY"C= @$document != 1
ABCresult
1XX1
01X1
0011
0000
208 0 ▶ $error ||= 'invalid FieldSet';
Condition0%0/2
$error ||= "invalid FieldSet"
l!l
00
MC/DC0%0/1
$error ||= "invalid FieldSet"
$error
Truth table0%0/2
A
A= $error
Aresult
11
00
209 0 $error =~ s/\s+\z//;
210 0 die "Invalid \@key FieldSet on '$entity_name': $error\n";
211 }
212 _validate_fieldset_selections(
213 6 ▶ $entity_name, $entity_type, $document->[0]{selections} || [],
Condition50%1/2
$document->[0]{'selections'} || []
l!l
60
MC/DC0%0/1
$document->[0]{'selections'} || []
$document->[0]{'selections'}
Truth table50%1/2
A
A= $document->[0]{'selections'}
Aresult
11
00
214 );
215 4 push @{ $compiled{$entity_name} }, $document->[0]{selections};
216 }
217 }
218 5 return \%compiled;
219 }
220  
221 6 ▶sub _validate_fieldset_selections {
Subroutine _validate_fieldset_selections: called CC=19 SCAR=35.0
222 6 my ($coordinate, $type, $selections) = @_;
223 6 ▶ die "Invalid \@key FieldSet on '$coordinate': fields must not be empty\n"
Branch: 1 branch
BranchTrueFalseTotal
if ref $selections ne "ARRAY" or not @$selections 0 6 6
Condition33%1/3
ref $selections ne "ARRAY" or not @$selections
l!l&&r!l&&!r
006
MC/DC0%0/2
ref $selections ne "ARRAY" or not @$selections
ref $selections ne "ARRAY" not @$selections
Truth table33%1/3
A or not(B)
A= ref $selections ne "ARRAY"B= not @$selections
ABresult
1X1
011
000
224 if ref($selections) ne 'ARRAY' || !@$selections;
225 6 ▶ my $fields = $type->can('fields') ? $type->fields : undef;
Branch: 1 branch
BranchTrueFalseTotal
$type->can('fields') ? : 6 0 6
226 6 ▶ die "Invalid \@key FieldSet on '$coordinate': type is not composite\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $fields 0 6 6
227 if !$fields;
228 6 for my $selection (@$selections) {
229 die "Invalid \@key FieldSet on '$coordinate': only fields are allowed\n"
230 if ($selection->{kind} || '') ne 'field'
231 || $selection->{alias}
232 6 ▶ || keys %{ $selection->{arguments} || {} }
Condition50%1/2
$selection->{'arguments'} || {}
l!l
06
MC/DC0%0/1
$selection->{'arguments'} || {}
$selection->{'arguments'}
Truth table50%1/2
A
A= $selection->{'arguments'}
Aresult
11
00
233 6 ▶ || @{ $selection->{directives} || [] };
Branch: 1 branch
BranchTrueFalseTotal
if ($selection->{"kind"} || "") ne "field" or $selection->{"alias"} or keys %{$selection->{"arguments"} or {};} or @{$selection->{"directives"} or [];} 0 6 6
Condition38%5/13
($selection->{"kind"} || "") ne "field" or $selection->{"alias"} or keys %{$selection->{"arguments"} or {};} or @{$selection->{"directives"} or [];}
l!l&&r!l&&!r
006
($selection->{"kind"} || "") ne "field" or $selection->{"alias"} or keys %{$selection->{"arguments"} or {};}
l!l&&r!l&&!r
006
($selection->{"kind"} || "") ne "field" or $selection->{"alias"}
l!l&&r!l&&!r
006
$selection->{'kind'} || ''
l!l
60
$selection->{'directives'} || []
l!l
06
MC/DC0%0/4
($selection->{"kind"} || "") ne "field" or $selection->{"alias"} or keys %{$selection->{"arguments"} or {};} or @{$selection->{"directives"} or [];}
$selection->{'kind'} $selection->{"alias"} keys %{$selection->{"arguments"} or {};} @{$selection->{"directives"} or [];}
MC/DC0%0/1
$selection->{'directives'} || []
$selection->{'directives'}
Truth table0%0/5
A or B or C or D
A= $selection->{'kind'}B= $selection->{"alias"}C= keys %{$selection->{"arguments"} or {};}D= @{$selection->{"directives"} or [];}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
Truth table50%1/2
A
A= $selection->{'directives'}
Aresult
11
00
234 6 my $name = $selection->{name};
235 6 ▶ my $field = $fields->{$name}
Branch: 1 branch
BranchTrueFalseTotal
my $field = $fields->{$name} or die "Invalid \@key FieldSet: field '$coordinate.${name}' does not exist\n" 5 1 6
236 or die "Invalid \@key FieldSet: field '$coordinate.$name' does not exist\n";
237 5 my $field_type = $field->{type};
238 5 ▶ $field_type = $field_type->of while ref($field_type) && $field_type->can('of');
Branch: 1 branch
BranchTrueFalseTotal
ref $field_type and $field_type->can("of") and do { $field_type = $field_type->of } 5 5 10
Condition66%2/3
ref $field_type and $field_type->can("of")
!ll&&!rl&&r
055
MC/DC50%1/2
ref $field_type and $field_type->can("of")
ref $field_type $field_type->can("of")
Truth table66%2/3
A and B
A= ref $field_typeB= $field_type->can("of")
ABresult
0X0
100
111
239 5 ▶ my $children = $selection->{selections} || [];
Condition50%1/2
$selection->{'selections'} || []
l!l
05
MC/DC0%0/1
$selection->{'selections'} || []
$selection->{'selections'}
Truth table50%1/2
A
A= $selection->{'selections'}
Aresult
11
00
240 5 ▶ if (@$children) {
Branch: 2 branches
BranchTrueFalseTotal
if (@$children) { } 0 5 5
elsif ($field_type->can('fields')) { } 1 4 5
241 0 _validate_fieldset_selections("$coordinate.$name", $field_type, $children);
242 }
243 elsif ($field_type->can('fields')) {
244 1 die "Invalid \@key FieldSet: composite field '$coordinate.$name' requires a selection\n";
245 }
246 }
247 4 return;
248 }
249  
250 6 ▶sub _resolve_representation {
Subroutine _resolve_representation: called CC=11 SCAR=24.6
251 6 my ($representation, $context, $entities, $entity_resolvers,
252 $async_adapter, $builtin_async) = @_;
253 6 ▶ die "Federation representation must be an object\n"
Branch: 1 branch
BranchTrueFalseTotal
if ref $representation ne "HASH" 0 6 6
254 if ref($representation) ne 'HASH';
255 6 my $typename = $representation->{__typename};
256 6 ▶ die "Federation representation requires a string __typename\n"
Branch: 1 branch
BranchTrueFalseTotal
if not defined $typename or ref $typename or $typename eq "" 0 6 6
Condition33%2/6
not defined $typename or ref $typename or $typename eq ""
l!l&&r!l&&!r
006
not defined $typename or ref $typename
l!l&&r!l&&!r
006
MC/DC0%0/3
not defined $typename or ref $typename or $typename eq ""
not defined $typename ref $typename $typename eq ""
Truth table25%1/4
not(A) or B or C
A= not defined $typenameB= ref $typenameC= $typename eq ""
ABCresult
1XX1
01X1
0011
0000
257 if !defined($typename) || ref($typename) || $typename eq '';
258 die "Unknown Federation entity type '$typename'\n"
259 6 ▶ if !$entities->{$typename};
Branch: 1 branch
BranchTrueFalseTotal
unless $entities->{$typename} 1 5 6
260 die "Federation representation for '$typename' does not satisfy any \@key\n"
261 5 if !grep { _representation_has_fields($representation, $_) }
262 5 ▶ @{ $entities->{$typename} };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {_representation_has_fields($representation, $_);} @{$$entities{$typename};} 1 4 5
263 4 my $value = $entity_resolvers->{$typename}->($representation, $context);
264 4 ▶ if ($builtin_async && is_promise_xs_value($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($builtin_async and is_promise_xs_value($value)) 1 3 4
Condition100%3/3
$builtin_async and is_promise_xs_value($value)
!ll&&!rl&&r
121
MC/DC100%2/2
$builtin_async and is_promise_xs_value($value)
$builtin_async is_promise_xs_value($value)
Truth table100%3/3
A and B
A= $builtin_asyncB= is_promise_xs_value($value)
ABresult
0X0
100
111
265 1 ▶ return $value->then(sub { _tag_entity_result($typename, $_[0]) });
Subroutine __ANON__: called CC=1 SCAR=0.0
266 }
267 3 ▶ if (!$builtin_async && $async_adapter->is_promise($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $builtin_async and $async_adapter->is_promise($value)) 1 2 3
Condition66%2/3
not $builtin_async and $async_adapter->is_promise($value)
!ll&&!rl&&r
201
MC/DC50%1/2
not $builtin_async and $async_adapter->is_promise($value)
not $builtin_async $async_adapter->is_promise($value)
Truth table66%2/3
not(A) and B
A= not $builtin_asyncB= $async_adapter->is_promise($value)
ABresult
0X0
100
111
268 return $async_adapter->then(
269 1 ▶ $value, sub { _tag_entity_result($typename, $_[0]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
270 1 );
271 }
272 2 return _tag_entity_result($typename, $value);
273 }
274  
275 5 ▶sub _representation_has_fields {
Subroutine _representation_has_fields: called CC=7 SCAR=20.7
276 5 my ($representation, $selections) = @_;
277 5 ▶ return 0 if ref($representation) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $representation ne "HASH" 0 5 5
278 5 for my $selection (@$selections) {
279 5 my $name = $selection->{name};
280 5 ▶ return 0 if !exists $representation->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $representation->{$name} 1 4 5
281 4 ▶ my $children = $selection->{selections} || [];
Condition50%1/2
$selection->{'selections'} || []
l!l
04
MC/DC0%0/1
$selection->{'selections'} || []
$selection->{'selections'}
Truth table50%1/2
A
A= $selection->{'selections'}
Aresult
11
00
282 return 0 if @$children
283 4 ▶ && !_representation_has_fields($representation->{$name}, $children);
Branch: 1 branch
BranchTrueFalseTotal
if @$children and not _representation_has_fields($representation->{$name}, $children) 0 4 4
Condition33%1/3
@$children and not _representation_has_fields($representation->{$name}, $children)
!ll&&!rl&&r
400
MC/DC0%0/2
@$children and not _representation_has_fields($representation->{$name}, $children)
@$children not _representation_has_fields($representation->{$name}, $children)
Truth table33%1/3
A and not(B)
A= @$childrenB= not _representation_has_fields($representation->{$name}, $children)
ABresult
0X0
100
111
284 }
285 4 return 1;
286 }
287  
288 4 ▶sub _tag_entity_result {
Subroutine _tag_entity_result: called CC=3 SCAR=11.4
289 4 my ($typename, $value) = @_;
290 4 ▶ return undef if !defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 4 4
291 4 ▶ die "Federation entity resolver for '$typename' must return a hash reference or undef\n"
Branch: 1 branch
BranchTrueFalseTotal
if ref $value ne "HASH" 0 4 4
292 if ref($value) ne 'HASH';
293 4 return { %$value, __typename => $typename };
294 }
295  
296 1 1;
297  
298 __END__
« blib/lib/GraphQL/Houtou/Runtime/SchemaGraph.pm ↑ Summary blib/lib/GraphQL/Houtou/Role/HashMappable.pm »