aboutsummaryrefslogtreecommitdiff
path: root/source/library/graphql
diff options
context:
space:
mode:
Diffstat (limited to 'source/library/graphql')
-rw-r--r--source/library/graphql/format.ts22
1 files changed, 22 insertions, 0 deletions
diff --git a/source/library/graphql/format.ts b/source/library/graphql/format.ts
new file mode 100644
index 0000000..905e25b
--- /dev/null
+++ b/source/library/graphql/format.ts
@@ -0,0 +1,22 @@
+
+
+
+
+/*** IMPORT ------------------------------------------- ***/
+
+import { parse, print } from "graphql";
+
+/*** EXPORT ------------------------------------------- ***/
+
+export function format(query: string): string {
+ const trimmed = query.trim();
+
+ if (!trimmed)
+ return query;
+
+ try {
+ return print(parse(query));
+ } catch {
+ return query;
+ }
+}