File Coverage

blib/lib/GraphQL/Plugin/Convert.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1              
2             use Moo;
3 1     1   521 use strict;
  1         2  
  1         6  
4 1     1   277 use warnings;
  1         1  
  1         19  
5 1     1   4  
  1         2  
  1         54  
6             =head1 NAME
7              
8             GraphQL::Plugin::Convert - GraphQL plugin API abstract class
9              
10             =head1 SYNOPSIS
11              
12             package GraphQL::Plugin::Convert::DBIC;
13             use Moo;
14             extends qw(GraphQL::Plugin::Convert);
15             # ...
16              
17             package main;
18             use Mojolicious::Lite;
19             use Schema;
20             use GraphQL::Plugin::Convert::DBIC;
21             helper db => sub { Schema->connect('dbi:SQLite:test.db') };
22             my $converted = GraphQL::Plugin::Convert::DBIC->to_graphql(sub { app->db });
23             plugin GraphQL => {
24             map { $_ => $converted->{$_} }
25             qw(schema resolver root_value subscribe_resolver)
26             };
27              
28             # OR, for knowledgeable consumers of GraphQL::Plugin::Convert APIs:
29             package main;
30             use Mojolicious::Lite;
31             use Schema;
32             helper db => sub { Schema->connect('dbi:SQLite:test.db') };
33             plugin GraphQL => { convert => [ 'DBIC', sub { app->db } ] };
34              
35             =head1 DESCRIPTION
36              
37             Abstract class for other GraphQL type classes to inherit from and
38             implement.
39              
40             =head1 METHODS
41              
42             =head2 to_graphql(@values)
43              
44             When called with suitable values (as defined by the implementing class),
45             will return a hash-ref with these keys:
46              
47             =over
48              
49             =item schema
50              
51             A L<GraphQL::Schema>.
52              
53             =item resolver
54              
55             A code-ref suitable for using as a resolver by
56             L<GraphQL::Execution/execute>. Optional.
57              
58             =item root_value
59              
60             A hash-ref suitable for using as a C<$root_value> by
61             L<GraphQL::Execution/execute>. Optional.
62              
63             =item subscribe_resolver
64              
65             A code-ref suitable for using as a C<$subscribe_resolver> by
66             L<GraphQL::Subscription/subscribe>. Optional.
67              
68             =back
69              
70             =head2 from_graphql
71              
72             When called with a hash-ref shaped as above, with at least a C<schema>
73             key with a L<GraphQL::Schema>, returns some value(s). Optional to
74             implement. If the plugin does implement this, allows conversion from
75             a GraphQL schema to that plugin's domain.
76              
77             =cut
78              
79             __PACKAGE__->meta->make_immutable();
80              
81             1;