1
1
#!/usr/bin/env python3
2
2
import argparse
3
+ import os
3
4
from io import UnsupportedOperation
4
5
5
6
import yaml
@@ -21,13 +22,24 @@ def cmd(args):
21
22
else :
22
23
config = {}
23
24
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
25
35
schema_string = ''
26
- for file in args . input . split ( ',' ) :
36
+ for file in files :
27
37
with open (file , 'r' ) as f :
28
38
schema_string += f .read () + '\n '
39
+ schema = build_schema (schema_string )
29
40
30
- schema = run (build_schema (schema_string ), config )
41
+ # run
42
+ schema = run (schema , config )
31
43
32
44
# write to file or stdout
33
45
if args .output :
@@ -186,11 +198,12 @@ def drop_comments(schema):
186
198
if __name__ == '__main__' :
187
199
parser = argparse .ArgumentParser ()
188
200
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 ' )
190
202
parser .add_argument ('--output' , type = str ,
191
203
help = 'Output schema file (default stdout)' )
192
204
parser .add_argument ('--config' , type = str ,
193
205
help = 'Path to configuration file' )
206
+
194
207
cmd (parser .parse_args ())
195
208
196
209
0 commit comments