jaydenseric / graphql-upload

Middleware and a scalar Upload to add support for GraphQL multipart requests (file uploads via queries and mutations) to various Node.js GraphQL servers.
https://npm.im/graphql-upload
MIT License
1.43k stars 132 forks source link

Resolver issue #220

Closed nebnes closed 4 years ago

nebnes commented 4 years ago

When I call a sequelize operation here for example : "await File.create({name:"test"})" The resolver is block and return nothing. If I remove the sequelize line. It's works..

Do you know why I can't call sequelize ?

const resolve = async (request, args) => {
      const { file } = args;
      const { filename, createReadStream } = await file;
      const stream = createReadStream();
      await uploadFileToBucket(stream);
      const file = await File.create({name:"test"});
      return file;
});

Setup : graphql-express

jaydenseric commented 4 years ago

There is not enough information in this issue to be able to help. What is "sequelize"? What does uploadFileToBucket do? What is File, and why would you seemingly create and return a dummy file unrelated to the earlier upload?

nebnes commented 4 years ago

@jaydenseric

Here is a simplify example. I seem that I can't run promise in the resolver :

This doesn't work :

const sleep = _time => {
    return new Promise((res, rej) => {
        setTimeout(() => {
            res();
        }, _time);
    });
};

const resolve = async (request, args) => {
       const { file } = args;
       const { filename, createReadStream } = await file;
      const stream = createReadStream();
      await sleep(100);
      return "hello";
});

This works :

const resolve = async (request, args) => {
       const { file } = args;
       const { filename, createReadStream } = await file;
      const stream = createReadStream();
      return "hello";
});
jaydenseric commented 4 years ago

This doesn't work

What does that mean, is there an error?

Please see the tips:

https://github.com/jaydenseric/graphql-upload#tips

In both of those code examples the file stream is neither promisified and awaited, or destroyed. Not handling the streams correctly will cause all sorts of problems.

nebnes commented 4 years ago

Thanks for your time. It's the first implementation of graphql-upload for me. I have follow the readme. I didn't find yet what is wrong on my side. Even if I destroy the stream :

const sleep = _time => {
    return new Promise((res, rej) => {
        setTimeout(() => {
            res();
        }, _time);
    });
};

const resolve = async (request, args) => {
       const { file } = args;
       const { filename, createReadStream } = await file;
      const stream = createReadStream();
      stream.destroy();
      await sleep(100);
      return "hello";
});

The resolver no resolve : return nothing.

jaydenseric commented 4 years ago

If you run npm ls graphql-upload, is there only one version in node_modules, and is it the latest?

nebnes commented 4 years ago

└── graphql-upload@11.0.0 Yes

jaydenseric commented 4 years ago

What is the full JSON response, and HTTP status code?

nebnes commented 4 years ago

I have find something. My bad the issue come from my client part. I have debug with altair and it's seem ok. HTTP status 200 and JSON valid Thanks for your time !

jaydenseric commented 4 years ago

Glad you got it working :)