| 1 | package GraphQL::Houtou::Type::Union; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | 13 | ▶ | use parent 'GraphQL::Houtou::Type'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | 13 | ▶ | use Role::Tiny::With; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | 13 | ▶ | use GraphQL::Houtou::Type::List (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | 13 | ▶ | use GraphQL::Houtou::Type::NonNull (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | 13 | with qw( | |||||||||||||||||||||||||||||||||
| 13 | GraphQL::Houtou::Role::Output | ||||||||||||||||||||||||||||||||||
| 14 | GraphQL::Houtou::Role::Composite | ||||||||||||||||||||||||||||||||||
| 15 | GraphQL::Houtou::Role::Abstract | ||||||||||||||||||||||||||||||||||
| 16 | GraphQL::Houtou::Role::Named | ||||||||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||
| 19 | 9 | ▶ | sub list { | ||||||||||||||||||||||||||||||||
|
Subroutine
list: called CC=2 SCAR=9.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 20 | 9 | ▶ | $_[0]->{_houtou_list} ||= GraphQL::Houtou::Type::List->new(of => $_[0]); | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$_[0]{"_houtou_list"} ||= "GraphQL::Houtou::Type::List"->new("of", $_[0])
MC/DC0%0/2
$_[0]{"_houtou_list"} ||= "GraphQL::Houtou::Type::List"->new("of", $_[0])
$_[0]{"_houtou_list"}
"GraphQL::Houtou::Type::List"->new("of", $_[0])
Truth table33%1/3
A ||= B
A= $_[0]{"_houtou_list"}B= "GraphQL::Houtou::Type::List"->new("of", $_[0])
| |||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub non_null { | ||||||||||||||||||||||||||||||||
|
Subroutine
non_null: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | $_[0]->{_houtou_non_null} ||= GraphQL::Houtou::Type::NonNull->new(of => $_[0]); | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_[0]{"_houtou_non_null"} ||= "GraphQL::Houtou::Type::NonNull"->new("of", $_[0])
MC/DC0%0/2
$_[0]{"_houtou_non_null"} ||= "GraphQL::Houtou::Type::NonNull"->new("of", $_[0])
$_[0]{"_houtou_non_null"}
"GraphQL::Houtou::Type::NonNull"->new("of", $_[0])
Truth table0%0/3
A ||= B
A= $_[0]{"_houtou_non_null"}B= "GraphQL::Houtou::Type::NonNull"->new("of", $_[0])
| |||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | 13 | ▶ | use constant DEBUG => $ENV{GRAPHQL_DEBUG}; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||
| 29 | 24 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 30 | 24 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||
| 31 | 24 | ▶ | die "GraphQL::Houtou::Type::Union requires name" if !defined $args{name}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 32 | 24 | ▶ | die "GraphQL::Houtou::Type::Union requires types" if !exists $args{types}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 33 | 24 | my $types = $args{types}; | |||||||||||||||||||||||||||||||||
| 34 | 24 | ▶ | _validate_member_types($types) if ref($types) ne 'CODE'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 35 | 24 | my $self = $class->SUPER::new(%args); | |||||||||||||||||||||||||||||||||
| 36 | 24 | $self->{name} = $args{name}; | |||||||||||||||||||||||||||||||||
| 37 | 24 | $self->{description} = $args{description}; | |||||||||||||||||||||||||||||||||
| 38 | 24 | $self->{types} = $types; | |||||||||||||||||||||||||||||||||
| 39 | 24 | $self->{resolve_type} = $args{resolve_type}; | |||||||||||||||||||||||||||||||||
| 40 | 24 | $self->{tag_resolver} = $args{tag_resolver}; | |||||||||||||||||||||||||||||||||
| 41 | 24 | $self->{tag_map} = $args{tag_map}; | |||||||||||||||||||||||||||||||||
| 42 | 24 | $self->{_types_validated} = 0; | |||||||||||||||||||||||||||||||||
| 43 | 24 | return $self; | |||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||
| 46 | 363 | ▶ | sub name { return $_[0]->{name} } | ||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 47 | 94 | ▶ | sub description { return $_[0]->{description} } | ||||||||||||||||||||||||||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 48 | 185 | ▶ | sub to_string { return $_[0]->{to_string} ||= $_[0]->name } | ||||||||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=2 SCAR=7.2
Pod
undocumented
Condition66%2/3
$_[0]{"to_string"} ||= $_[0]->name
MC/DC0%0/2
$_[0]{"to_string"} ||= $_[0]->name
$_[0]{"to_string"}
$_[0]->name
Truth table66%2/3
A ||= B
A= $_[0]{"to_string"}B= $_[0]->name
| |||||||||||||||||||||||||||||||||||
| 49 | 24 | ▶ | sub _validate_member_types { | ||||||||||||||||||||||||||||||||
|
Subroutine
_validate_member_types: called CC=6 SCAR=19.6
| |||||||||||||||||||||||||||||||||||
| 50 | 24 | my ($types) = @_; | |||||||||||||||||||||||||||||||||
| 51 | 24 | ▶ | die "GraphQL::Houtou::Type::Union requires a non-empty types array" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $types ne "ARRAY" or not @$types
MC/DC0%0/2
ref $types ne "ARRAY" or not @$types
ref $types ne "ARRAY"
not @$types
Truth table33%1/3
A or not(B)
A= ref $types ne "ARRAY"B= not @$types
| |||||||||||||||||||||||||||||||||||
| 52 | if ref($types) ne 'ARRAY' || !@$types; | ||||||||||||||||||||||||||||||||||
| 53 | 24 | my %seen; | |||||||||||||||||||||||||||||||||
| 54 | 24 | for my $type (@$types) { | |||||||||||||||||||||||||||||||||
| 55 | 30 | ▶ | die "GraphQL::Houtou::Type::Union requires object types" if !ref($type); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 56 | 30 | ▶ | die "Duplicate union member " . $type->name if $seen{$type->name}++; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||
| 58 | 24 | return; | |||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||
| 61 | 244 | ▶ | sub types { | ||||||||||||||||||||||||||||||||
|
Subroutine
types: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 62 | 244 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 63 | 244 | ▶ | if (ref($self->{types}) eq 'CODE') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 64 | 12 | my $types = $self->{types}->(); | |||||||||||||||||||||||||||||||||
| 65 | 12 | _validate_member_types($types); | |||||||||||||||||||||||||||||||||
| 66 | 12 | $self->{types} = $types; | |||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||
| 68 | 244 | return $self->{types}; | |||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | 12 | ▶ | sub from_ast { | ||||||||||||||||||||||||||||||||
|
Subroutine
from_ast: called CC=1 SCAR=0.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 72 | 12 | my ($class, $name2type, $ast_node) = @_; | |||||||||||||||||||||||||||||||||
| 73 | 12 | require GraphQL::Houtou::Internal::TypeSupport; | |||||||||||||||||||||||||||||||||
| 74 | return $class->new( | ||||||||||||||||||||||||||||||||||
| 75 | GraphQL::Houtou::Internal::TypeSupport::named_from_ast($ast_node), | ||||||||||||||||||||||||||||||||||
| 76 | GraphQL::Houtou::Internal::TypeSupport::from_ast_maptype($name2type, $ast_node, 'types'), | ||||||||||||||||||||||||||||||||||
| 77 | # SDL carries no dispatch logic; replace via the resolvers option of | ||||||||||||||||||||||||||||||||||
| 78 | # Schema->from_doc (resolve_type / tag_resolver) before executing | ||||||||||||||||||||||||||||||||||
| 79 | # queries that hit this union. | ||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | resolve_type => sub { return }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 81 | 12 | ); | |||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||
| 83 | 131 | ▶ | sub resolve_type { return $_[0]->{resolve_type} } | ||||||||||||||||||||||||||||||||
|
Subroutine
resolve_type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 84 | 28 | ▶ | sub tag_resolver { return $_[0]->{tag_resolver} } | ||||||||||||||||||||||||||||||||
|
Subroutine
tag_resolver: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 85 | 18 | ▶ | sub tag_map { return $_[0]->{tag_map} } | ||||||||||||||||||||||||||||||||
|
Subroutine
tag_map: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 86 | 229 | ▶ | sub _types_validated { | ||||||||||||||||||||||||||||||||
|
Subroutine
_types_validated: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 87 | 229 | my ($self, @set) = @_; | |||||||||||||||||||||||||||||||||
| 88 | 229 | ▶ | $self->{_types_validated} = $set[0] if @set; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 89 | 229 | return $self->{_types_validated}; | |||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | 205 | ▶ | sub get_types { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_types: called CC=9 SCAR=23.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 93 | 205 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 94 | 205 | my @types = @{ $self->types }; | |||||||||||||||||||||||||||||||||
| 95 | 205 | ▶ | return \@types if $self->_types_validated; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||
| 97 | 24 | $self->_types_validated(1); | |||||||||||||||||||||||||||||||||
| 98 | my @non_object = grep { | ||||||||||||||||||||||||||||||||||
| 99 | 24 | ▶ | !ref($_) | ||||||||||||||||||||||||||||||||
|
Condition66%4/6
ref $_ && ($_->isa('GraphQL::Houtou::Type::Object') || $_->isa('GraphQL::Type::Object'))
$_->isa("GraphQL::Houtou::Type::Object") or $_->isa("GraphQL::Type::Object")
MC/DC33%1/3
ref $_ && ($_->isa('GraphQL::Houtou::Type::Object') || $_->isa('GraphQL::Type::Object'))
ref $_
$_->isa("GraphQL::Houtou::Type::Object")
$_->isa("GraphQL::Type::Object")
Truth table50%2/4
A && B or C
A= ref $_B= $_->isa("GraphQL::Houtou::Type::Object")C= $_->isa("GraphQL::Type::Object")
| |||||||||||||||||||||||||||||||||||
| 100 | || !($_->isa('GraphQL::Houtou::Type::Object') || $_->isa('GraphQL::Type::Object')) | ||||||||||||||||||||||||||||||||||
| 101 | } @types; | ||||||||||||||||||||||||||||||||||
| 102 | 1 | die "Union type @{[$self->name]} can only include Object types, found " | |||||||||||||||||||||||||||||||||
| 103 | 24 | ▶ | . join(', ', map { ref($_) ? $_->to_string : "'$_'" } @non_object) . ".\n" | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 104 | if @non_object; | ||||||||||||||||||||||||||||||||||
| 105 | 23 | ▶ | if (!$self->resolve_type && !$self->tag_resolver) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->resolve_type or $self->tag_resolver
MC/DC0%0/2
$self->resolve_type or $self->tag_resolver
$self->resolve_type
$self->tag_resolver
Truth table66%2/3
A or B
A= $self->resolve_typeB= $self->tag_resolver
| |||||||||||||||||||||||||||||||||||
| 106 | 0 | my @bad = map $_->name, grep !$_->is_type_of, @types; | |||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | die $self->name . " no resolve_type and no is_type_of for @bad" if @bad; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||
| 109 | 23 | return \@types; | |||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||
| 112 | 3 | ▶ | sub to_doc { | ||||||||||||||||||||||||||||||||
|
Subroutine
to_doc: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 113 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 114 | 3 | ▶ | return $self->{to_doc} if exists $self->{to_doc}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 115 | 3 | require GraphQL::Houtou::Internal::TypeSupport; | |||||||||||||||||||||||||||||||||
| 116 | return $self->{to_doc} = join '', map "$_\n", | ||||||||||||||||||||||||||||||||||
| 117 | GraphQL::Houtou::Internal::TypeSupport::description_doc_lines($self->description), | ||||||||||||||||||||||||||||||||||
| 118 | 3 | "union @{[$self->name]} = " . join(' | ', map $_->name, @{ $self->types }); | |||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||
| 121 | 13 | 1; | |||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||
| 123 | __END__ | ||||||||||||||||||||||||||||||||||