Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
:param type:
query, mutation, subscription
:param qname:
query, mutation, subscription names
:param content:
file content
:param mode:
w, a and so on
:return:
none
"""
with open(opath % (type, '%s.query' % qname), mode) as ofile:
ofile.write(content)
def generate(argument, fpath, custom=False, target="empty"):
"""
Generate HTML Documentation
:param argument: introspection query result
:param fpath: output result
:param custom: enable or disable custom types, disabled by default
:param target: who is the owner of that graphql endpoint
:return: None
"""
with open(fpath, 'w') as output_file:
result = argument.copy()
# Write HTML header for the documentation
# --------------------
output_file.write("<title>GraphQL Schema</title>")
# write CSS
output_file.write(stl)
# write target URL
output_file.write("<h2>GraphQL Schema</h2><h3><a href="{0}">{0}</a></h3>".format(target))
# write legend box
output_file.write(
"<div class="box"><h4>Legend</h4><ul><li class="query">Queries</li><li class="mutation">Mutations</li><"
"li class='subscription'>Subscriptions<li class="argument">Arguments</li>"
"<li class="type">Types: String, Float, not_null!, [list]</li><li class="deprecated">Deprecated</li>"
"<li class="field">Fields</li></ul></div>")
# --------------------
output_file.write("<p>Available Operations Types:</p>")
def generate(argument, fpath="introspection.json"):
"""
Generate Schema JSON
:param argument: introspection query output
:param fpath: file output
:return: None
"""
with open(fpath, "w") as schema_file:
schema_file.write(json.dumps(argument, indent=4, sort_keys=True))