bramble
bramble copied to clipboard
Request syntax error while trying to upload file
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?
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.
It looks like adding the MultipartForm
transport to gateway.go
will be needed
It also looks like one will need to set multipart/form-data
for downstream services here.
@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 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.
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.