Closed protatix closed 2 years ago
Sorry to hear you've been having a frustrating time getting this to work. I've helped a lot of people with similar problems in past; please search and refer to those old issues. It generally relates to conflicting installations of graphql-upload
in the project. The Upload
scalar coming from one version, and the middleware another. Only one version of graphql-upload
should be installed.
I have been struggling this issue last 2 days, Something is missing maybe or there is a bug. When I upload a file I got this object and createReadStream returns undefined in the file object; Other properties such as filename, mimetype and encoding are reachable.
args { image: { promise: {}, file: { filename: 'istanbul.jpg', mimetype: 'image/jpeg', encoding: '7bit' } } }
Package versions;
"apollo-server": "3.6.3", "apollo-server-express": "3.6.3" "graphql-upload": "13.0.0", "graphql": "15.8.0",
My server setup as below. I've added express middleware. By the way, after upgrading Apollo Server v2 to v3, not fixed my problem.
app.use(graphqlUploadExpress());
const resolvers = { Query: { Store: Store.getWidgets, Upload: GraphQLUpload, }, Mutation: { imageUpload: Store.imageUpload, } }
static async imageUpload(_, { image }) { try { const { file } = image; const { filename, mimetype, createReadStream } = await file; console.log('filename', filename); const stream = createReadStream(); console.log('stream', stream); // console.log('filename', filename); // console.log('mimetype', mimetype); // console.log('encoding', encoding); return { filename: 'test' }; } catch (error) { console.error(
logFor=StoreError-imageUpload error=${error.message} - ${error.stack}); } return null; }
I got error;
logFor=StoreError-imageUpload error=createReadStream is not a function - TypeError: createReadStream is not a function