yoga2 icon indicating copy to clipboard operation
yoga2 copied to clipboard

File Handling like Active Storage in Rails

Open guledali opened this issue 6 years ago • 7 comments

Describe

Integrate an easy solution for uploading files that is build into this framework!

guledali avatar Jan 27 '19 09:01 guledali

It should be simple thing to do using ejected template and apollo file uploads: https://blog.apollographql.com/file-uploads-with-apollo-server-2-0-5db2f3f60675

However it will be nice to check it nexus will handle this using FileUpload scalar etc. and have separate template for this case. @guledali This sounds like good community contribution that could be done as template. See also: https://github.com/prisma/yoga2/issues/31

wtrocki avatar Jan 27 '19 12:01 wtrocki

I'm not sure whether we need any kind of integration to support upload here.

https://github.com/jaydenseric/graphql-upload seems to do the job on its own, and should not require you to eject at any time.

All you should need is to export the Upload type from one of your resolvers file, and then the library gives you other utils to handle it.

Wouldn't that be enough?

Weakky avatar Mar 05 '19 14:03 Weakky

@Weakky It would be nice if this was build into the framework somehow like out of the box solution.

guledali avatar Mar 05 '19 15:03 guledali

@Weakky I know you're working on the docs right now could you at least add section on how to do File Upload

guledali avatar Mar 06 '19 10:03 guledali

I was able to get it working by doing the following:

  1. Add a new file src/graphql/Upload.ts
  2. paste the following code in the file:
import { scalarType } from "yoga";
import { GraphQLUpload } from 'graphql-upload'

export const Upload = scalarType(GraphQLUpload)

rohit-ravikoti avatar Mar 13 '19 23:03 rohit-ravikoti

@rohit-ravikoti You don't event need to use scalarType here, nexus supports graphql-js types out of the box.

import { GraphQLUpload } from 'graphql-upload'

export const Upload = GraphQLUpload

Should be sufficient

@guledali I'll add a section for that!

Weakky avatar Mar 15 '19 10:03 Weakky

More context: https://spectrum.chat/nexus/general/uploading-files-with-nexus-yoga2~e9643500-d4b7-4548-b4fb-f8eac6221916

schickling avatar Apr 18 '19 11:04 schickling