Skip to content

Commit 1f19818

Browse files
committed
simplify cli
1 parent d0b4275 commit 1f19818

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

graphql-api-generator/generator.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python3
22
import argparse
3+
import os
34
from io import UnsupportedOperation
45

56
import yaml
@@ -21,13 +22,24 @@ def cmd(args):
2122
else:
2223
config = {}
2324

24-
# concat input files
25+
# get list of schema files
26+
files = []
27+
if os.path.isdir(args.input):
28+
for filename in os.listdir(args.input):
29+
if filename.endswith(".graphql"):
30+
files.append(f'{args.input}/{filename}')
31+
else:
32+
files = args.input.split(',')
33+
34+
# build schema
2535
schema_string = ''
26-
for file in args.input.split(','):
36+
for file in files:
2737
with open(file, 'r') as f:
2838
schema_string += f.read() + '\n'
39+
schema = build_schema(schema_string)
2940

30-
schema = run(build_schema(schema_string), config)
41+
# run
42+
schema = run(schema, config)
3143

3244
# write to file or stdout
3345
if args.output:
@@ -186,11 +198,12 @@ def drop_comments(schema):
186198
if __name__ == '__main__':
187199
parser = argparse.ArgumentParser()
188200
parser.add_argument('--input', type=str, required=True,
189-
help='Input schema files (separated by commas)')
201+
help='GraphQL DB schema files (separated by commas), or a path to a schema directory')
190202
parser.add_argument('--output', type=str,
191203
help='Output schema file (default stdout)')
192204
parser.add_argument('--config', type=str,
193205
help='Path to configuration file')
206+
194207
cmd(parser.parse_args())
195208

196209

graphql-api-generator/main.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
#!/usr/bin/env python3
2-
import yaml
3-
from graphql import build_schema
4-
5-
import generator
6-
7-
config_file = './resources/config.yml'
8-
input_files = './resources/schema.graphql'
9-
10-
config = ''
11-
with open(config_file) as f:
12-
config = yaml.safe_load(f)
2+
import os
133

144
# input files
15-
schema_string = ''
16-
for file in input_files.split(','):
17-
with open(file, 'r') as f:
18-
schema_string += f.read() + '\n'
19-
20-
schema = generator.run(build_schema(schema_string), config)
21-
print(generator.print_schema(schema))
5+
os.system('python3 generator.py --input ./resources --config ./resources/config.yml')

0 commit comments

Comments
 (0)