| 1 | package DBIO::GraphQL::Limits; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Check a GraphQL document for cycles, depth and cost before it runs | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 14 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 14 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 14 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 14 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | # The document is walked before the engine sees it: the engine has no | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # validation of its own, and the relationship fields point at each other, so | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # one document can ask for an unbounded amount of work. Three rules, all | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # checked on the parsed AST before the first SQL: | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # * no fragment cycle (the engine has no NoFragmentCycles rule); | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # * the selection depth after unfolding fragments is at most max_depth; | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # * the cost is at most max_cost: every field costs 1, aliases one by one, | ||||||||||||||||||||||||||||||||||||||||||
| 18 | # and a field that yields rows -- a plural root query with its connection | ||||||||||||||||||||||||||||||||||||||||||
| 19 | # object, a has_many relationship field -- multiplies the cost of what is | ||||||||||||||||||||||||||||||||||||||||||
| 20 | # below it by its page size. | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 235 | ▶ | sub check { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check: called CC=10 SCAR=23.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 235 | my ($class, %a) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 235 | my $ast = $a{ast}; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 235 | my $policy = $a{policy}; | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 235 | my %fragments = map { $_->{name} => $_ } grep { $_->{kind} eq 'fragment' } @$ast; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 235 | _no_fragment_cycles(\%fragments); | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 231 | my @operations = grep { $_->{kind} eq 'operation' } @$ast; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | ▶ | @operations = grep { ($_->{name} // '') eq $a{operation} } @operations | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_->{"name"} // ""
MC/DC0%0/1
$_->{"name"} // ""
$_->{"name"}
Truth table50%1/2
A
A= $_->{"name"}
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 231 | ▶ | if defined $a{operation} && length $a{operation}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $a{"operation"} and length $a{"operation"}
MC/DC50%1/2
defined $a{"operation"} and length $a{"operation"}
defined $a{"operation"}
length $a{"operation"}
Truth table66%2/3
A and B
A= defined $a{"operation"}B= length $a{"operation"}
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 231 | my $schema = $a{schema}; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 231 | my %connection = _connection_types($schema); | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 231 | for my $op (@operations) { | |||||||||||||||||||||||||||||||||||||||||
| 39 | 231 | ▶ | my $type = $schema->${\ ($op->{operationType} || 'query')} or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$op->{'operationType'} || 'query'
MC/DC100%1/1
$op->{'operationType'} || 'query'
$op->{'operationType'}
Truth table100%2/2
A
A= $op->{'operationType'}
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | my $ctx = { | ||||||||||||||||||||||||||||||||||||||||||
| 41 | fragments => \%fragments, | ||||||||||||||||||||||||||||||||||||||||||
| 42 | policy => $policy, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | schema => $schema, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | connection => \%connection, | ||||||||||||||||||||||||||||||||||||||||||
| 45 | variables => $a{variables} || {}, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | op_vars => $op->{variables} || {}, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 230 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition75%3/4
$a{'variables'} || {}
$op->{'variables'} || {}
MC/DC0%0/1
$a{'variables'} || {}
$a{'variables'}
MC/DC100%1/1
$op->{'variables'} || {}
$op->{'variables'}
Truth table50%1/2
A
A= $a{'variables'}
Truth table100%2/2
A
A= $op->{'variables'}
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 230 | ▶ | _cost($ctx, $op->{selections} || [], $type, 0); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$op->{'selections'} || []
MC/DC0%0/1
$op->{'selections'} || []
$op->{'selections'}
Truth table50%1/2
A
A= $op->{'selections'}
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 212 | return; | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | # The connection objects of the plural root queries: the return type of every | ||||||||||||||||||||||||||||||||||||||||||
| 54 | # root field that takes both page and cursor. | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 231 | ▶ | sub _connection_types { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_connection_types: called CC=7 SCAR=20.4
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 231 | my ($schema) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 231 | my %names; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 231 | my $fields = $schema->query->fields; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 231 | for my $def (values %$fields) { | |||||||||||||||||||||||||||||||||||||||||
| 60 | 1050 | ▶ | next unless ref $def->{args} eq 'HASH' && $def->{args}{page} && $def->{args}{cursor}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
ref $def->{"args"} eq "HASH" and $def->{"args"}{"page"} and $def->{"args"}{"cursor"}
ref $def->{"args"} eq "HASH" and $def->{"args"}{"page"}
MC/DC33%1/3
ref $def->{"args"} eq "HASH" and $def->{"args"}{"page"} and $def->{"args"}{"cursor"}
ref $def->{"args"} eq "HASH"
$def->{"args"}{"page"}
$def->{"args"}{"cursor"}
Truth table50%2/4
A and B and C
A= ref $def->{"args"} eq "HASH"B= $def->{"args"}{"page"}C= $def->{"args"}{"cursor"}
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 545 | my $type = _unwrap($def->{type}); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 545 | ▶ | $names{ $type->name } = 1 if $type && $type->can('name'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$type and $type->can("name")
MC/DC0%0/2
$type and $type->can("name")
$type
$type->can("name")
Truth table33%1/3
A and B
A= $typeB= $type->can("name")
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 231 | return %names; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 11675 | ▶ | sub _unwrap { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unwrap: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 11675 | my ($type) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 11675 | ▶ | $type = $type->of while $type && $type->can('of'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type and $type->can("of")
MC/DC50%1/2
$type and $type->can("of")
$type
$type->can("of")
Truth table66%2/3
A and B
A= $typeB= $type->can("of")
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 11675 | return $type; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | # --- fragment cycles ------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 17 | ▶ | sub _spreads { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_spreads: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 17 | my ($selections, $into) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 17 | for my $node (@$selections) { | |||||||||||||||||||||||||||||||||||||||||
| 78 | 21 | ▶ | push @$into, $node->{name} if ($node->{kind} // '') eq 'fragment_spread'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$node->{"kind"} // ""
MC/DC0%0/1
$node->{"kind"} // ""
$node->{"kind"}
Truth table50%1/2
A
A= $node->{"kind"}
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 21 | ▶ | _spreads($node->{selections}, $into) if $node->{selections}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 17 | return $into; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 235 | ▶ | sub _no_fragment_cycles { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_no_fragment_cycles: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 235 | my ($fragments) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 235 | ▶ | my %edges = map { $_ => _spreads($fragments->{$_}{selections} || [], []) } keys %$fragments; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$fragments->{$_}{'selections'} || []
MC/DC0%0/1
$fragments->{$_}{'selections'} || []
$fragments->{$_}{'selections'}
Truth table50%1/2
A
A= $fragments->{$_}{'selections'}
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 235 | my %state; # 1 = on the current path, 2 = done | |||||||||||||||||||||||||||||||||||||||||
| 88 | 15 | ▶ | my $visit; $visit = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 15 | my ($name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 15 | ▶ | return if !$edges{$name} || ($state{$name} // 0) == 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
not $edges{$name} or ($state{$name} // 0) == 2
$state{$name} // 0
MC/DC50%1/2
not $edges{$name} or ($state{$name} // 0) == 2
not $edges{$name}
$state{$name}
Truth table66%2/3
not(A) or B
A= not $edges{$name}B= $state{$name}
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 14 | ▶ | die "DBIO::GraphQL: fragment cycle through '$name'\n" if ($state{$name} // 0) == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$state{$name} // 0
MC/DC100%1/1
$state{$name} // 0
$state{$name}
Truth table100%2/2
A
A= $state{$name}
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 10 | $state{$name} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 10 | $visit->($_) for @{ $edges{$name} }; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 5 | $state{$name} = 2; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 235 | }; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 235 | $visit->($_) for sort keys %edges; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 231 | undef $visit; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 231 | return; | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | # --- depth and cost ---------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | # _cost($ctx, \@selections, $parent_type, $depth) | ||||||||||||||||||||||||||||||||||||||||||
| 104 | # | ||||||||||||||||||||||||||||||||||||||||||
| 105 | # The cost of a selection set, fragments unfolded at every spread. Dies as soon | ||||||||||||||||||||||||||||||||||||||||||
| 106 | # as the depth or the running cost passes its limit, so the walk stays as small | ||||||||||||||||||||||||||||||||||||||||||
| 107 | # as the budget. | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 10739 | ▶ | sub _cost { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cost: called CC=16 SCAR=28.1
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 10739 | my ($ctx, $selections, $type, $depth) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 10739 | my $policy = $ctx->{policy}; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 10739 | my $total = 0; | |||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 10739 | for my $node (@$selections) { | |||||||||||||||||||||||||||||||||||||||||
| 114 | 21147 | ▶ | my $kind = $node->{kind} // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$node->{"kind"} // ""
MC/DC0%0/1
$node->{"kind"} // ""
$node->{"kind"}
Truth table50%1/2
A
A= $node->{"kind"}
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 21147 | ▶ | if ($kind eq 'fragment_spread') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 10006 | ▶ | my $fragment = $ctx->{fragments}{ $node->{name} } or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 10006 | ▶ | $total += _cost($ctx, $fragment->{selections} || [], $type, $depth); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$fragment->{'selections'} || []
MC/DC0%0/1
$fragment->{'selections'} || []
$fragment->{'selections'}
Truth table50%1/2
A
A= $fragment->{'selections'}
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | elsif ($kind eq 'inline_fragment') { | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 3 | ▶ | $total += _cost($ctx, $node->{selections} || [], $type, $depth); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$node->{'selections'} || []
MC/DC0%0/1
$node->{'selections'} || []
$node->{'selections'}
Truth table50%1/2
A
A= $node->{'selections'}
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | elsif ($kind eq 'field') { | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 11138 | my $level = $depth + 1; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 11138 | ▶ | die "DBIO::GraphQL: query depth exceeds max_depth (" . $policy->max_depth . ")\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | if $level > $policy->max_depth; | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 11134 | ▶ | my $def = $type && $type->can('fields') ? $type->fields->{ $node->{name} } : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type and $type->can("fields")
MC/DC50%1/2
$type and $type->can("fields")
$type
$type->can("fields")
Truth table66%2/3
A and B
A= $typeB= $type->can("fields")
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 11134 | ▶ | my $inner = $def ? _unwrap($def->{type}) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 11134 | ▶ | my $factor = $def ? _factor($ctx, $node, $def, $type) : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | my $below = $node->{selections} | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 11130 | ▶ | ? _cost($ctx, $node->{selections}, $inner, $level) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | : 0; | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 11109 | $total += 1 + $factor * $below; | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 21114 | ▶ | die "DBIO::GraphQL: query cost exceeds max_cost (" . $policy->max_cost . ")\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | if $total > $policy->max_cost; | ||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 10695 | return $total; | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | # How many rows a field yields, per parent row: the page size of a plural root | ||||||||||||||||||||||||||||||||||||||||||
| 144 | # query, default_rows for a has_many field, 1 for everything else. | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 11130 | ▶ | sub _factor { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_factor: called CC=13 SCAR=25.8
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 11130 | my ($ctx, $node, $def, $parent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 11130 | my $policy = $ctx->{policy}; | |||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 11130 | ▶ | if (ref $def->{args} eq 'HASH' && $def->{args}{page} && $def->{args}{cursor}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
ref $def->{"args"} eq "HASH" and $def->{"args"}{"page"} and $def->{"args"}{"cursor"}
ref $def->{"args"} eq "HASH" and $def->{"args"}{"page"}
MC/DC66%2/3
ref $def->{"args"} eq "HASH" and $def->{"args"}{"page"} and $def->{"args"}{"cursor"}
ref $def->{"args"} eq "HASH"
$def->{"args"}{"page"}
$def->{"args"}{"cursor"}
Truth table75%3/4
A and B and C
A= ref $def->{"args"} eq "HASH"B= $def->{"args"}{"page"}C= $def->{"args"}{"cursor"}
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 176 | ▶ | my $args = $node->{arguments} || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$node->{'arguments'} || {}
MC/DC100%1/1
$node->{'arguments'} || {}
$node->{'arguments'}
Truth table100%2/2
A
A= $node->{'arguments'}
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 176 | my $cursor = _value($ctx, $args->{cursor}); | |||||||||||||||||||||||||||||||||||||||||
| 152 | 176 | ▶ | if (ref $cursor eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 65 | return _rows(_value($ctx, $cursor->{first}), 10, $policy, 'first'); | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 111 | my $page = _value($ctx, $args->{page}); | |||||||||||||||||||||||||||||||||||||||||
| 156 | 111 | ▶ | if (ref $page eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 31 | return _rows(_value($ctx, $page->{take}), 10, $policy, 'take'); | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 80 | return $policy->default_rows; | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 10954 | my $type = $def->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 10954 | ▶ | $type = $type->of while $type && $type->can('of') && !$type->isa('GraphQL::Type::List'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$type and $type->can("of") and not $type->isa("GraphQL::Type::List")
$type and $type->can("of")
MC/DC0%0/3
$type and $type->can("of") and not $type->isa("GraphQL::Type::List")
$type
$type->can("of")
not $type->isa("GraphQL::Type::List")
Truth table50%2/4
A and B and not(C)
A= $typeB= $type->can("of")C= not $type->isa("GraphQL::Type::List")
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | return $policy->default_rows | ||||||||||||||||||||||||||||||||||||||||||
| 165 | if $type && $type->isa('GraphQL::Type::List') | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 10954 | ▶ | && !$ctx->{connection}{ $parent->name }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$type and $type->isa("GraphQL::Type::List") and not $ctx->{"connection"}{$parent->name}
$type and $type->isa("GraphQL::Type::List")
MC/DC66%2/3
$type and $type->isa("GraphQL::Type::List") and not $ctx->{"connection"}{$parent->name}
$type
$type->isa("GraphQL::Type::List")
not $ctx->{"connection"}{$parent->name}
Truth table75%3/4
A and B and not(C)
A= $typeB= $type->isa("GraphQL::Type::List")C= not $ctx->{"connection"}{$parent->name}
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 10928 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | # A given row count, or the resolver's own default when the argument is absent. | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 96 | ▶ | sub _rows { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rows: called CC=6 SCAR=18.3
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 96 | my ($value, $absent, $policy, $what) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 96 | ▶ | return $absent unless defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 89 | ▶ | return $policy->default_rows | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not ref $value and &Scalar::Util::looks_like_number($value)
MC/DC0%0/2
not ref $value and &Scalar::Util::looks_like_number($value)
not ref $value
&Scalar::Util::looks_like_number($value)
Truth table33%1/3
not(A) and B
A= not ref $valueB= &Scalar::Util::looks_like_number($value)
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | unless !ref $value && Scalar::Util::looks_like_number($value); | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 89 | ▶ | die "DBIO::GraphQL: $what $value exceeds max_rows (" . $policy->max_rows . ")\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | if $value > $policy->max_rows; | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 85 | ▶ | return $value >= 1 ? $value : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | # An argument value with variables resolved: the given value, else the | ||||||||||||||||||||||||||||||||||||||||||
| 182 | # variable's default in the operation. | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 383 | ▶ | sub _value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_value: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 383 | my ($ctx, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 383 | ▶ | if (ref $value eq 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 6 | my $name = $$value; | |||||||||||||||||||||||||||||||||||||||||
| 187 | return exists $ctx->{variables}{$name} | ||||||||||||||||||||||||||||||||||||||||||
| 188 | ? $ctx->{variables}{$name} | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 6 | ▶ | : ($ctx->{op_vars}{$name} || {})->{default_value}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$ctx->{'op_vars'}{$name} || {}
MC/DC0%0/1
$ctx->{'op_vars'}{$name} || {}
$ctx->{'op_vars'}{$name}
Truth table50%1/2
A
A= $ctx->{'op_vars'}{$name}
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 377 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 14 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | __END__ | ||||||||||||||||||||||||||||||||||||||||||