ariadne-codegen icon indicating copy to clipboard operation
ariadne-codegen copied to clipboard

Difficulty getting non-data "extensions" info from response

Open johnhainline opened this issue 1 year ago • 0 comments

So, the GraphQL spec apparently includes an optional section in responses called "extensions". https://spec.graphql.org/October2021/#sec-Response-Format So some implementations may return important data outside the {"data": ...} field in a response. Specifically, Shopify responds with

{
    "data": ...,
    "extensions": {
        "cost": {
            "requestedQueryCost": 65,
            "actualQueryCost": 16,
            "throttleStatus": {
                "maximumAvailable": 2000.0,
                "currentlyAvailable": 1984,
                "restoreRate": 100.0
            }
        }
    }
}

to provide meta information on a request throttling scheme that Shopify uses. Unfortunately I can see no easy way of getting this information when using ariadne-codegen to generate requests. A plugin can fix this by re-writing all the return values from generate_client_method, but would you all consider an optional return value for this extensions dictionary? (in a hacky plugin I have the generated client.py returning Tuple[MyShopifyResponseType, Optional[Dict[str, Any]]] on every function) Or perhaps some other mechanism for easy access to this data in responses?

Thanks for your time, and I love the library!

johnhainline avatar Mar 13 '24 14:03 johnhainline