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: Cannot read property 'body' of undefined #84

Closed
voodooattack opened this issue Aug 6, 2016 · 5 comments
Closed

Koa: Cannot read property 'body' of undefined #84

voodooattack opened this issue Aug 6, 2016 · 5 comments

Comments

@voodooattack
Copy link

When I use apolloKoa with koa-router like this:

const app = koa();
const router = new Router();
const apolloMiddleware = apolloKoa({ schema });

app.use(koaBody());

router.post('/api', apolloMiddleware);

app.use(router.routes());
app.use(router.allowedMethods());

I get the following error:

  TypeError: Cannot read property 'body' of undefined
      at /home/voodooattack/dev/foxls/node_modules/apollo-server/dist/integrations/koaApollo.js:35:25
      at undefined.next (native)
      at fulfilled (/home/voodooattack/dev/foxls/node_modules/apollo-server/dist/integrations/koaApollo.js:4:58)
      at run (/home/voodooattack/dev/foxls/node_modules/core-js/modules/es6.promise.js:87:22)
      at /home/voodooattack/dev/foxls/node_modules/core-js/modules/es6.promise.js:100:28
      at flush (/home/voodooattack/dev/foxls/node_modules/core-js/modules/_microtask.js:18:9)
      at _combinedTickCallback (internal/process/next_tick.js:67:7)
      at process._tickCallback (internal/process/next_tick.js:98:9)

package.json:

  "dependencies": {
    "apollo-client": "^0.4.11",
    "apollo-server": "^0.2.3",
  }
@HriBB
Copy link
Contributor

HriBB commented Aug 6, 2016

Which version are you using? Currently we only support v2.

@voodooattack
Copy link
Author

@HriBB Thank you, I just upgraded to koa 2 and it all works. It would be useful if this was mentioned in the documentation.

@HriBB
Copy link
Contributor

HriBB commented Aug 6, 2016

@voodooattack great to hear that! But you were lucky to be able to switch to v2 easily, other users might not have that option, if their entire app is already built around v1.

It would be cool if we supported both versions and threw an error if user used the wrong version. The syntax from v1 to v2 changed only slightly, and I suspect that it should be possible to detect version and adjust apolloKoa() or simply provide apolloKoa() and apolloKoa2().

@helfer what do you think about this? How should we approach this if we decide to support koa v1?

@helfer
Copy link
Contributor

helfer commented Aug 6, 2016

@HriBB If you can make it work for both versions, that would be great! Even if the export is different, that's fine as long as the code is mostly shared. I'd say go for it!

@cvburgess
Copy link

cvburgess commented Nov 15, 2016

Tested this locally for those on Koa 1.x - koa-convert has a convert.back() method that makes this work just fine with koa 1.x

@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