shurcooL / graphql

Package graphql provides a GraphQL client implementation.
MIT License
704 stars 280 forks source link

Allow providing a custom request factory #73

Open andig opened 3 years ago

andig commented 3 years ago

This PR allows customizing the requests sent for APIs that require additional headers.

Replace #47, #48, #49, https://github.com/shurcooL/graphql/pull/64, #68.

This is not the most beautiful solution but offers the highest amount of customizing the request with the least amount of added lines of code. Making the request factory a private member and optional NewClient parameter would be a further option.

/cc @dmitshur

fi0 commented 3 years ago

how do I provide my own request factory?

andig commented 3 years ago

I've kept it simple. After creating the client you would simply replace client.RequestFactory with a custom func(method, url string, body io.Reader) (*http.Request, error).

andig commented 1 year ago

Ping @dmitshur