apollographql / apollo-server

🌍  Spec-compliant and production ready JavaScript GraphQL server that lets you develop in a schema-first way. Built for Express, Connect, Hapi, Koa, and more.
https://www.apollographql.com/docs/apollo-server/
MIT License
13.81k stars 2.03k forks source link

Direct-to-Storage File Uploads #3739

Closed stemmlerjs closed 3 years ago

stemmlerjs commented 4 years ago

Today, our documentation on File Uploads recommends uploading by piping file data through the GraphQL server to the application server. The main drawback of that approach is that it puts stress on the application server and might introduce more problems in production environments.

I just learned about this today from a conversation with @ThisIsMissEm on Spectrum, but Rails has this feature called active storage that facilitates uploading directly to either:

If, for example, you wanted to use AWS for Direct-to-Storage, we could enable users to configure apollo-server by hooking up an apollo-server-aws Storage Adapter with their AWS creds, tell it the bucket name, and then expose a built-in type like UploadToken:

type UploadToken {
  # URL to the file in storage
  url: String!
  signedUrl: String!
  expiry: Integer!
}

The client would then need to perform two mutations. The first to request the signed URL to upload the file to, and the second to signal that the upload has been finished, allowing the application server to create any database records associated with the upload.

If we were to implement this, we could get started by defining some sort of IStorageAdapter and then implement it for the local filesystem, AWS, Google, Cloudinary, etc.

ciekawy commented 3 years ago

any update on this? are there any known implementations of the described flow supporting apollo?

glasser commented 3 years ago

We found that shipping a particular version of graphql-upload along with Apollo Server (which we then couldn't upgrade past a certain point due to back-compat guarantees) was a bad pattern, so we are removing the direct upload integration from Apollo Server 3; integrating graphql-upload with Apollo Server on the web frameworks they both support is relatively straightforward. So this sort of future improvement is best asked about on graphql-upload's repo.