yoga2
yoga2 copied to clipboard
File Handling like Active Storage in Rails
Describe
Integrate an easy solution for uploading files that is build into this framework!
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
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 It would be nice if this was build into the framework somehow like out of the box solution.
@Weakky I know you're working on the docs right now could you at least add section on how to do
File Upload
I was able to get it working by doing the following:
- Add a new file
src/graphql/Upload.ts
- paste the following code in the file:
import { scalarType } from "yoga";
import { GraphQLUpload } from 'graphql-upload'
export const Upload = scalarType(GraphQLUpload)
@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!
More context: https://spectrum.chat/nexus/general/uploading-files-with-nexus-yoga2~e9643500-d4b7-4548-b4fb-f8eac6221916