Graphql-go: How can i upload file (e.g. : image) with graphql-go?

Created on 6 Aug 2018  路  11Comments  路  Source: graph-gophers/graphql-go

Any examples for retrieving an file ?
Should i make scalar type?
Thanks for help.

Most helpful comment

But why not support file uploads out of the box? E.g. by implementing the graphql multipart spec

This is meant to be a feature request.

All 11 comments

Usually what I've done is create mutation which returns a URL external to the API which the client can upload their file to. That way, we don't have to keep long-lived connections open in the GraphQL API.

That being said, it's definitely possible to add file uploads to your GraphQL API, if you wish.
How Apollo Server does it: https://www.apollographql.com/docs/guides/file-uploads.html

But why not support file uploads out of the box? E.g. by implementing the graphql multipart spec

This is meant to be a feature request.

@robsdedude
Hi, what approach did you eventually use?
@tonyghita Would your approach not lead to multiple uploads?

@smithaitufe None yet. Still work in progress. But we'll probably write a middleware to handle files according to the graphql multipart spec.

@robsdedude Please check this middleware that allow upload of files.
I am still working on improving it but for now, it does upload successfully.

I know this was closed, but is there any update on supporting this in the current implementation? Or should any app I work on just operate with REST endpoints to handle images?

Why isn't the graphql-multipart-request-spec spec not build-in into this library?

For the graphql server we are building we had to do a load of hacking to get graphql multi part request working beside authentication and some custom context.

Beside that i'm new with graphql and to build the spec myself is to much work so i want to use a plug and play solution but the libraries available for that are not really usable if you already have a big code base with different contexts.

  • smithaitufe/go-graphql-upload should work but i've looked though the code and there are just some serious issues (why are all files global and what was the point of a global defined wait group and why does the library panic when a user uploads multiple files??)
  • jpascal/graphql-upload This was our choice, and it should work out of the box but the code is again not great as it contains loads of panics. We also didn't want to use it as specified in the Readme but just in a request handler function but this all meant we had to change around 50% of the library it's code.

I expected that building a graphql server using this library was a peace of cake but things like this make me reconsider my choices next time i need to chose between old-school rest and graphql
I know that this library doesn't provide solutions to this but for me as new user i kinda expect that this is builtin and now looking back at the amount of work required to implemented this in a "normal" api with oauth and a user context is just a bit to much.

Also just a bit of context, we are building a public api for our users and we decided to build it in graphql because we have loads of filters and the responses with rest did become huge so graphql seems like the perfect option as it is self explaining and we can add as much fields as we want to the response.
This is also why we want to use graphql-multipart-request-spec as it seems to be the standard of uploading files in a graphql server.

@mjarkk

In the next few weeks, I am going to update the code to handle the issue of multiple file upload.

Also example/contact app will be updated and the issues you raised will be looked into. I have simply been very busy with some projects.

Thanks for looking into the go-graphql-upload package.

@smithaitufe Any chance you got to this?

@farax seems like he made it here: https://github.com/smithaitufe/go-graphql-upload

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LeeWong picture LeeWong  路  4Comments

jakubdal picture jakubdal  路  6Comments

aquiseb picture aquiseb  路  4Comments

saward picture saward  路  6Comments

tonyghita picture tonyghita  路  3Comments