| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package SQL::Translator::Producer::GraphQL; |
|
2
|
3
|
|
|
3
|
|
614277
|
use strict; |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
103
|
|
|
3
|
3
|
|
|
3
|
|
18
|
use warnings; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
92
|
|
|
4
|
3
|
|
|
3
|
|
489
|
use GraphQL::Plugin::Convert::DBIC; |
|
|
3
|
|
|
|
|
27
|
|
|
|
3
|
|
|
|
|
511
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = "0.05"; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
my $dbic_schema_class_track = 'CLASS00000'; |
|
9
|
|
|
|
|
|
|
sub produce { |
|
10
|
3
|
|
|
3
|
0
|
1574024
|
my $translator = shift; |
|
11
|
3
|
|
|
|
|
58
|
my $schema = $translator->schema; |
|
12
|
3
|
|
|
|
|
138
|
my $dbic_schema_class = ++$dbic_schema_class_track; |
|
13
|
3
|
|
|
|
|
79
|
my $dbic_translator = bless { %$translator }, ref $translator; |
|
14
|
3
|
|
|
|
|
76
|
$dbic_translator->producer_args({ prefix => $dbic_schema_class }); |
|
15
|
3
|
|
|
|
|
239
|
my $perl = dbic_produce($dbic_translator); |
|
16
|
3
|
|
|
2
|
|
430
|
eval $perl; |
|
|
2
|
|
|
2
|
|
20
|
|
|
|
2
|
|
|
2
|
|
5
|
|
|
|
2
|
|
|
2
|
|
899
|
|
|
|
2
|
|
|
2
|
|
20892
|
|
|
|
2
|
|
|
2
|
|
6
|
|
|
|
2
|
|
|
2
|
|
48
|
|
|
|
2
|
|
|
2
|
|
10
|
|
|
|
2
|
|
|
2
|
|
5
|
|
|
|
2
|
|
|
2
|
|
473
|
|
|
|
2
|
|
|
2
|
|
15
|
|
|
|
2
|
|
|
2
|
|
6
|
|
|
|
2
|
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
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
25
|
|
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
93
|
|
|
17
|
3
|
50
|
|
|
|
19
|
die "Failed to make DBIx::Class::Schema: $@" if $@; |
|
18
|
3
|
|
|
|
|
34
|
my $converted = GraphQL::Plugin::Convert::DBIC->to_graphql($dbic_schema_class->connect); |
|
19
|
3
|
|
|
|
|
835067
|
$converted->{schema}->to_doc; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
{ |
|
23
|
|
|
|
|
|
|
# from SQL::Translator::Producer::DBIx::Class::File; |
|
24
|
3
|
|
|
3
|
|
1057
|
use SQL::Translator::Schema::Constants; |
|
|
3
|
|
|
|
|
783
|
|
|
|
3
|
|
|
|
|
310
|
|
|
25
|
3
|
|
|
3
|
|
1375
|
use SQL::Translator::Utils qw(header_comment); |
|
|
3
|
|
|
|
|
6489
|
|
|
|
3
|
|
|
|
|
157
|
|
|
26
|
3
|
|
|
3
|
|
649
|
use Data::Dumper (); |
|
|
3
|
|
|
|
|
6207
|
|
|
|
3
|
|
|
|
|
2217
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
## Skip all column type translation, as we want to use whatever the parser got. |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
## Translate parsers -> PK::Auto::Foo, however |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my %parser2PK = ( |
|
33
|
|
|
|
|
|
|
MySQL => 'PK::Auto::MySQL', |
|
34
|
|
|
|
|
|
|
PostgreSQL => 'PK::Auto::Pg', |
|
35
|
|
|
|
|
|
|
DB2 => 'PK::Auto::DB2', |
|
36
|
|
|
|
|
|
|
Oracle => 'PK::Auto::Oracle', |
|
37
|
|
|
|
|
|
|
); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub dbic_produce |
|
40
|
|
|
|
|
|
|
{ |
|
41
|
3
|
|
|
3
|
0
|
11
|
my ($translator) = @_; |
|
42
|
3
|
|
|
|
|
68
|
my $no_comments = $translator->no_comments; |
|
43
|
3
|
|
|
|
|
91
|
my $add_drop_table = $translator->add_drop_table; |
|
44
|
3
|
|
|
|
|
70
|
my $schema = $translator->schema; |
|
45
|
3
|
|
|
|
|
126
|
my $output = ''; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Steal the XML producers "prefix" arg for our namespace? |
|
48
|
|
|
|
|
|
|
my $dbixschema = $translator->producer_args()->{prefix} || |
|
49
|
3
|
|
50
|
|
|
64
|
$schema->name || 'My::Schema'; |
|
50
|
3
|
|
50
|
|
|
155
|
my $pkclass = $parser2PK{$translator->parser_type} || ''; |
|
51
|
|
|
|
|
|
|
|
|
52
|
3
|
|
|
|
|
115
|
my %tt_vars = (); |
|
53
|
3
|
|
|
|
|
12
|
$tt_vars{dbixschema} = $dbixschema; |
|
54
|
3
|
|
|
|
|
10
|
$tt_vars{pkclass} = $pkclass; |
|
55
|
|
|
|
|
|
|
|
|
56
|
3
|
|
|
|
|
15
|
my $schemaoutput .= << "DATA"; |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
package ${dbixschema}; |
|
59
|
|
|
|
|
|
|
use base 'DBIx::Class::Schema'; |
|
60
|
|
|
|
|
|
|
use strict; |
|
61
|
|
|
|
|
|
|
use warnings; |
|
62
|
|
|
|
|
|
|
DATA |
|
63
|
|
|
|
|
|
|
|
|
64
|
3
|
|
|
|
|
7
|
my %tableoutput = (); |
|
65
|
3
|
|
|
|
|
7
|
my %tableextras = (); |
|
66
|
3
|
|
|
|
|
20
|
foreach my $table ($schema->get_tables) |
|
67
|
|
|
|
|
|
|
{ |
|
68
|
10
|
|
|
|
|
1383
|
my $tname = $table->name; |
|
69
|
10
|
|
|
|
|
961
|
my $output .= qq{ |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
package ${dbixschema}::${tname}; |
|
72
|
|
|
|
|
|
|
use base 'DBIx::Class'; |
|
73
|
|
|
|
|
|
|
use strict; |
|
74
|
|
|
|
|
|
|
use warnings; |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__PACKAGE__->load_components(qw/${pkclass} Core/); |
|
77
|
|
|
|
|
|
|
__PACKAGE__->table('${tname}'); |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
}; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my @fields = map |
|
82
|
|
|
|
|
|
|
{ |
|
83
|
10
|
|
|
|
|
42
|
{ $_->name => { |
|
84
|
|
|
|
|
|
|
name => $_->name, |
|
85
|
|
|
|
|
|
|
is_auto_increment => $_->is_auto_increment, |
|
86
|
|
|
|
|
|
|
is_foreign_key => $_->is_foreign_key, |
|
87
|
|
|
|
|
|
|
is_nullable => $_->is_nullable, |
|
88
|
|
|
|
|
|
|
default_value => $_->default_value, |
|
89
|
|
|
|
|
|
|
data_type => $_->data_type, |
|
90
|
|
|
|
|
|
|
size => $_->size, |
|
91
|
71
|
50
|
|
|
|
78880
|
($_->{extra} ? (extra => $_->{extra}) : ()), |
|
92
|
|
|
|
|
|
|
} } |
|
93
|
|
|
|
|
|
|
} ($table->get_fields); |
|
94
|
|
|
|
|
|
|
|
|
95
|
10
|
|
|
|
|
17718
|
$output .= "\n__PACKAGE__->add_columns("; |
|
96
|
10
|
|
|
|
|
31
|
foreach my $f (@fields) |
|
97
|
|
|
|
|
|
|
{ |
|
98
|
71
|
|
|
|
|
117
|
local $Data::Dumper::Terse = 1; |
|
99
|
71
|
|
|
|
|
190
|
$output .= "\n '" . (keys %$f)[0] . "' => " ; |
|
100
|
71
|
|
|
|
|
285
|
my $colinfo = |
|
101
|
|
|
|
|
|
|
Data::Dumper->Dump([values %$f], |
|
102
|
|
|
|
|
|
|
[''] # keys %$f] |
|
103
|
|
|
|
|
|
|
); |
|
104
|
71
|
|
|
|
|
4062
|
chomp($colinfo); |
|
105
|
71
|
|
|
|
|
171
|
$output .= $colinfo . ","; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
10
|
|
|
|
|
24
|
$output .= "\n);\n"; |
|
108
|
|
|
|
|
|
|
|
|
109
|
10
|
|
|
|
|
36
|
my $pk = $table->primary_key; |
|
110
|
10
|
50
|
|
|
|
1793
|
if($pk) |
|
111
|
|
|
|
|
|
|
{ |
|
112
|
10
|
|
|
|
|
35
|
my @pk = map { $_->name } ($pk->fields); |
|
|
10
|
|
|
|
|
3453
|
|
|
113
|
10
|
|
|
|
|
1017
|
$output .= "__PACKAGE__->set_primary_key("; |
|
114
|
10
|
|
|
|
|
56
|
$output .= "'" . join("', '", @pk) . "');\n"; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
10
|
|
|
|
|
92
|
foreach my $cont ($table->get_constraints) |
|
118
|
|
|
|
|
|
|
{ |
|
119
|
|
|
|
|
|
|
# print Data::Dumper::Dumper($cont->type); |
|
120
|
17
|
100
|
|
|
|
1128
|
if($cont->type =~ /foreign key/i) |
|
121
|
|
|
|
|
|
|
{ |
|
122
|
|
|
|
|
|
|
# $output .= "\n__PACKAGE__->belongs_to('" . |
|
123
|
|
|
|
|
|
|
# $cont->fields->[0]->name . "', '" . |
|
124
|
|
|
|
|
|
|
# "${dbixschema}::" . $cont->reference_table . "');\n"; |
|
125
|
|
|
|
|
|
|
|
|
126
|
5
|
|
|
|
|
513
|
$tableextras{$table->name} .= "\n__PACKAGE__->belongs_to('" . |
|
127
|
|
|
|
|
|
|
$cont->fields->[0]->name . "', '" . |
|
128
|
|
|
|
|
|
|
"${dbixschema}::" . $cont->reference_table . "');\n"; |
|
129
|
|
|
|
|
|
|
|
|
130
|
5
|
|
|
|
|
2650
|
my $other = "\n__PACKAGE__->has_many('" . |
|
131
|
|
|
|
|
|
|
$table->name. "', '" . |
|
132
|
|
|
|
|
|
|
"${dbixschema}::" . $table->name. "', '" . |
|
133
|
|
|
|
|
|
|
$cont->fields->[0]->name . "');"; |
|
134
|
5
|
|
|
|
|
3076
|
$tableextras{$cont->reference_table} .= $other; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
10
|
|
|
|
|
679
|
$tableoutput{$table->name} .= $output; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
3
|
|
|
|
|
342
|
foreach my $to (keys %tableoutput) |
|
142
|
|
|
|
|
|
|
{ |
|
143
|
10
|
|
|
|
|
54
|
$output .= $tableoutput{$to}; |
|
144
|
10
|
|
|
|
|
39
|
$schemaoutput .= "\n__PACKAGE__->register_class('${to}', '${dbixschema}::${to}');\n"; |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
3
|
|
|
|
|
13
|
foreach my $te (keys %tableextras) |
|
148
|
|
|
|
|
|
|
{ |
|
149
|
8
|
|
|
|
|
27
|
$output .= "\npackage ${dbixschema}::$te;\n"; |
|
150
|
8
|
|
|
|
|
22
|
$output .= $tableextras{$te} . "\n"; |
|
151
|
|
|
|
|
|
|
# $tableoutput{$te} .= $tableextras{$te} . "\n"; |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# print "$output\n"; |
|
155
|
3
|
|
|
|
|
80
|
return "${output}\n\n${schemaoutput}\n1;\n"; |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=encoding utf-8 |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 NAME |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
SQL::Translator::Producer::GraphQL - GraphQL schema producer for SQL::Translator |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=begin markdown |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
# PROJECT STATUS |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
| OS | Build status | |
|
170
|
|
|
|
|
|
|
|:-------:|--------------:| |
|
171
|
|
|
|
|
|
|
| Linux | [](https://travis-ci.org/graphql-perl/SQL-Translator-Producer-GraphQL) | |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
[](https://metacpan.org/pod/SQL::Translator::Producer::GraphQL) |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=end markdown |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
use SQL::Translator; |
|
180
|
|
|
|
|
|
|
use SQL::Translator::Producer::GraphQL; |
|
181
|
|
|
|
|
|
|
my $t = SQL::Translator->new( parser => '...' ); |
|
182
|
|
|
|
|
|
|
$t->producer('GraphQL'); |
|
183
|
|
|
|
|
|
|
$t->translate; |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
This module will produce a L<GraphQL::Schema> from the given |
|
188
|
|
|
|
|
|
|
L<SQL::Translator::Schema>. It does this by first |
|
189
|
|
|
|
|
|
|
turning it into a L<DBIx::Class::Schema> using |
|
190
|
|
|
|
|
|
|
L<SQL::Translator::Producer::DBIx::Class::File>, then passing it to |
|
191
|
|
|
|
|
|
|
L<GraphQL::Plugin::Convert::DBIC/to_graphql>. |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 ARGUMENTS |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Currently none. |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 DEBUGGING |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
To debug, set environment variable C<GRAPHQL_DEBUG> to a true value. |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 AUTHOR |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Ed J, C<< <etj at cpan.org> >> |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Based heavily on L<SQL::Translator::Producer::DBIxSchemaDSL>. |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head1 LICENSE |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Copyright (C) Ed J |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
212
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=cut |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
1; |