graphql-platform icon indicating copy to clipboard operation
graphql-platform copied to clipboard

StrawberrryShake Add Overload to ExecuteAsync to allow extensions to be passed.

Open MattMinke opened this issue 2 years ago • 7 comments

Is your feature request related to a problem?

A 3rd party API we are integrating with requires us to add additional headers to each request that are unique to the request and are not known when the client is registered with the service collection. Combining the suggested solution below with a custom IHttpConnection implementation that reads from the OperationRequest.Extensions will allow us to satisfy the behavior required by the 3rd party.

We can replace the IHttpConnection using this code.


branchClientBuilder.ClientServices.Replace<IHttpConnection>(ServiceLifetime.Singleton, (provider =>
{
    var clientFactory = provider.GetRequiredService<global::System.Net.Http.IHttpClientFactory>();
        return new MyCustomHttpConnection(() => clientFactory.CreateClient("BranchClient"));
}));

The solution you'd like

Add an overload to ExecuteAsync for each query that allows an extensions collection to be added to the OperationRequest

image

Product

Strawberry Shake

MattMinke avatar Jun 30 '22 22:06 MattMinke

@MattMinke you know that you can configure the http client factory? you can also configure the http client builder as the third argument of ConfigureHttpClient https://chillicream.com/docs/strawberryshake/networking/authentication#http

PascalSenn avatar Jul 05 '22 18:07 PascalSenn

Yep I am aware of that. unfortunately It does not solve the issue in our case. The value we need to add to the headers is unique per request. The client builder will let us add a header at configuration time but that is too soon. The header changes with each request and is not consistent. The header has to be calculated at request time.

With the solution I am proposing we would be able to add additional values to the request.Extensions dictionary and then access this dictionary in a custom IHttpConnection.

MattMinke avatar Jul 05 '22 21:07 MattMinke

Looks similar to #3467.

jorrit avatar Jul 08 '22 11:07 jorrit

@jorrit may be simplified example from #3467 comment should be added to documentation page

it might solve many future issues

in our case we have console kafka consumer which uses strawberry shake client so we have no http context to pass headers from but example above did work perfectly

mac2000 avatar Sep 22 '22 09:09 mac2000

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jan 20 '23 11:01 stale[bot]

This issue is currently marked as part of milestone HC-13.0.0. Please do not close this issue. I have been waiting patiently for this milestone to be complete so I can take advantage of this.

MattMinke avatar Jan 21 '23 00:01 MattMinke

as I commented in https://github.com/ChilliCream/graphql-platform/issues/6426 I would also appreciate the ability to specify custom headers per request.

danny-zegel-zocdoc avatar Aug 28 '23 12:08 danny-zegel-zocdoc

This issue is currently marked as part of milestone HC-13.0.0. Please do not close this issue. I have been waiting patiently for this milestone to be complete so I can take advantage of this. I need to pass per request custom headers milestone [HC-13.0.0] is closed .. was it done ? if yes , how do I pass per request custom headers ?

sabbadino avatar Jan 11 '24 17:01 sabbadino