graphql-python/gql

Fails to honour HTTPS_PROXY environment variable

Closed this issue · 3 comments

Describe the bug
gql does not handle proxy usage when using the asyncio API. Other libraries such as httpx support this out of the box by honouring the HTTPS_PROXY / HTTP_PROXY environment variable.

To Reproduce

  • deploy a squid proxy.
  • set the HTTPS_PROXY variable to that corresponding proxy
  • make a graphql request to github

Expected behavior
The request goes through the proxy. We block all outgoing network requests that don't go through the proxy, so this means we get a timeout when making graphql requests.

System info (please complete the following information):

  • OS: debian
  • Python version: 3.8
  • gql version: 3.3.0
  • graphql-core version: 3.2.1

ps. Alternatively, this could be addressed by supporting async httpx.

From the aiohttp docs:

Contrary to the requests library, it won’t read environment variables by default. But you can do so by passing trust_env=True into aiohttp.ClientSession constructor for extracting proxy configuration from HTTP_PROXY, HTTPS_PROXY, WS_PROXY or WSS_PROXY environment variables (all are case insensitive)

gql allows you to pass custom parameters to the ClientSession call with the client_session_args argument of AIOHTTPTransport

So maybe something like this could work:

transport = AIOHTTPTransport(url="YOUR_URL", client_session_args={"trust_env": True})

Note: See also PR #340 for httpx support (work in progress)

huyz commented

But how would one set trust_env to True when using gql-cli? It seems we can't, which makes gql-cli unusable for me.

huyz commented

Seems to me that trust_env should be set to True by default for gql-cli since it's just a development tool and not deployed.