4
4
from io import UnsupportedOperation
5
5
6
6
import yaml
7
- from modules .utils import *
7
+ from utils .utils import *
8
8
9
9
string_transforms = {
10
10
'uppercase' : uppercase ,
@@ -35,7 +35,6 @@ def cmd(args):
35
35
for file in files :
36
36
with open (file , 'r' ) as f :
37
37
schema_string += f .read () + '\n '
38
-
39
38
schema = build_schema (schema_string )
40
39
41
40
# run
@@ -60,22 +59,19 @@ def run(schema: GraphQLSchema, config: dict):
60
59
61
60
# API generation
62
61
if config .get ('generation' ):
63
- # check if DateTime exists or should be added
64
- if config .get ('generation' ).get ('field_for_creation_date' ):
65
- datetime_control (schema )
66
-
67
- # add query type
68
62
if config .get ('generation' ).get ('add_query_type' ):
69
63
schema = add_query_type (schema )
70
-
71
- # add mutation type
72
64
if config .get ('generation' ).get ('add_mutation_type' ):
73
65
schema = add_mutation_type (schema )
74
66
75
67
# add id
76
68
if config .get ('generation' ).get ('field_for_id' ):
77
69
schema = add_id_to_types (schema )
78
70
71
+ # check if DateTime exists, or should be added
72
+ if config .get ('generation' ).get ('generate_datetime' ):
73
+ datetime_control (schema )
74
+
79
75
# add reverse edges for traversal
80
76
if config .get ('generation' ).get ('reverse_edges' ):
81
77
schema = add_reverse_edges (schema )
@@ -97,11 +93,9 @@ def run(schema: GraphQLSchema, config: dict):
97
93
# add queries
98
94
if config .get ('generation' ).get ('query_by_id' ):
99
95
schema = add_get_queries (schema )
100
-
101
- # add filters
102
96
if config .get ('generation' ).get ('query_type_filter' ) or config .get ('generation' ).get ('query_list_of' ):
103
97
schema = add_enum_filters (schema )
104
- schema = add_scalar_filters (schema )
98
+ schema = add_scalar_filters (schema , config )
105
99
schema = add_type_filters (schema )
106
100
107
101
if config .get ('generation' ).get ('query_type_filter' ):
@@ -150,6 +144,7 @@ def run(schema: GraphQLSchema, config: dict):
150
144
151
145
152
146
def validate_names (schema : GraphQLSchema , validate ):
147
+
153
148
# types and interfaces
154
149
if validate .get ('type_names' ):
155
150
# type names
@@ -191,6 +186,7 @@ def validate_names(schema: GraphQLSchema, validate):
191
186
192
187
193
188
def transform_names (schema : GraphQLSchema , transform ):
189
+
194
190
# types and interfaces
195
191
if transform .get ('type_names' ):
196
192
if transform .get ('type_names' ) in string_transforms :
@@ -218,7 +214,7 @@ def transform_names(schema: GraphQLSchema, transform):
218
214
219
215
220
216
def transform_types (schema , transform ):
221
- type_names = set (schema .type_map .keys ())
217
+ type_names = list (schema .type_map .keys ())
222
218
for type_name in type_names :
223
219
_type = schema .type_map [type_name ]
224
220
if type_name .startswith ('_' ) or is_scalar_type (_type ):
@@ -232,7 +228,7 @@ def transform_fields(schema, transform):
232
228
for _type in schema .type_map .values ():
233
229
if _type .name .startswith ('_' ) or is_scalar_type (_type ) or is_enum_type (_type ):
234
230
continue
235
- field_names = set (_type .fields .keys ())
231
+ field_names = list (_type .fields .keys ())
236
232
for field_name in field_names :
237
233
if field_name .startswith ('_' ):
238
234
continue
@@ -246,7 +242,7 @@ def transform_enums(schema, transform):
246
242
if _type .name .startswith ('_' ) or not is_enum_type (_type ):
247
243
continue
248
244
249
- enum_values_names = set (_type .values .keys ())
245
+ enum_values_names = list (_type .values .keys ())
250
246
for i in enum_values_names :
251
247
enum_value = _type .values [i ]
252
248
_type .values .pop (i )
@@ -267,12 +263,12 @@ def drop_comments(schema):
267
263
268
264
269
265
def datetime_control (schema ):
270
- type_names = set (schema .type_map .keys ())
266
+ type_names = list (schema .type_map .keys ())
271
267
if 'DateTime' in type_names :
272
268
if not is_scalar_type (schema .type_map ['DateTime' ]):
273
269
raise Exception ('DateTime exists but is not scalar type: ' + schema .type_map ['DateTime' ])
274
270
else :
275
- schema .type_map ['DateTime' ] = GraphQLScalarType ('DateTime' , serialize = lambda x : str ( x ) )
271
+ schema .type_map ['DateTime' ] = GraphQLScalarType ('DateTime' )
276
272
if not is_scalar_type (schema .type_map ['DateTime' ]):
277
273
raise Exception ('DateTime could not be added as scalar!' )
278
274
@@ -282,9 +278,10 @@ def datetime_control(schema):
282
278
parser .add_argument ('--input' , type = str , required = True ,
283
279
help = 'GraphQL DB schema files (separated by commas), or a path to a schema directory' )
284
280
parser .add_argument ('--output' , type = str ,
285
- help = 'Output schema file (optional )' )
281
+ help = 'Output schema file (default stdout )' )
286
282
parser .add_argument ('--config' , type = str ,
287
283
help = 'Path to configuration file' )
284
+
288
285
cmd (parser .parse_args ())
289
286
290
287
0 commit comments