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