About Measuring GraphQL Performance with Requests

You can check GraphQL query performance using the requests library, as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
>>> import requests
>>> url = "https://example.com/en/graphql/"
>>> query = """
... query {
... # YOUR GRAPHQL QUERY
... }"""
>>> headers = {
...     "Authorization": "Bearer YOUR_TOKEN_HERE",
...     "Content-Type": "application/json"
... }
>>> payload = {"query": query, "variables": {}}
>>> response = requests.post(url, json=payload, headers=headers)
>>> response.elapsed
datetime.timedelta(seconds=5, microseconds=849475)
>>> response.json()
{...}

Tips and Tricks Programming Performance Django 5.x Django 4.2 Django 3.2 requests Graphene-Django GraphQL