Skip to content

Instantly share code, notes, and snippets.

@gregxsunday
Created August 7, 2019 11:04
Show Gist options
  • Save gregxsunday/888d67f6e6e2f29bbe92cd811435c72d to your computer and use it in GitHub Desktop.
Save gregxsunday/888d67f6e6e2f29bbe92cd811435c72d to your computer and use it in GitHub Desktop.
pretty print GraphQL schema query response
schema = r.json()
print("============= [SCHEMA] ===============")
print("e.g: \033[92mname\033[0m[\033[94mType\033[0m]: arg (\033[93mType\033[0m!)\n")
for types in schema['data']['__schema']['types']:
if types['kind'] == "OBJECT":
print(types['name'])
if not "__" in types['name']:
for fields in types['fields']:
field_type = ""
try:
field_type = fields['type']['ofType']['name']
except Exception as e :
pass
print("\t\033[92m{}\033[0m[\033[94m{}\033[0m]: ".format(fields['name'], field_type), end='')
for args in fields['args']:
args_name = args.get('name')
args_tkind = ""
args_ttype = ""
try:
args_tkind = args['type']['kind']
except:
pass
try:
args_ttype = args['type']['ofType']['name']
except Exception as e:
pass
print("{} (\033[93m{}\033[0m!), ".format(args_name, args_ttype), end='')
print("")
@gregxsunday
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment