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

koa-bodyparser seems dead now; @koa/bodyparser is the up-to-date version #214

Open
aseemk opened this issue Mar 3, 2024 · 2 comments
Open

Comments

@aseemk
Copy link

aseemk commented Mar 3, 2024

Hi there. Thanks for this library! We've been using it and it's helpful.

I recently ran into an issue unrelated to Apollo, but related to the Koa body-parsing middleware this library expects and requires.

We installed koa-bodyparser which this library's readme recommends. However, you can see that package is stuck on version 4.

If you go to the Koa bodyparser's GitHub repo, it actually specifies the package name as @koa/bodyparser — and that package is on version 5 now (and actually maintained).

I had to use a new option added to version 5 to fix a bug, and couldn't understand why there was no version 5 on npm.

Please consider upgrading not just the readme here but also the code and test dependencies on this package.

Thanks again and hope this helps others!

@aseemk
Copy link
Author

aseemk commented Mar 5, 2024

Another issue related to this: going from v4 (koa-bodyparser) to v5, @koa/bodyparser now no longer populates ctx.request.body (even to {}) on GET requests:

https://github.com/koajs/bodyparser/blob/664cd7c413250d5e12eb5bb0fbf4e52d31ef24f5/src/body-parser.ts#L30

https://github.com/koajs/bodyparser/blob/664cd7c413250d5e12eb5bb0fbf4e52d31ef24f5/src/body-parser.ts#L76-L87

Makes sense since GET requests have no body, so should need no parsing.

But this Apollo Koa integration still indiscriminately expects a ctx.request.body to be set even if the method is GET (for loading the Apollo GraphiQL UI):

return async (ctx) => {
if (!ctx.request.body) {
// The json koa-bodyparser *always* sets ctx.request.body to {} if it's unset (even
// if the Content-Type doesn't match), so if it isn't set, you probably
// forgot to set up koa-bodyparser.
ctx.status = 500;
ctx.body =
'`ctx.request.body` is not set; this probably means you forgot to set up the ' +
'`koa-bodyparser` middleware before the Apollo Server middleware.';
return;
}

I'm hackily setting ctx.request.body ??= {} myself in my own wrapper middleware if ctx.method === 'GET', and this works. But should this be fixed here in this library? Thank you!

@matthew-gordon
Copy link
Collaborator

matthew-gordon commented Mar 11, 2024

Hi @aseemk, please refer to this previous comment: #60 (comment)

Ultimately I agree It is certainly a good idea to use packages that are actively maintained, if you feel strongly I definitely encourage a PR with the changes.

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

No branches or pull requests

2 participants