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.28k stars 748 forks source link

Multipart request specification support for client-side #3312

Closed tobias-tengler closed 2 years ago

tobias-tengler commented 3 years ago

Since the Multipart request specification has now been implemented on the Server-side with version 11.1.0, I think it would be nice if StrawberryShake could take advantage of this.

Currently the Upload type is treated as a string. In my opinion there should be a new Type the user can instantiate, let's call it Uploadable for now. Which contains the (optional) Filename as a string and the Content as a Stream.

Example:

# UploadPhoto.graphql
mutation UploadPhoto($photo: Upload!) {
  uploadPhoto(photo: $photo) {
    url
  }
}

For the above operation, StrawberryShake would generate the following signature for the matching user-facing ExecuteAsync method:

Task<...> ExecuteAsync(Uploadable photo) { ... }
...
var photo = new Uploadable(stream, "Example.png");
await client.UploadPhoto.ExecuteAsync(photo);

The following MultipartFormContent would be sent to the GraphQL server:

var form = new MultipartFormDataContent();

form.Add(new StringContent("{ \"query\": \"mutation UploadPhoto($photo: Upload!) { uploadPhoto(photo: $photo) { url } }\", \"variables\": { \"photo\": null } }"), "operations");
form.Add(new StringContent("{ \"0\": [\"variables.photo\"] }"), "map");            
form.Add(new StreamContent(uploadable.Content), "0", uploadable.Filename);

List of Uploadables would be handled in a similar fashion according to the specification.

What are your thoughts?

michaelstaib commented 3 years ago

The MultiPart protocol is not supported yet. We will focus on more protocols with the June release. Same goes for defer which uses multipart in the response.

velchev commented 3 years ago

@michaelstaib What is the best alternative that can be used as a client till this feature is ready? I had a look at RestSharp and just create http request, works but is not nice solution. I am looking at other libraries and I am wondering if you can point me to the best one?

tobias-tengler commented 3 years ago

I don't think there is a C# library that covers the GraphQL multipart request specification from a client's perspective yet. Your best bet at the moment is probably either RestSharp or plain old HttpClient. :/

stale[bot] commented 2 years ago

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.