Apollo-server: Upload fails with DeprecationWarning: File upload property ‘stream’ is deprecated. Use ‘createReadStream()’ instead.

Created on 17 Dec 2018  Â·  3Comments  Â·  Source: apollographql/apollo-server

Using node 8.11.4 with [email protected]:

(STDERR) (node:19126) DeprecationWarning: File upload property ‘stream’ is deprecated. Use ‘createReadStream()’ instead.

It seems that this was due to changes since [email protected], as the version before worked without an Error.

Assuming the breaking change was only intended for node versions before 8.5, then my report means that 8.11.4 is affected by this probably. #2054

(Update: my bad, 8.11.4 is good :+1: )

Most helpful comment

This is working as intended; @optunetobi please migrate to the new API in your mutation resolvers:

- const { stream, filename, mimetype } = await upload
+ const { createReadStream, filename, mimetype } = await upload
+ const stream = createReadStream()

If you don't, it will still work for now but you will see this deprecation warning:

screen shot 2018-10-29 at 10 03 43 pm

As @abernix pointed out, this API change happened in graphql-upload v7 and was necessary to fix a whole bunch of issues, the most obvious being that you can now use a single Upload as a variable that can be used as input for multiple mutations in one request. Previously, consuming the stream in one resolver would interfere with consuming the same stream in another.

All 3 comments

Could you please provide a small, runnable reproduction of your particular problem? (CodeSandbox is great for this). Or at the _very_ least, an example of one of your resolvers?

Basically: This warning message should be just that: a warning. According to the both the issue you linked (https://github.com/apollographql/apollo-server/pull/2054#pullrequestreview-180465263) and the official CHANGELOG for graphql-upload, stream should still be available and still work properly, but would be deprecated in a future version.

This is working as intended; @optunetobi please migrate to the new API in your mutation resolvers:

- const { stream, filename, mimetype } = await upload
+ const { createReadStream, filename, mimetype } = await upload
+ const stream = createReadStream()

If you don't, it will still work for now but you will see this deprecation warning:

screen shot 2018-10-29 at 10 03 43 pm

As @abernix pointed out, this API change happened in graphql-upload v7 and was necessary to fix a whole bunch of issues, the most obvious being that you can now use a single Upload as a variable that can be used as input for multiple mutations in one request. Previously, consuming the stream in one resolver would interfere with consuming the same stream in another.

@abernix thank you for your feedback and explanation. Unfortunately it broke my resolver code in my case, or I was misattributing this warning as an error as I passed the stream to another cloud-storage uploader, which then failed without error to console (I may have forgotten a catch).

@jaydenseric thank you for the detailed explanation, I could fix it now. (with your provided diff)

Was this page helpful?
0 / 5 - 0 ratings