Skip to content

Commit 0772f58

Browse files
committed
Merge branch 'master' into 41-add-resolver-function-generator
# Conflicts: # graphql-api-generator/generator.py
2 parents 6431faa + 3333210 commit 0772f58

File tree

4 files changed

+83
-45
lines changed

4 files changed

+83
-45
lines changed

graphql-api-generator/generator.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from io import UnsupportedOperation
55

66
import yaml
7-
from modules.utils import *
7+
from utils.utils import *
88

99
string_transforms = {
1010
'uppercase': uppercase,
@@ -35,7 +35,6 @@ def cmd(args):
3535
for file in files:
3636
with open(file, 'r') as f:
3737
schema_string += f.read() + '\n'
38-
3938
schema = build_schema(schema_string)
4039

4140
# run
@@ -60,22 +59,19 @@ def run(schema: GraphQLSchema, config: dict):
6059

6160
# API generation
6261
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
6862
if config.get('generation').get('add_query_type'):
6963
schema = add_query_type(schema)
70-
71-
# add mutation type
7264
if config.get('generation').get('add_mutation_type'):
7365
schema = add_mutation_type(schema)
7466

7567
# add id
7668
if config.get('generation').get('field_for_id'):
7769
schema = add_id_to_types(schema)
7870

71+
# check if DateTime exists, or should be added
72+
if config.get('generation').get('generate_datetime'):
73+
datetime_control(schema)
74+
7975
# add reverse edges for traversal
8076
if config.get('generation').get('reverse_edges'):
8177
schema = add_reverse_edges(schema)
@@ -97,11 +93,9 @@ def run(schema: GraphQLSchema, config: dict):
9793
# add queries
9894
if config.get('generation').get('query_by_id'):
9995
schema = add_get_queries(schema)
100-
101-
# add filters
10296
if config.get('generation').get('query_type_filter') or config.get('generation').get('query_list_of'):
10397
schema = add_enum_filters(schema)
104-
schema = add_scalar_filters(schema)
98+
schema = add_scalar_filters(schema, config)
10599
schema = add_type_filters(schema)
106100

107101
if config.get('generation').get('query_type_filter'):
@@ -150,6 +144,7 @@ def run(schema: GraphQLSchema, config: dict):
150144

151145

152146
def validate_names(schema: GraphQLSchema, validate):
147+
153148
# types and interfaces
154149
if validate.get('type_names'):
155150
# type names
@@ -191,6 +186,7 @@ def validate_names(schema: GraphQLSchema, validate):
191186

192187

193188
def transform_names(schema: GraphQLSchema, transform):
189+
194190
# types and interfaces
195191
if transform.get('type_names'):
196192
if transform.get('type_names') in string_transforms:
@@ -218,7 +214,7 @@ def transform_names(schema: GraphQLSchema, transform):
218214

219215

220216
def transform_types(schema, transform):
221-
type_names = set(schema.type_map.keys())
217+
type_names = list(schema.type_map.keys())
222218
for type_name in type_names:
223219
_type = schema.type_map[type_name]
224220
if type_name.startswith('_') or is_scalar_type(_type):
@@ -232,7 +228,7 @@ def transform_fields(schema, transform):
232228
for _type in schema.type_map.values():
233229
if _type.name.startswith('_') or is_scalar_type(_type) or is_enum_type(_type):
234230
continue
235-
field_names = set(_type.fields.keys())
231+
field_names = list(_type.fields.keys())
236232
for field_name in field_names:
237233
if field_name.startswith('_'):
238234
continue
@@ -246,7 +242,7 @@ def transform_enums(schema, transform):
246242
if _type.name.startswith('_') or not is_enum_type(_type):
247243
continue
248244

249-
enum_values_names = set(_type.values.keys())
245+
enum_values_names = list(_type.values.keys())
250246
for i in enum_values_names:
251247
enum_value = _type.values[i]
252248
_type.values.pop(i)
@@ -267,12 +263,12 @@ def drop_comments(schema):
267263

268264

269265
def datetime_control(schema):
270-
type_names = set(schema.type_map.keys())
266+
type_names = list(schema.type_map.keys())
271267
if 'DateTime' in type_names:
272268
if not is_scalar_type(schema.type_map['DateTime']):
273269
raise Exception('DateTime exists but is not scalar type: ' + schema.type_map['DateTime'])
274270
else:
275-
schema.type_map['DateTime'] = GraphQLScalarType('DateTime', serialize=lambda x: str(x))
271+
schema.type_map['DateTime'] = GraphQLScalarType('DateTime')
276272
if not is_scalar_type(schema.type_map['DateTime']):
277273
raise Exception('DateTime could not be added as scalar!')
278274

@@ -282,9 +278,10 @@ def datetime_control(schema):
282278
parser.add_argument('--input', type=str, required=True,
283279
help='GraphQL DB schema files (separated by commas), or a path to a schema directory')
284280
parser.add_argument('--output', type=str,
285-
help='Output schema file (optional)')
281+
help='Output schema file (default stdout)')
286282
parser.add_argument('--config', type=str,
287283
help='Path to configuration file')
284+
288285
cmd(parser.parse_args())
289286

290287

0 commit comments

Comments
 (0)