ChilliCream / graphql-platform

Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
https://chillicream.com
MIT License
5.26k stars 745 forks source link

Be able to provide http and websocket client to strawberry shake #4754

Open kolpav opened 2 years ago

kolpav commented 2 years ago

Is your feature request related to a problem?

I am using WebApplicationFactory for integration testing which uses its own in memory http client and I have to register IHttpClientFactory to make strawberry shake to use client from web factory instead of its own client which was not straight forward. I was not able to do the same for web sockets.

The solution you'd like

Product

Strawberry Shake

Edit:

In the end I was able to provide my own web socket implementation by copy pasting web socket client from HC and hardcoding its values as implementing IWebSocketClient is not something I would be able to do.

jarlef commented 1 year ago

I think this issue can be closed. Strawberry Shake contains an extension method ConfigureHttpClient where the second parameter is the .net http client builder. This builder can be used to inject the http message handler for the test server.


 var serviceCollection = new ServiceCollection();

// overriding the strawberry shake client with the client middleware from WebApplicationFactory
serviceCollection.AddSomeClient().ConfigureHttpClient(c =>
{
    c.BaseAddress = new Uri(factory.Server.BaseAddress, "graphql");
}, c =>
{
    c.ConfigurePrimaryHttpMessageHandler(() => factory.Server.CreateHandler());
});

var client = serviceCollection.BuildServiceProvider().GetRequiredService<ISomeClient>();
kolpav commented 1 year ago

Websocket client is the one which is hard to provide your own implementation for.

rolfwessels commented 9 months ago

@kolpav would you mind sharing some code, please? I got the HttpClient working with WebApplicationFactory but I'm unable to get the WebSocket client to work.

kolpav commented 9 months ago

@rolfwessels At the time I think I just copy-pasted whatever is implementing IWebSocketClient in HC and hardcoded my own values. Even if I could find the code it would be unusable now.