Skip to content

Commit 5bd690a

Browse files
committed
handle mysql-style enums too
1 parent 83d42e8 commit 5bd690a

File tree

5 files changed

+136
-3
lines changed

5 files changed

+136
-3
lines changed

MANIFEST

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ t/03-sqlread.t
1212
t/lib-dbicschema/Schema.pm
1313
t/lib-dbicschema/Schema/Result/Blog.pm
1414
t/lib-dbicschema/Schema/Result/BlogTag.pm
15+
t/lib-dbicschema/Schema/Result/Mysql.pm
1516
t/lib-dbicschema/Schema/Result/Pg.pm
1617
t/lib-dbicschema/Schema/Result/Photo.pm
1718
t/lib-dbicschema/Schema/Result/Photoset.pm

lib/GraphQL/Plugin/Convert/DBIC.pm

+5-3
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,13 @@ my %TYPEMAP = (
102102
} @{ $GRAPHQL_TYPE2SQLS{$gql_type} }
103103
} keys %GRAPHQL_TYPE2SQLS),
104104
enum => sub {
105-
my $info = shift;
105+
my ($source, $column, $info) = @_;
106106
my $extra = $info->{extra};
107107
return {
108108
kind => 'enum',
109-
name => _dbicsource2pretty($extra->{custom_type_name}),
109+
name => _dbicsource2pretty(
110+
$extra->{custom_type_name} || "${source}_$column"
111+
),
110112
values => { map { _trim_name($_) => { value => $_ } } @{ $extra->{list} } },
111113
}
112114
},
@@ -252,7 +254,7 @@ sub to_graphql {
252254
DEBUG and _debug("schema_dbic2graphql($name.col)", $column, $info);
253255
my $rawtype = $TYPEMAP{ lc $info->{data_type} };
254256
if ( 'CODE' eq ref $rawtype ) {
255-
my $col_spec = $rawtype->($info);
257+
my $col_spec = $rawtype->($name, $column, $info);
256258
push @ast, $col_spec unless $seentype{$col_spec->{name}};
257259
$rawtype = $col_spec->{name};
258260
$seentype{$col_spec->{name}} = 1;
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use utf8;
2+
package Schema::Result::Mysql;
3+
4+
# to test Mysql-style enum
5+
6+
use strict;
7+
use warnings;
8+
9+
use base 'DBIx::Class::Core';
10+
__PACKAGE__->load_components("InflateColumn::DateTime");
11+
__PACKAGE__->table("mysql");
12+
__PACKAGE__->add_columns(
13+
"id",
14+
{ data_type => "uuid", is_nullable => 0 },
15+
"enum_column",
16+
{
17+
data_type => "enum",
18+
extra => { list => ["foo", "bar", "baz space"] },
19+
is_nullable => 0,
20+
},
21+
"timestamp_with_tz",
22+
{ data_type => "timestamp with time zone", is_nullable => 1 },
23+
"timestamp_without_tz",
24+
{ data_type => "timestamp without time zone", is_nullable => 0 },
25+
"another_enum_column",
26+
{
27+
data_type => "enum",
28+
extra => { list => ["foo", "bar", "baz space"] },
29+
is_nullable => 0,
30+
},
31+
);
32+
__PACKAGE__->set_primary_key("id");
33+
34+
1;

t/snapshots/01-dbicschema_t/schema

+48
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,66 @@ enum CustomType {
6767
type Mutation {
6868
createBlog(input: [BlogCreateInput!]!): [Blog]
6969
createBlogTag(input: [BlogTagCreateInput!]!): [BlogTag]
70+
createMysql(input: [MysqlCreateInput!]!): [Mysql]
7071
createPg(input: [PgCreateInput!]!): [Pg]
7172
createPhoto(input: [PhotoCreateInput!]!): [Photo]
7273
createPhotoset(input: [PhotosetCreateInput!]!): [Photoset]
7374
deleteBlog(input: [BlogMutateInput!]!): [Boolean]
7475
deleteBlogTag(input: [BlogTagMutateInput!]!): [Boolean]
76+
deleteMysql(input: [MysqlMutateInput!]!): [Boolean]
7577
deletePg(input: [PgMutateInput!]!): [Boolean]
7678
deletePhoto(input: [PhotoMutateInput!]!): [Boolean]
7779
deletePhotoset(input: [PhotosetMutateInput!]!): [Boolean]
7880
updateBlog(input: [BlogMutateInput!]!): [Blog]
7981
updateBlogTag(input: [BlogTagMutateInput!]!): [BlogTag]
82+
updateMysql(input: [MysqlMutateInput!]!): [Mysql]
8083
updatePg(input: [PgMutateInput!]!): [Pg]
8184
updatePhoto(input: [PhotoMutateInput!]!): [Photo]
8285
updatePhotoset(input: [PhotosetMutateInput!]!): [Photoset]
8386
}
8487

88+
type Mysql {
89+
another_enum_column: MysqlAnotherEnumColumn!
90+
enum_column: MysqlEnumColumn!
91+
id: String!
92+
timestamp_with_tz: DateTime
93+
timestamp_without_tz: DateTime!
94+
}
95+
96+
enum MysqlAnotherEnumColumn {
97+
bar
98+
baz_space
99+
foo
100+
}
101+
102+
input MysqlCreateInput {
103+
another_enum_column: MysqlAnotherEnumColumn!
104+
enum_column: MysqlEnumColumn!
105+
timestamp_with_tz: DateTime
106+
timestamp_without_tz: DateTime!
107+
}
108+
109+
enum MysqlEnumColumn {
110+
bar
111+
baz_space
112+
foo
113+
}
114+
115+
input MysqlMutateInput {
116+
another_enum_column: MysqlAnotherEnumColumn
117+
enum_column: MysqlEnumColumn
118+
id: String!
119+
timestamp_with_tz: DateTime
120+
timestamp_without_tz: DateTime
121+
}
122+
123+
input MysqlSearchInput {
124+
another_enum_column: MysqlAnotherEnumColumn
125+
enum_column: MysqlEnumColumn
126+
timestamp_with_tz: DateTime
127+
timestamp_without_tz: DateTime
128+
}
129+
85130
type Pg {
86131
another_enum_column: CustomType!
87132
enum_column: CustomType!
@@ -279,6 +324,7 @@ input PhotosetSearchInput {
279324
type Query {
280325
blog(id: [Int!]!): [Blog]
281326
blogTag(id: [Int!]!): [BlogTag]
327+
mysql(id: [String!]!): [Mysql]
282328
pg(id: [String!]!): [Pg]
283329
photo(id: [String!]!): [Photo]
284330
photoset(id: [String!]!): [Photoset]
@@ -287,6 +333,8 @@ type Query {
287333
"input to search"
288334
searchBlogTag(input: BlogTagSearchInput!): [BlogTag]
289335
"input to search"
336+
searchMysql(input: MysqlSearchInput!): [Mysql]
337+
"input to search"
290338
searchPg(input: PgSearchInput!): [Pg]
291339
"input to search"
292340
searchPhoto(input: PhotoSearchInput!): [Photo]

t/snapshots/01-dbicschema_t/schema_simple

+48
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,66 @@ enum CustomType {
6666
type Mutation {
6767
createBlog(input: [BlogCreateInput!]!): [Blog]
6868
createBlogTag(input: [BlogTagCreateInput!]!): [BlogTag]
69+
createMysql(input: [MysqlCreateInput!]!): [Mysql]
6970
createPg(input: [PgCreateInput!]!): [Pg]
7071
createPhoto(input: [PhotoCreateInput!]!): [Photo]
7172
createPhotoset(input: [PhotosetCreateInput!]!): [Photoset]
7273
deleteBlog(input: [BlogMutateInput!]!): [Boolean]
7374
deleteBlogTag(input: [BlogTagMutateInput!]!): [Boolean]
75+
deleteMysql(input: [MysqlMutateInput!]!): [Boolean]
7476
deletePg(input: [PgMutateInput!]!): [Boolean]
7577
deletePhoto(input: [PhotoMutateInput!]!): [Boolean]
7678
deletePhotoset(input: [PhotosetMutateInput!]!): [Boolean]
7779
updateBlog(input: [BlogMutateInput!]!): [Blog]
7880
updateBlogTag(input: [BlogTagMutateInput!]!): [BlogTag]
81+
updateMysql(input: [MysqlMutateInput!]!): [Mysql]
7982
updatePg(input: [PgMutateInput!]!): [Pg]
8083
updatePhoto(input: [PhotoMutateInput!]!): [Photo]
8184
updatePhotoset(input: [PhotosetMutateInput!]!): [Photoset]
8285
}
8386

87+
type Mysql {
88+
another_enum_column: MysqlAnotherEnumColumn!
89+
enum_column: MysqlEnumColumn!
90+
id: String!
91+
timestamp_with_tz: DateTime
92+
timestamp_without_tz: DateTime!
93+
}
94+
95+
enum MysqlAnotherEnumColumn {
96+
bar
97+
baz_space
98+
foo
99+
}
100+
101+
input MysqlCreateInput {
102+
another_enum_column: MysqlAnotherEnumColumn!
103+
enum_column: MysqlEnumColumn!
104+
timestamp_with_tz: DateTime
105+
timestamp_without_tz: DateTime!
106+
}
107+
108+
enum MysqlEnumColumn {
109+
bar
110+
baz_space
111+
foo
112+
}
113+
114+
input MysqlMutateInput {
115+
another_enum_column: MysqlAnotherEnumColumn
116+
enum_column: MysqlEnumColumn
117+
id: String!
118+
timestamp_with_tz: DateTime
119+
timestamp_without_tz: DateTime
120+
}
121+
122+
input MysqlSearchInput {
123+
another_enum_column: MysqlAnotherEnumColumn
124+
enum_column: MysqlEnumColumn
125+
timestamp_with_tz: DateTime
126+
timestamp_without_tz: DateTime
127+
}
128+
84129
type Pg {
85130
another_enum_column: CustomType!
86131
enum_column: CustomType!
@@ -276,6 +321,7 @@ input PhotosetSearchInput {
276321
type Query {
277322
blog(id: [Int!]!): [Blog]
278323
blogTag(id: [Int!]!): [BlogTag]
324+
mysql(id: [String!]!): [Mysql]
279325
pg(id: [String!]!): [Pg]
280326
photo(id: [String!]!): [Photo]
281327
photoset(id: [String!]!): [Photoset]
@@ -284,6 +330,8 @@ type Query {
284330
"input to search"
285331
searchBlogTag(input: BlogTagSearchInput!): [BlogTag]
286332
"input to search"
333+
searchMysql(input: MysqlSearchInput!): [Mysql]
334+
"input to search"
287335
searchPg(input: PgSearchInput!): [Pg]
288336
"input to search"
289337
searchPhoto(input: PhotoSearchInput!): [Photo]

0 commit comments

Comments
 (0)