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

Uploading files with Multer #301

Closed
jferrettiboke opened this issue Feb 4, 2017 · 7 comments
Closed

Uploading files with Multer #301

jferrettiboke opened this issue Feb 4, 2017 · 7 comments

Comments

@jferrettiboke
Copy link

jferrettiboke commented Feb 4, 2017

Hi everyone!

I am trying to uploading files with Multer through GraphQL. There are two ways to go.

  1. Uploading files in a single no-GraphQL endpoint or using Multer like Express middleware.
  2. Uploading files using Multer inside a specific GraphQL resolver function.

For the first approach any file can be uploaded using .any() (Multer), which is fast but it is not possible to make specific validation rules for each GraphQL resource.
For the second approach is totally valid make validation rules, which is more flexible.

Once explained this, I am interested to achieve the second approach. I think it is almost done but I am getting errors.

Test output.

Uncaught SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse (<anonymous>)

I am getting this error because the server is not returning text in the response. res.text is undefined on expect(JSON.parse(res.text)).to.deep.equal(...).

Server output.

TypeError: Cannot read property 'definitions' of undefined
    at buildExecutionContext (\Projects\graphql-express-multer-example\node_modules\graphql\execution\execute.js:162:11)
    at Object.execute (\Projects\graphql-express-multer-example\node_modules\graphql\execution\execute.js:109:17)
    at doRunQuery (\Projects\graphql-express-multer-example\node_modules\graphql-server-core\dist\runQuery.js:77:26)
    at resolvedPromise.then (\Projects\graphql-express-multer-example\node_modules\graphql-server-core\dist\runQuery.js:18:39)

You can see and check the repository here. Feel free to send a PR or create a issue there.

Maybe something related with Apollo Server? Any thoughts on this?

Thanks in advance.

@smolinari
Copy link

Have you seen this?

https://github.com/jangerhofer/apolloFileUpload/blob/master/server/main.js

Also, are you using apollo-client? If you are, have a look at this issue.

Scott

@jferrettiboke
Copy link
Author

Thanks @smolinari.

Note in the code that I would like to use Multer inside GraphQL resolve functions, not using a single endpoint or middleware before calling graphqlExpress(). The example you gave me is using Multer like a Express middleware before calling GraphQL.
I think my approach is worth because I do not miss the validation rules with Multer, so I can set different validation rules depending of the resource.

Thanks for the issue! I did not know about it.

@jaydenseric
Copy link

@jferrettiboke did you get it to work in the end?

@jferrettiboke
Copy link
Author

Hi @jaydenseric. No, yet. Do you have some ideas?

@jaydenseric
Copy link

Yea, I'll try to get everything working and publish it sometime soon.

@helfer
Copy link
Contributor

helfer commented Apr 19, 2017

Closing this for lack of activity. Let's keep track of file upload related things in #229. If anyone has time to write up and propose a design, I'd be more than happy to review it. Any and all contributions, big or small are welcome!

@helfer helfer closed this as completed Apr 19, 2017
@jaydenseric
Copy link

For an immediate solution, checkout apollo-upload-server.

trevor-scheer pushed a commit that referenced this issue May 6, 2020
Co-authored-by: Renovate Bot <bot@renovateapp.com>
trevor-scheer pushed a commit that referenced this issue May 14, 2020
Co-authored-by: Renovate Bot <bot@renovateapp.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants