Closed yazer79 closed 2 years ago
Treat user uploaded files in a similar way to user database content. They should be stored somewhere other than the GraphQL API server, which you want to be able to redeploy/discard/upgrade/etc. without worrying about losing user data.
You might be interested in this old comment on the topic: https://github.com/jaydenseric/graphql-upload/issues/251#issuecomment-862135269 .
I don't suggest using a mutation named something like uploadFile
to upload all files for various purposes; instead it should be for example userCreate
and one of the arguments is avatar
of Upload
scalar type.
Here is a realistic example from a real API to add an artwork that can have images, and later, to add, reorder, and delete artwork images:
Notice how the naming convention allows mutations relating to the same things to sort together.
I make a few generic helpers like storeS3Image
and getImgixImageMeta
to make resolver code more DRY.
This is not a problem, just help or explanation needed about how uploads are best handled in graphql. I have upload client / singleUpload apolloserver resolver, I feel lost after this basic step. I do not feel that uploading all files just in 1 directory is a good idea. My question is, if I need multiple upload types in my app, how do I handle this? For example, uploading an avatar, a profile picture, ..etc Do I do repeat a resolver (on server side) for each upload type? eg: avatarUpload resolver, pictureUpload resolver,... etc Or there is some way to send more info about the "upload type or group / save directory" from client? Or simply all uploads are saved in one directory? Any ideas are welcome