GraphQL/Plugin/Convert/Test.pm

filter: Statementstmt 100% 14 / 14 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 91.3% 21 / 23 CC 3 SCAR 7.2
CC
3
Cov
89%
to_graphql
3.1
BEGIN
1.0
BEGIN
1.0
CRAP 2.0
« GraphQL/Plugin/Type/DateTime.pm ↑ Summary GraphQL/Validation.pm »
1 package GraphQL::Plugin::Convert::Test;
2  
3 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use GraphQL::Schema;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 extends qw(GraphQL::Plugin::Convert);
6  
7 =head1 NAME
8  
9 GraphQL::Plugin::Convert::Test - GraphQL plugin test class
10  
11 =head1 SYNOPSIS
12  
13 package main;
14 use GraphQL::Plugin::Convert::Test;
15 use GraphQL::Execution qw(execute);
16 my $converted = GraphQL::Plugin::Convert::Test->to_graphql;
17 print execute(
18 $converted->{schema}, '{helloWorld}', $converted->{root_value}
19 )->{data}{helloWorld}, "\n";
20  
21 # show schema from shell
22 perl -Maliased=GraphQL::Plugin::Convert::Test -e 'print Test->to_graphql->{schema}->to_doc'
23  
24 =head1 DESCRIPTION
25  
26 Example class to allow testing of convert plugin consumers.
27  
28 =head1 METHODS
29  
30 Produces a schema and root value that defines the top-level query field
31 C<helloWorld>. That will return the string C<Hello, world!>.
32  
33 Also has a mutation, C<echo>, that takes a String C<s>, and returns it.
34  
35 =head2 to_graphql(@values)
36  
37 If the first value is true, it is a C<subscribe_resolver>,
38 enabling subscriptions in the generated schema. It will be returned
39 as the relevant key in the hash-ref, suitable for being passed as the
40 relevant arg to L<GraphQL::Subscription/subscribe>. The schema will have
41 a subscription field C<timedEcho> that takes a String C<s>, and should
42 return it periodically, in a way determined by the subscription function.
43  
44 =cut
45  
46 1 ▶sub to_graphql {
Subroutine to_graphql: called CC=3 SCAR=11.3
Pod documented
47 1 my ($class, $subscribe_resolver) = @_;
48 1 my $sdl = <<'EOF';
49 type Query { helloWorld: String! }
50 type Mutation { echo(s: String!): String! }
51 EOF
52 1 ▶ $sdl .= "type Subscription { timedEcho(s: String!): String! }\n"
Branch: 1 branch
BranchTrueFalseTotal
if $subscribe_resolver 1 0 1
53 if $subscribe_resolver;
54 +{
55 schema => GraphQL::Schema->from_doc($sdl),
56 root_value => {
57 helloWorld => 'Hello, world!',
58 1 ▶ echo => sub { $_[0]->{s} },
Subroutine __ANON__: called CC=1 SCAR=0.0
59 },
60 1 ▶ $subscribe_resolver ? (subscribe_resolver => $subscribe_resolver) : (),
Branch: 1 branch
BranchTrueFalseTotal
$subscribe_resolver ? : 1 0 1
61 };
62 }
63  
64 1 __PACKAGE__->meta->make_immutable();
65  
66 1 1;
« GraphQL/Plugin/Type/DateTime.pm ↑ Summary GraphQL/Validation.pm »