Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting empty object instead of file #94

Closed
jordan-jarolim opened this issue Jul 30, 2018 · 7 comments
Closed

Getting empty object instead of file #94

jordan-jarolim opened this issue Jul 30, 2018 · 7 comments
Labels

Comments

@jordan-jarolim
Copy link

jordan-jarolim commented Jul 30, 2018

Hi, I ran into this problem and cannot figure it out. Once I upload file using apollo-upload-client + apollo-upload-server I am getting an empty object {} instead of a file. I went through several issues and everything seems to be set up correctly.

  1. I have set createUploadLink (Getting an empty object {} in server instead of file #73)
  2. My payload looks like this - https://github.com/jaydenseric/graphql-multipart-request-spec#request-payload (File sending does not work apollo-upload-client#82)
  3. I have followed all the other steps in readme such as scalar Upload etc...

Here is my server config:

server.use('/graphql', bodyParser.json(), auth, apolloUploadExpress(), graphqlExpress((req, res) => { const context = { user: req.user, req, res, }; return { schema, context, }; }));
Is there any known issue with bodyParser as mentioned in one of referenced issues? Could you point me to any other direction please?

Thanks

@jaydenseric
Copy link
Owner

jaydenseric commented Jul 31, 2018

I don't think you need the body parser at all, apollo-upload-server does not need it and express-graphql can handle that internally. The example in the readme may need to be updated.

@jaydenseric
Copy link
Owner

Oh, sorry I was confused. I think the readme example assumed Apollo, not express-graphql. The examples still may need to be updated though: https://www.apollographql.com/docs/apollo-server/essentials/server.html#middleware

@jordan-jarolim
Copy link
Author

Sorry, this was totally my mistake. I missed that part saying: " the resolver recieves a promise...". So I was missing await in my resolver. Feel free to close this. Anyway, I have one more question. You are saving the stream data into a file using pipe in your example. Is it possible to save data into a variable? I tried to use on('data', function...) but the stream seems to be writable only. My use case is that once I get the file I wanna send it over REST to an external service. So creating a file on the disk is not necessary for me. I know this is not related to this issue nor the library but if you know the way, it might help the others as I didnt find any solution.

Thanks :)

@jaydenseric
Copy link
Owner

jaydenseric commented Jul 31, 2018

Glad you worked it out! As for passing the file on to an external service using REST, you should be able to use the stream as a multipart form field when using libraries such as form-data and node-fetch.

@mike-marcacci
Copy link
Collaborator

mike-marcacci commented Jul 31, 2018

@jordan-jarolim the stream should be a duplex stream, (it’s actually a writable stream that proxies readable methods/events to a readable stream) so the data event should work... if it doesn’t, it will once #92 lands, since it bumps the version of capacitor to one that uses a real read stream as opposed to a proxy.

Note that you can always pipe it to a passthrough stream, and listen on that one.

@jordan-jarolim
Copy link
Author

@mike-marcacci Well I tried the example using pipe with file output but it behaves little bit nondeterministic. It sometimes produces an empty file of 0B (just simple .txt of 2B originally). I also tried own implementation using 'data' or 'readable' events and I had still the same problem. If I dump a type of the stream using (streamobj instanceof stream.Readable) it always gives me false, but gives true for stream.Writable. I guess this might be a correct behavior?

@mike-marcacci
Copy link
Collaborator

Hey @jordan-jarolim thanks for reporting back! What you're describing sounds like a timing issue that was already fixed in fs-capacitor. I just checked, and it looks like I never bumped the dependency version here, assuming a patch would automatically be imported. However, since it was pre-1.0.0, all new versions are assumed to be breaking. I just manually bumped the version in #97. We'll get that out ASAP, and would much appreciate if you try again: it should work the way you're using it.

Again, once #92 lands, this your instanceof check will succeed, as you'll be interacting with a real Readable stream. I'm going to try to finish that up as soon as I get a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants