File Coverage

blib/lib/SQL/Translator/Producer/GraphQL.pm
Criterion Covered Total %
statement 78 78 100.0
branch 1 2 50.0
condition n/a
subroutine 25 25 100.0
pod 0 1 0.0
total 104 106 98.1


line stmt bran cond sub pod time code
1             package SQL::Translator::Producer::GraphQL;
2 3     3   60741 use 5.008001;
  3         13  
3 3     3   19 use strict;
  3         7  
  3         66  
4 3     3   15 use warnings;
  3         6  
  3         81  
5 3     3   1469 use SQL::Translator::Producer::DBIx::Class::File;
  3         19491  
  3         90  
6 3     3   1637 use GraphQL::Plugin::Convert::DBIC;
  3         3325619  
  3         475  
7              
8             our $VERSION = "0.03";
9              
10             my $dbic_schema_class_track = 'CLASS00000';
11             sub produce {
12 3     3 0 1177166 my $translator = shift;
13 3         52 my $schema = $translator->schema;
14 3         116 my $dbic_schema_class = ++$dbic_schema_class_track;
15 3         51 my $dbic_translator = bless { %$translator }, ref $translator;
16 3         66 $dbic_translator->producer_args({ prefix => $dbic_schema_class });
17 3     2   152 eval SQL::Translator::Producer::DBIx::Class::File::produce($dbic_translator);
  2     2   82100  
  2     2   4  
  2     2   599  
  2     2   22351  
  2     2   6  
  2     2   68  
  2     2   9  
  2     2   14  
  2     2   417  
  2     2   12  
  2     2   5  
  2     2   159  
  2     2   11  
  2     2   20  
  2     1   37  
  2     1   8  
  2     1   4  
  2         294  
  2         13  
  2         3  
  2         416  
  2         7359  
  2         5  
  2         34  
  2         8  
  2         4  
  2         128  
  2         17547  
  2         5  
  2         217  
  2         15  
  2         5  
  2         64  
  2         12  
  2         5  
  2         528  
  2         13  
  2         5  
  2         161  
  2         13  
  2         4  
  2         35  
  2         10  
  2         5  
  2         185  
  1         6  
  1         2  
  1         85  
  1         7  
  1         3  
  1         18  
  1         5  
  1         1  
  1         57  
18 3 50       20 die "Failed to make DBIx::Class::Schema: $@" if $@;
19             my $converted = GraphQL::Plugin::Convert::DBIC->to_graphql(
20 3     3   41 sub { $dbic_schema_class->connect }
21 3         43 );
22 3         501722 $converted->{schema}->to_doc;
23             }
24              
25             =encoding utf-8
26              
27             =head1 NAME
28              
29             SQL::Translator::Producer::GraphQL - GraphQL schema producer for SQL::Translator
30              
31             =begin markdown
32              
33             # PROJECT STATUS
34              
35             | OS | Build status |
36             |:-------:|--------------:|
37             | Linux | [![Build Status](https://travis-ci.org/graphql-perl/SQL-Translator-Producer-GraphQL.svg?branch=master)](https://travis-ci.org/graphql-perl/SQL-Translator-Producer-GraphQL) |
38              
39             [![CPAN version](https://badge.fury.io/pl/SQL-Translator-Producer-GraphQL.svg)](https://metacpan.org/pod/SQL::Translator::Producer::GraphQL)
40              
41             =end markdown
42              
43             =head1 SYNOPSIS
44              
45             use SQL::Translator;
46             use SQL::Translator::Producer::GraphQL;
47             my $t = SQL::Translator->new( parser => '...' );
48             $t->producer('GraphQL');
49             $t->translate;
50              
51             =head1 DESCRIPTION
52              
53             This module will produce a L<GraphQL::Schema> from the given
54             L<SQL::Translator::Schema>. It does this by first
55             turning it into a L<DBIx::Class::Schema> using
56             L<SQL::Translator::Producer::DBIx::Class::File>, then passing it to
57             L<GraphQL::Plugin::Convert::DBIC/to_graphql>.
58              
59             =head1 ARGUMENTS
60              
61             Currently none.
62              
63             =head1 DEBUGGING
64              
65             To debug, set environment variable C<GRAPHQL_DEBUG> to a true value.
66              
67             =head1 AUTHOR
68              
69             Ed J, C<< <etj at cpan.org> >>
70              
71             Based heavily on L<SQL::Translator::Producer::DBIxSchemaDSL>.
72              
73             =head1 LICENSE
74              
75             Copyright (C) Ed J
76              
77             This library is free software; you can redistribute it and/or modify
78             it under the same terms as Perl itself.
79              
80             =cut
81              
82             1;