Return file from GraphQL resolve Return file from GraphQL resolve express express

Return file from GraphQL resolve


GraphQL uses JSON format, which represents as text format, not as binary.

If you don't want download files with REST, then you should:

  1. Encode your file content into base64 string in the back end. Related question
  2. Send this string as part of query response.
  3. Save encoded base64 string as a file in the front end. Related question

But right architecture design is add a file link in the GraphQL response and use browser for downloading/rendering the file.