Add support for client that uses GET as transport mechanism (#186)
Current implementation always uses POST as the transport mechanism. Adding GET support enables usage of GET queries for caching simply via URL. Some notes: - I left the existing API for creating a new client as is, but the implementation could be much cleaner by introducing some sort of configuration struct when creating a new client - The construction of the query parameters follows the logic from Apollo's client implementation, which can be found here https://github.com/apollographql/apollo-client/blob/8beb4820edc6352996e08f7f73bde3573f1eb666/src/link/http/rewriteURIForGET.ts - Updated integration tests to use both sets of clients. Updating the tests to use a test suite would be cleaner
This commit is contained in:
@@ -101,10 +101,25 @@ func (c *roundtripClient) MakeRequest(ctx context.Context, req *graphql.Request,
|
||||
return nil
|
||||
}
|
||||
|
||||
func newRoundtripClients(t *testing.T, endpoint string) []graphql.Client {
|
||||
return []graphql.Client{newRoundtripClient(t, endpoint), newRoundtripGetClient(t, endpoint)}
|
||||
}
|
||||
|
||||
func newRoundtripClient(t *testing.T, endpoint string) graphql.Client {
|
||||
transport := &lastResponseTransport{wrapped: http.DefaultTransport}
|
||||
httpClient := &http.Client{Transport: transport}
|
||||
return &roundtripClient{
|
||||
wrapped: graphql.NewClient(endpoint, &http.Client{Transport: transport}),
|
||||
wrapped: graphql.NewClient(endpoint, httpClient),
|
||||
transport: transport,
|
||||
t: t,
|
||||
}
|
||||
}
|
||||
|
||||
func newRoundtripGetClient(t *testing.T, endpoint string) graphql.Client {
|
||||
transport := &lastResponseTransport{wrapped: http.DefaultTransport}
|
||||
httpClient := &http.Client{Transport: transport}
|
||||
return &roundtripClient{
|
||||
wrapped: graphql.NewClientUsingGet(endpoint, httpClient),
|
||||
transport: transport,
|
||||
t: t,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user