bramble icon indicating copy to clipboard operation
bramble copied to clipboard

Request syntax error while trying to upload file

Open timspin opened this issue 2 years ago • 6 comments

Hi!

I've implemented file uploading using these library https://github.com/jaydenseric/graphql-multipart-request-spec for my graphql service. And it works correctly when I querying my service directly. But in case when there is bramble between I get error like: input:1: Syntax Error GraphQL request (1:36) Expected Name, found String

So my question is: does bramble support those kind of queries with multipart/form-data content type?

timspin avatar Apr 28 '22 14:04 timspin

Hi @timspin. This isn't something that we have used / found a need for yet but it does sound interesting. As you've noticed, Bramble doesn't currently support this but we would welcome any contributions.

nmaquet avatar May 01 '22 23:05 nmaquet

It looks like adding the MultipartForm transport to gateway.go will be needed

pkqk avatar May 01 '22 23:05 pkqk

It also looks like one will need to set multipart/form-data for downstream services here.

benzolium avatar Mar 17 '23 14:03 benzolium

@nmaquet @pkqk could you please guide me where to start implementing this feature?

I think I'd have to do something like this in nautilus, but in bramble.

benzolium avatar Mar 19 '23 15:03 benzolium

@benzolium the github.com/99designs/gqlgen/graphql/handler module should handle the receiving of multipart requests, I haven't tested it but I think the uploaded file streams will be available as variables.

You've identified the right spot in client.go where you'll need to add the option to make a multipart request to the downstream service in your comment above

You could add something to the context that indicates if the incoming request used a multipart request, and then decide if based on the variables present (they are filtered down to only those necessary for the downstream request) if the downstream request needs to be a multipart request. (I wouldn't do it by default as it's not a standard transport and perhaps not all downstream services support it)

You might have to construct the multipart request yourself based on the spec, I haven't found a module that does it for you.

pkqk avatar Mar 19 '23 20:03 pkqk

FWIW, I added this feature to Ruby stitching recently: https://github.com/gmac/graphql-stitching-ruby/pull/103. There’s some documentation and code there that may serve as a motivational example of the feature.

gmac avatar Mar 02 '24 02:03 gmac