-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgraphql_to_reason.re
59 lines (52 loc) · 1.39 KB
/
graphql_to_reason.re
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
open Core;
let json_file_path =
Command.Spec.Arg_type.create(filename =>
switch (Sys.is_file(filename)) {
| `Yes =>
switch (Caml.Filename.extension(filename)) {
| ".json" => filename
| _ =>
eprintf("'%s' is not a json file.\n%!", filename);
exit(1);
}
| `No
| `Unknown =>
eprintf("'%s' is not a regular file.\n%!", filename);
exit(1);
}
);
let output = (~outputFiles, ~result) => {
let (formatter, oc) =
switch (outputFiles) {
| [target, ..._rest] =>
let oc = Out_channel.create(target);
(Format.formatter_of_out_channel(oc), Some(oc));
| _ => (Format.std_formatter, None)
};
Reason_toolchain.RE.print_implementation_with_comments(formatter, result);
Format.print_flush();
switch (oc) {
| Some(oc) => Out_channel.close(oc)
| None => ()
};
};
let fromFile =
Command.Let_syntax.(
Command.basic(
~summary="generate reason types from graphql_schema.json",
{
let%map_open filepath = anon("filepath" %: json_file_path)
and outputFiles = anon(sequence("output_path" %: file));
() => {
let result =
Lib.(
SchemaRead.File(filepath)
|> SchemaRead.read
|> SchemaPrint.print
);
output(~outputFiles, ~result);
};
},
)
);
Command.run(~build_info="", fromFile);