Skip to content

Instantly share code, notes, and snippets.

@timelf123
Created March 31, 2023 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timelf123/e0438314b4e67937e3364e67d71304bd to your computer and use it in GitHub Desktop.
Save timelf123/e0438314b4e67937e3364e67d71304bd to your computer and use it in GitHub Desktop.
mitmdump -s capture-graphql.py
# mitmdump -s capture-graphql.py
import json
import re
from mitmproxy import http
def response(flow: http.HTTPFlow) -> None:
if flow.request.url.endswith('/graphql'):
payload = json.loads(flow.request.content.decode('utf-8'))
filename = re.sub(r'[^a-zA-Z0-9]', '_', payload['operationName']) + '.graphql.txt'
with open(filename, 'w') as f:
json.dump(payload, fp=f, indent=2)
f.write(f"\n\n// ==== REQUEST ====\n\n")
f.write(f"{payload['query']}\n\n")
f.write("// ==== RESPONSE ====\n\n")
json.dump(json.loads(flow.response.content), fp=f, indent=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment