Created
April 27, 2017 20:39
-
-
Save Diullei/b63aa2f8aab3486590ab7bb8534d7c2d to your computer and use it in GitHub Desktop.
Rudimentary graphql to typescript definition generator. Accepts a graphql schema file (not json, nor js) and converts it to typescript defs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
cat "$1" \ | |
| sed -r 's/^(\s*)#/\1\/\//' \ | |
| sed -r 's/!//g' \ | |
| sed -r 's/^input /export interface /g' \ | |
| sed -r 's/^enum /export enum /g' \ | |
| sed -r 's/^type /export interface /g' \ | |
| sed -r 's/^union /export type /g'\ | |
| sed -r 's/^schema /export interface schema /g' \ | |
| sed -r 's/^(\s+[a-zA-Z0-9_-]+\s*)\([^\)]+\)(\s*:\s*)/\1\2/g' \ | |
| sed -r 's/([:\=\|]\s*)\[ID!?\]!?($|\s+|\))/\1string[]\2/g' \ | |
| sed -r 's/([:\=\|]\s*)ID!?($|\s+|\))/\1string\2/g' \ | |
| sed -r 's/([:\=\|]\s*)\[String!?\]!?($|\s+|\))/\1string[]\2/g' \ | |
| sed -r 's/([:\=\|]\s*)String!?($|\s+|\))/\1string\2/g' \ | |
| sed -r 's/([:\=\|]\s*)\[Int!?\]!?($|\s+|\))/\1number[]\2/g' \ | |
| sed -r 's/([:\=\|]\s*)Int!?($|\s+|\))/\1number\2/g' \ | |
| sed -r 's/([:\=\|]\s*)\[Float!?\]!?($|\s+|\))/\1number[]\2/g' \ | |
| sed -r 's/([:\=\|]\s*)Float!?($|\s+|\))/\1number\2/g' \ | |
| sed -r 's/([:\=\|]\s*)\[Boolean!?\]!?($|\s+|\))/\1boolean[]\2/g' \ | |
| sed -r 's/([:\=\|]\s*)Boolean!?($|\s+|\))/\1boolean\2/g' \ | |
| sed -r 's/\[([a-zA-Z0-9_-]+)!?\]!?/\1[]/' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment