question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

POST body missing. Did you forget use body-parser middleware?

See original GitHub issue

I used graphql and koa2.


const Koa = require('koa')
const json = require('koa-json')
const bodyparser = require('koa-bodyparser')
const config = require('./config')
const port = config.URL.port
const cors = require('@koa/cors')
const UserRoute = require('./routes/user.router')
const { ApolloServer, gql } = require('apollo-server-koa')
const app = new Koa()

const typeDefs = gql`
  type Book {
    title: String
    author: String
  }
  type Query {
    books: [Book]
  }
`

const resolvers = {
  Query: {
    books: () => books,
  },
}

app.use(cors({
  origin: '*',
  credentials: true,
  methods: ['PUT', 'POST', 'GET', 'DELETE', 'OPTIONS'],
  allowedHeaders: ['Content-Type', 'Content-Length', 'Authorization', 'Accept', 'X-Requested-With', 'x-access-token']
}))
app.use(UserRoute.routes(), UserRoute.allowedMethods())
app.use(bodyparser())
app.use(json())

const server = new ApolloServer({ typeDefs, resolvers })

server.applyMiddleware({
  app,
  path: config.URL.graphql,
})

module.exports = app.listen(port)

I just want to use graphql on some of the interfaces.

image

image

I use postman for debugging. Any good suggestions?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

8reactions
yvanwanglcommented, Apr 22, 2019

Or you can use the package koa-bodyparser-graphql directly.

1reaction
akashelhancecommented, May 27, 2021

ok, thanks for the help

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - GraphQL - POST body missing. Did you forget use ...
I have tried different recommendations with body-parser online, but still can't seem to fix it. Server: require('babel-polyfill') const express ...
Read more >
Why I getting this error: POST body missing. Did you forget ...
I am trying to upload a file to the server using apollo-server-fastify. I didn't use the fastify-multipart or similar dependencies because ...
Read more >
POST body missing. Did you forget use body-parser ...
Did you forget use body-parser mpoatiddleware? Hi , I already update my katalon to 5.8 , but when I runned my graphQL script...
Read more >
post body missing did you forget use body-parser middleware,
We have been having issues with the req.body being empty on POST requests in our middleware, since version 9.0.0. We use this to...
Read more >
POST body missing. Did you forget use body-parser ...
Hi,. Has anyone faced this issue. POST body missing. Did you forget use body-parser middleware? SyntaxError: Unexpected token P in JSON at ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found