File Coverage

blib/lib/GraphQL.pm
Criterion Covered Total %
statement 8 8 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 11 11 100.0


line stmt bran cond sub pod time code
1              
2             use 5.014;
3 1     1   100195 use strict;
  1         4  
4 1     1   5 use warnings;
  1         1  
  1         34  
5 1     1   5  
  1         2  
  1         69  
6             =head1 NAME
7              
8             GraphQL - Perl implementation of GraphQL
9              
10             =cut
11              
12             our $VERSION = '0.54';
13              
14             =begin markdown
15              
16             # PROJECT STATUS
17              
18             | OS | Build status |
19             |:-------:|--------------:|
20             | Linux | [![Build Status](https://travis-ci.org/graphql-perl/graphql-perl.svg?branch=master)](https://travis-ci.org/graphql-perl/graphql-perl) |
21              
22             [![CPAN version](https://badge.fury.io/pl/GraphQL.svg)](https://metacpan.org/pod/GraphQL) [![Coverage Status](https://coveralls.io/repos/github/graphql-perl/graphql-perl/badge.svg?branch=master)](https://coveralls.io/github/graphql-perl/graphql-perl?branch=master)
23              
24             =end markdown
25              
26             =head1 SYNOPSIS
27              
28             use GraphQL::Schema;
29             use GraphQL::Type::Object;
30             use GraphQL::Type::Scalar qw($String);
31             use GraphQL::Execution qw(execute);
32              
33             my $schema = GraphQL::Schema->from_doc(<<'EOF');
34             type Query {
35             helloWorld: String
36             }
37             EOF
38             post '/graphql' => sub {
39             send_as JSON => execute(
40             $schema,
41             body_parameters->{query},
42             { helloWorld => 'Hello world!' },
43             undef,
44             body_parameters->{variables},
45             body_parameters->{operationName},
46             undef,
47             );
48             };
49              
50             The above is from L<the sample Dancer 2 applet|https://github.com/graphql-perl/sample-dancer2>.
51              
52             =head1 DESCRIPTION
53              
54             This module is a port of the GraphQL reference implementation,
55             L<graphql-js|https://github.com/graphql-js/graphql-js>, to Perl 5.
56              
57             It now supports Promises, allowing asynchronous operation. See
58             L<Mojolicious::Plugin::GraphQL> for an example of how to take advantage
59             of this.
60              
61             As of 0.39, supports GraphQL subscriptions.
62              
63             See L<GraphQL::Type> for description of how to create GraphQL types.
64              
65             =head2 Introduction to GraphQL
66              
67             GraphQL is a technology that lets clients talk to APIs via a single
68             endpoint, which acts as a single "source of the truth". This means clients
69             do not need to seek the whole picture from several APIs. Additionally,
70             it makes this efficient in network traffic, time, and programming effort:
71              
72             =over
73              
74             =item Network traffic
75              
76             The request asks for exactly what it wants, which it gets, and no
77             more. No wasted traffic.
78              
79             =item Time
80              
81             It gets all the things it needs in one go, including any connected
82             resources, so it does not need to make several requests to fill its
83             information requirement.
84              
85             =item Programming effort
86              
87             With "fragments" that can be attached to user-interface components,
88             keeping track of what information a whole page needs to request can be
89             automated. See L<Relay|https://facebook.github.io/relay/> or
90             L<Apollo|http://dev.apollodata.com/> for more on this.
91              
92             =back
93              
94             =head2 Basic concepts
95              
96             GraphQL implements a system featuring a L<schema|GraphQL::Schema>,
97             which features various classes of L<types|GraphQL::Type>, some of which
98             are L<objects|GraphQL::Type::Object>. Special objects provide the roots
99             of queries (mandatory), and mutations and subscriptions (both optional).
100              
101             Objects have fields, each of which can be specified to take arguments,
102             and which have a return type. These are effectively the properties and/or
103             methods on the type. If they return an object, then a query can specify
104             subfields of that object, and so on - as alluded to in the "time-saving"
105             point above.
106              
107             For more, see the JavaScript tutorial in L</"SEE ALSO">.
108              
109             =head2 Hooking your system up to GraphQL
110              
111             You will need to decide how to model your system in GraphQL terms. This
112             will involve deciding on what L<output object types|GraphQL::Type::Object>
113             you have, what fields they have, and what arguments and return-types
114             those fields have.
115              
116             Additionally, you will need to design mutations if you want to be able
117             to update/create/delete data. This requires some thought for return types,
118             to ensure you can get all the information you need to proceed to avoid
119             extra round-trips.
120              
121             The easiest way to achieve these things is to make a
122             L<GraphQL::Plugin::Convert> subclass, to encapsulate the specifics of
123             your system. See the documentation for further information.
124              
125             Finally, you should consider whether you need "subscriptions". These
126             are designed to hook into WebSockets. Apollo has a L<JavaScript
127             module|https://github.com/apollographql/graphql-subscriptions> for this.
128              
129             Specifying types and fields is straightforward. See L<the
130             document|GraphQL::Type::Library/FieldMapOutput> for how to make resolvers.
131              
132             =head1 DEBUGGING
133              
134             To debug, set environment variable C<GRAPHQL_DEBUG> to a true value.
135              
136             =head1 EXPORT
137              
138             None yet.
139              
140             =head1 SEE ALSO
141              
142             L<SQL::Translator::Producer::GraphQL> - produce GraphQL schemas from a L<DBIx::Class::Schema> (or in fact any SQL database)
143              
144             L<GraphQL::Plugin::Convert::DBIC> - produce working GraphQL schema from
145             a L<DBIx::Class::Schema>
146              
147             L<GraphQL::Plugin::Convert::OpenAPI> - produce working GraphQL schema
148             from an OpenAPI specification
149              
150             L<Sample Mojolicious OpenAPI to GraphQL applet|https://github.com/graphql-perl/sample-mojolicious-openapi>
151              
152             L<Sample Dancer 2 applet|https://github.com/graphql-perl/sample-dancer2>
153              
154             L<Sample Mojolicious applet|https://github.com/graphql-perl/sample-mojolicious>
155              
156             L<Dancer2::Plugin::GraphQL>
157              
158             L<Mojolicious::Plugin::GraphQL>
159              
160             L<http://facebook.github.io/graphql/> - GraphQL specification
161              
162             L<http://graphql.org/graphql-js/> - Tutorial on the JavaScript version,
163             highly recommended.
164             L<Translation to
165             graphql-perl|http://blogs.perl.org/users/ed_j/2017/10/graphql-perl---graphql-js-tutorial-translation-to-graphql-perl-and-mojoliciousplugingraphql.html>.
166              
167             =head1 AUTHOR
168              
169             Ed J, C<< <etj at cpan.org> >>
170              
171             =head1 BUGS
172              
173             Please report any bugs or feature requests on
174             L<https://github.com/graphql-perl/graphql-perl/issues>.
175              
176             Or, if you prefer email and/or RT: to C<bug-graphql
177             at rt.cpan.org>, or through the web interface at
178             L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=GraphQL>. I will be
179             notified, and then you'll automatically be notified of progress on your
180             bug as I make changes.
181              
182             =head1 ACKNOWLEDGEMENTS
183              
184             The creation of this work has been sponsored by Perl Careers:
185             L<https://perl.careers/>.
186              
187             Artur Khabibullin C<< <rtkh at cpan.org> >> contributed valuable ports
188             of the JavaScript tests.
189              
190             The creation of the subscriptions functionality in this work has been
191             sponsored by Sanctus.app: L<https://sanctus.app>.
192              
193             =head1 LICENSE AND COPYRIGHT
194              
195             Copyright 2017 Ed J.
196              
197             This program is free software; you can redistribute it and/or modify it
198             under the terms of the the Artistic License (2.0). You may obtain a
199             copy of the full license at:
200              
201             L<http://www.perlfoundation.org/artistic_license_2_0>
202              
203             =cut
204              
205             1;