You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need to fetch raw image data from a service and then return a base64 encoded version of that data to the front end. After testing, I discovered that the stock node-fetch implementation is mangling the data without the appropriate response type. There doesn't appear to currently be a way with RESTDatasource to resolve the different types that fetch supports (arraybuffer, blob, text, json, etc).
Is this something that can be added in?
The text was updated successfully, but these errors were encountered:
glasser
transferred this issue from apollographql/apollo-server
Oct 11, 2022
You can override parseBody() to call arraybuffer() based on headers or whatever if you'd like. (You may want to override the new cloneParsedBody() as well if you're producing something mutable.)
However, you do run into trouble if the body is not a UTF-8 string, because the HTTPCache writes UTF-8 strings to the shared cache (created via JSON.stringify, read with response.text()). This is storing the raw body pre-JSON-parsing, but will mangle the body if it's non-UTF-8. I think the best thing to do would be to allow you to specify that the body should be treated as binary (maybe by a new field under cacheOptions?) and in that case we could base64 the body and store it in a different key in the object written to the cache. (Always base64-ing seems like an unnecessary performance and space usage in the common JSON/text case.)
This is something we'd be happy to review a PR for.
I need to fetch raw image data from a service and then return a base64 encoded version of that data to the front end. After testing, I discovered that the stock node-fetch implementation is mangling the data without the appropriate response type. There doesn't appear to currently be a way with RESTDatasource to resolve the different types that fetch supports (arraybuffer, blob, text, json, etc).
Is this something that can be added in?
The text was updated successfully, but these errors were encountered: