yakovkhalinsky/backblaze-b2

Question on integration with GraphQL

Closed this issue · 3 comments

How can I integrate the this API with GraphQl. Since node will reside on EC2 If I use getDownlaodAutherization it will be valid only for that id and wont work for client device. Similarly upload url might not work for client or I may be wrong.

Please do advise on how to go about this.

If I understand correctly you want to upload a file to B2 via the client device (browser)? You should be able to simply use getUploadUrl and pass the returned URL + auth token to the client. You'll need to set up CORS rules as well if you plan on doing this from a browser.

@deltamish if you want your GraphQL service to be stateless you will need to pass something either in your query or in the header to alllow the authorisation to occur on every request.

The other option is to not include file uploading as a part of your GraphQL and use "classic" style REST just for file uploads.

Since you need to be able to possibly support retries and chunking, it might be wise to leave it out of your GraphQL service.

Let us know what you think. I'm curious to understand this kind of use case.

Yeah that's a good suggestion and @odensc the Upload part is good approach. The reason I wanted to pus/pull from B2 via Graphql server was to abstract it from the client/frontend so it would never know what API's being used which means I can swap out the B2 Api's with say S3 and it should still work. Also the extra layer protection since masterkey and all would be in server and not in device.

So I just thought there would be a way where I can return the stream returned by download API of B2 and pas it to the client so it can download it. As for upload we seem to have Upload provided by Apollo 2.0 as @odensc suggested.