NestJS upload using GraphQL

The name of the picture


NestJS upload using GraphQL



Is anyone has an example of how to upload a file in NestJs using GraphQl?



I can upload using given example via controller



https://github.com/nestjs/nest/issues/262#issuecomment-366098589,



but I couldn't find any comprehensive documentation how to upload using GrahpQL in NestJS




2 Answers
2



One normally does not use GraphQL for upload. GraphQL is fancy "specification of API", meaning that in the end of the day, low level HTTP request and responses are translated to/from JSON objects (if you don't have custom transport).



One solution could be to define special endpoint in GraphQL schema like:


mutation Mutation {
uploadFile(base64: String): Int
}



Then client would convert binary data to base64 string, which would be handled accordingly on resolver side. This way, file will become part of JSON object exchanged between GraphQL client and server.



While this is might be suitable for small files, small number of operations, it is definitely not a solution for upload service.



You could use the apollo-upload-server lib. Seems like the easiest thing to do, in my opinion. Cheers





If this answer solves your problem, make sure to upvote it so anyone else struggling with the same thing can find the answer much faster. :-)
– Clayton Ray
5 hours ago






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

How to scale/resize CVPixelBufferRef in objective C, iOS

Stripe::AuthenticationError No API key provided. Set your API key using “Stripe.api_key = ”

SVG with two text elements. When one resizes due to textLength - how to resize the other one to the same character size