graphql-request
graphql-request copied to clipboard
Add agent to client constructor options
It looks like there's some hangup around adding an agent property to the constructor options, but I'm not sure I entirely understand it.
For instance, Fredy C commented in https://github.com/prisma/graphql-request/issues/84 that:
I guess that my concern is about importing https module which would work fine in node environment, but when building eg. with Webpack, it would suddenly force users to somehow mock that module. From my experience even using inline require does not work because Webpack will see it.
However, if you like at the typings for the request module, they're doing the same thing so I'm not sure what the hangup is?
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/request/index.d.ts#L21
ping @schickling as I recently ran into this issue again and found my own issue here while debugging :)
Hello! I'd like to bump @schickling and/or @jjangga0214 to check out this PR, as this fixes a problem within an upstream dependency of ours.
I did a writeup of the bug that's happening here: https://gitlab.com/groups/gitlab-org/-/epics/6244#note_615087584
It would be amazing to have this fix merged in, which allows anyone using a self-signed cert to make the proper requests via an https.Agent. Thank you.
This would fix #41 as well.
Sorry for the radio silence from my end. Unfortunately I currently don't have the capacity to maintain this library but given that @jjangga0214 seems to have been active here recently I hope they can carry this PR forward. 🙏
@Gocnak @schickling Yes I think I can contribute :)
By the way, we are using cross-fetch under the hood, but it doesn't provide an agent option. So we can consider...
1. Replacing it to a non-compatible new library.
For example axios provides httpAgent and httpsAgent options.
However, that can be a breaking change, especially as we allow users to pass the fetch-compatible function.
https://github.com/prisma-labs/graphql-request/blob/c544c5f72942d23668aad6819257521c804f035f/src/types.dom.ts#L297
If needed, in order to avoid such a breaking change, we might still leave the option as-is, and
A. Using axios as default, fetch only when it is passed (and throw an error if agent and fetch are both given)
or
B. Using fetch as default, axios only when agent is passed.
Many parts of our code would need to be refactored, and some PRs waiting(pending) will become invalid.
2. Creating a slightly modified library, fetch-compatible except optionally allowing agent option.
For instance, we can modify cross-fetch a little bit, as it uses node-fetch on nodejs env, and node-fetch allows the agent option (though it is not standard whatwg-fetch spec).
In my humble opinion, I feel OK with such refactoring, but I want to also hear peoples' opinions first (especially @schickling @jasonkuhrt).