summaryrefslogtreecommitdiff
path: root/hack/graphql_to_header.py
diff options
context:
space:
mode:
Diffstat (limited to 'hack/graphql_to_header.py')
-rw-r--r--hack/graphql_to_header.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/hack/graphql_to_header.py b/hack/graphql_to_header.py
new file mode 100644
index 0000000..da0107d
--- /dev/null
+++ b/hack/graphql_to_header.py
@@ -0,0 +1,26 @@
+import sys
+from pathlib import Path
+
+input_path = Path(sys.argv[1])
+output_path = Path(sys.argv[2])
+var_name = sys.argv[3]
+
+with input_path.open() as f:
+ lines = f.readlines()
+
+with output_path.open("w") as f:
+ f.write(
+ f'''#ifndef QUERIES_{var_name.upper()}_H
+#define QUERIES_{var_name.upper()}_H
+
+'''
+ )
+ f.write(f'const char *{var_name} =\n')
+ for line in lines:
+ escaped = line.rstrip('\n').replace('\\', '\\\\').replace('"', '\\"')
+ f.write(f' "{escaped}\\n"\n')
+ f.write(';\n')
+ f.write(
+ f'''
+#endif // QUERIES_{var_name.upper()}_H
+''')