Allow the definition of a custom json serializer
Closed this issue · 3 comments
Basically, I want to be able to do something like
Client(serializer=orjson.loads, deserializer=orjson.dumps)
The aiohttp.ClientSession
allows for custom serialization so it shouldn't be an hard implementation?
https://docs.aiohttp.org/en/stable/client_reference.html
There was a previous discussion about this in issue #216
The main use case was custom scalars serialization and is solved with the current version of gql so it was closed, but I can see there are other uses for this.
The arguments should be set in the transports and not in the Client
though.
Feel free to submit a PR with tests.
I looked a bit more about this issue and found out that it is actually possible right now.
you can provide a client_session_args
argument to the AIOHTTPTransport
with any additional argument which need to be passed to aiohttp.ClientSession
, including the json_serialize
arg:
transport = AIOHTTPTransport(url=url, client_session_args={"json_serialize": json.dumps})
There are still json.dumps
calls elsewhere in the transport used for:
- logging
- file uploads
- appsync headers
In the PR #337 I modified the transport to be simplify it. It can be used like this now:
transport = AIOHTTPTransport(url=url, json_serialize=json.dumps)