diff options
Diffstat (limited to 'source/library/graphql/format.ts')
| -rw-r--r-- | source/library/graphql/format.ts | 22 |
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; + } +} |