jhnnsrs / rath

rath is an apollo-like graphql client that supports links, multipart uploads, websocket subscriptions with sync and async interface
https://jhnnsrs.github.io/rath/
MIT License
9 stars 3 forks source link

Unable to write complex variables using AIOHttpLink #7

Open strue36 opened 2 years ago

strue36 commented 2 years ago

For a GraphQL operation that uses a non-scalar input type, a pydantic model is created.

AIOHttpLink passes this model to self._session.post() which uses the default json encoder. This fails to serialize the pydantic model.

Building payload

payload["variables"] = operation.variables
post_kwargs = {"json": payload}
async with self._session.post(
    self.url, headers=operation.context.headers, **post_kwargs
) as response:

Calls this which uses the default JSONEncoder

elif json is not None:
    data = payload.JsonPayload(json, dumps=self._json_serialize)

I have created a pull request with an extended JSONEncoder which is used to handle these objects.