|  line  | 
 stmt  | 
 bran  | 
 cond  | 
 sub  | 
 pod  | 
 time  | 
 code  | 
| 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package GraphQL::Role::Abstract;  | 
| 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
3
 | 
6
 | 
 
 | 
 
 | 
  
6
  
 | 
 
 | 
4229
 | 
 use 5.014;  | 
| 
 
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
21
 | 
    | 
| 
4
 | 
6
 | 
 
 | 
 
 | 
  
6
  
 | 
 
 | 
33
 | 
 use strict;  | 
| 
 
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1082
 | 
    | 
| 
 
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
216
 | 
    | 
| 
5
 | 
18
 | 
 
 | 
 
 | 
  
6
  
 | 
 
 | 
183
 | 
 use warnings;  | 
| 
 
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
91
 | 
    | 
| 
 
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
196
 | 
    | 
| 
6
 | 
18
 | 
 
 | 
 
 | 
  
6
  
 | 
 
 | 
59
 | 
 use Moo::Role;  | 
| 
 
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
556
 | 
    | 
| 
 
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
37
 | 
    | 
| 
7
 | 
6
 | 
 
 | 
 
 | 
  
6
  
 | 
 
 | 
2203
 | 
 use GraphQL::MaybeTypeCheck;  | 
| 
 
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
11
 | 
    | 
| 
 
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
70
 | 
    | 
| 
8
 | 
18
 | 
 
 | 
 
 | 
  
6
  
 | 
 
 | 
77
 | 
 use Types::Standard -all;  | 
| 
 
 | 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
27
 | 
    | 
| 
 
 | 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
71
 | 
    | 
| 
9
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
10
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our $VERSION = '0.02';  | 
| 
11
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 NAME  | 
| 
13
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 GraphQL::Role::Abstract - GraphQL object role  | 
| 
15
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
16
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 SYNOPSIS  | 
| 
17
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   with qw(GraphQL::Role::Abstract);  | 
| 
19
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
20
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   # or runtime  | 
| 
21
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   Role::Tiny->apply_roles_to_object($foo, qw(GraphQL::Role::Abstract));  | 
| 
22
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
23
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 DESCRIPTION  | 
| 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
25
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Allows type constraints for abstract objects.  | 
| 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
27
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
29
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 method _complete_value(  | 
| 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   HashRef $context,  | 
| 
31
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   ArrayRef[HashRef] $nodes,  | 
| 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   HashRef $info,  | 
| 
33
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   ArrayRef $path,  | 
| 
34
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   Any $result,  | 
| 
35
 | 
4
 | 
  
 50
  
 | 
 
 | 
  
12
  
 | 
 
 | 
9
 | 
 ) {  | 
| 
 
 | 
4
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
34
 | 
    | 
| 
 
 | 
4
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
32
 | 
    | 
| 
 
 | 
4
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
37
 | 
    | 
| 
 
 | 
4
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
235
 | 
    | 
| 
 
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
6
 | 
    | 
| 
 
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
19
 | 
    | 
| 
 
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
125
 | 
    | 
| 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   my $runtime_type = ($self->resolve_type || \&_default_resolve_type)->(  | 
| 
37
 | 
 
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
     $result, $context->{context_value}, $info, $self  | 
| 
38
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   );  | 
| 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   # TODO promise stuff  | 
| 
40
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   $self->_ensure_valid_runtime_type(  | 
| 
41
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     $runtime_type,  | 
| 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     $context,  | 
| 
43
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     $nodes,  | 
| 
44
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     $info,  | 
| 
45
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     $result,  | 
| 
46
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   )->_complete_value(@_);  | 
| 
47
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
48
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
49
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 method _ensure_valid_runtime_type(  | 
| 
50
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   (Str | InstanceOf['GraphQL::Type::Object']) $runtime_type_or_name,  | 
| 
51
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   HashRef $context,  | 
| 
52
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   ArrayRef[HashRef] $nodes,  | 
| 
53
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   HashRef $info,  | 
| 
54
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   Any $result,  | 
| 
55
 | 
12
 | 
  
 50
  
 | 
 
 | 
  
12
  
 | 
 
 | 
30
 | 
 ) :ReturnType(InstanceOf['GraphQL::Type::Object']) {  | 
| 
 
 | 
12
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
27
 | 
    | 
| 
 
 | 
12
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
22
 | 
    | 
| 
 
 | 
12
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
24
 | 
    | 
| 
 
 | 
12
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
32
 | 
    | 
| 
 
 | 
12
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
28
 | 
    | 
| 
 
 | 
12
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
27
 | 
    | 
| 
 
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
18
 | 
    | 
| 
 
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
23
 | 
    | 
| 
 
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
23
 | 
    | 
| 
56
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   my $runtime_type = is_InstanceOf($runtime_type_or_name)  | 
| 
57
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     ? $runtime_type_or_name  | 
| 
58
 | 
12
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
86
 | 
     : $context->{schema}->name2type->{$runtime_type_or_name};  | 
| 
59
 | 
12
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
167
 | 
   die GraphQL::Error->new(  | 
| 
60
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
79
 | 
     message => "Abstract type @{[$self->name]} must resolve to an " .  | 
| 
61
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
76
 | 
       "Object type at runtime for field @{[$info->{parent_type}->name]}." .  | 
| 
62
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
59
 | 
       "@{[$info->{field_name}]} with value $result, received '@{[$runtime_type->name]}'.",  | 
| 
 
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
105
 | 
    | 
| 
63
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     nodes => [ $nodes ],  | 
| 
64
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   ) if !$runtime_type->isa('GraphQL::Type::Object');  | 
| 
65
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   die GraphQL::Error->new(  | 
| 
66
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
14
 | 
     message => "Runtime Object type '@{[$runtime_type->name]}' is not a possible type for " .  | 
| 
67
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
8
 | 
       "'@{[$self->name]}'.",  | 
| 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     nodes => [ $nodes ],  | 
| 
69
 | 
12
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
130
 | 
   ) if !$context->{schema}->is_possible_type($self, $runtime_type);  | 
| 
70
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
11
 | 
   $runtime_type;  | 
| 
71
 | 
16
 | 
 
 | 
 
 | 
  
6
  
 | 
 
 | 
277098
 | 
 }  | 
| 
 
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
14
 | 
    | 
| 
 
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
53
 | 
    | 
| 
72
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
73
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 fun _default_resolve_type(  | 
| 
74
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   Any $value,  | 
| 
75
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   Any $context,  | 
| 
76
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   HashRef $info,  | 
| 
77
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   (ConsumerOf['GraphQL::Role::Abstract']) $abstract_type,  | 
| 
78
 | 
 
 | 
 
 | 
 
 | 
  
4
  
 | 
 
 | 
 
 | 
 ) {  | 
| 
79
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   my @possibles = @{ $info->{schema}->get_possible_types($abstract_type) };  | 
| 
80
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   # TODO promise stuff  | 
| 
81
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   (grep $_->is_type_of->($value, $context, $info), grep $_->is_type_of, @possibles)[0];  | 
| 
82
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
83
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
84
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 __PACKAGE__->meta->make_immutable();  | 
| 
85
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
86
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 1;  |