line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package GraphQL::Role::Abstract; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
4031
|
use 5.014; |
|
6
|
|
|
|
|
22
|
|
4
|
6
|
|
|
6
|
|
38
|
use strict; |
|
18
|
|
|
|
|
976
|
|
|
18
|
|
|
|
|
248
|
|
5
|
18
|
|
|
6
|
|
222
|
use warnings; |
|
18
|
|
|
|
|
142
|
|
|
18
|
|
|
|
|
229
|
|
6
|
18
|
|
|
6
|
|
89
|
use Moo::Role; |
|
18
|
|
|
|
|
735
|
|
|
6
|
|
|
|
|
38
|
|
7
|
6
|
|
|
6
|
|
2441
|
use GraphQL::MaybeTypeCheck; |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
72
|
|
8
|
18
|
|
|
6
|
|
99
|
use Types::Standard -all; |
|
8
|
|
|
|
|
29
|
|
|
8
|
|
|
|
|
88
|
|
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
|
|
21
|
) { |
|
4
|
50
|
|
|
|
33
|
|
|
4
|
50
|
|
|
|
29
|
|
|
4
|
50
|
|
|
|
41
|
|
|
4
|
50
|
|
|
|
268
|
|
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
21
|
|
|
4
|
|
|
|
|
135
|
|
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
|
|
39
|
) :ReturnType(InstanceOf['GraphQL::Type::Object']) { |
|
12
|
50
|
|
|
|
34
|
|
|
12
|
50
|
|
|
|
22
|
|
|
12
|
50
|
|
|
|
26
|
|
|
12
|
50
|
|
|
|
42
|
|
|
12
|
100
|
|
|
|
39
|
|
|
12
|
50
|
|
|
|
35
|
|
|
12
|
|
|
|
|
21
|
|
|
12
|
|
|
|
|
31
|
|
|
12
|
|
|
|
|
34
|
|
56
|
|
|
|
|
|
|
my $runtime_type = is_InstanceOf($runtime_type_or_name) |
57
|
|
|
|
|
|
|
? $runtime_type_or_name |
58
|
12
|
100
|
|
|
|
104
|
: $context->{schema}->name2type->{$runtime_type_or_name}; |
59
|
12
|
50
|
|
|
|
202
|
die GraphQL::Error->new( |
60
|
12
|
|
|
|
|
98
|
message => "Abstract type @{[$self->name]} must resolve to an " . |
61
|
12
|
|
|
|
|
98
|
"Object type at runtime for field @{[$info->{parent_type}->name]}." . |
62
|
12
|
|
|
|
|
88
|
"@{[$info->{field_name}]} with value $result, received '@{[$runtime_type->name]}'.", |
|
12
|
|
|
|
|
89
|
|
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
|
|
|
|
|
11
|
"'@{[$self->name]}'.", |
68
|
|
|
|
|
|
|
nodes => [ $nodes ], |
69
|
12
|
50
|
|
|
|
172
|
) if !$context->{schema}->is_possible_type($self, $runtime_type); |
70
|
4
|
|
|
|
|
18
|
$runtime_type; |
71
|
16
|
|
|
6
|
|
311648
|
} |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
39
|
|
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; |