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

Hi,

Has anyone faced this issue

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

SyntaxError: Unexpected token P in JSON at position 0
    at JSON.parse (<anonymous>)
    at IncomingMessage.<anonymous> (/home/abc/server/node_modules/graphql.js/graphql.js:71:25)

this is my code

const query = graph(`mutation(
    $username: String!, 
    $password: String! ) {
      authentication {
      login(
        username: $username,
        password: $password,
        strategy: "local"
      ) {
        responseResult {
          succeeded
          errorCode
          message
        }
        jwt
      }
    }
  }`);

  query({
    username: req.body.username,
    password: req.body.password
  }).then(
    resData => {
      res.send(resData);
    },
    err => {
      console.error(err)
      res.status(500).send(err)
    }
  );

am running graphql.js in express server and not using ‘body-parser’ but rather uses express.json(). I am sure that I am able to read ‘req.body.username’ and ‘req.body.password’ values successfully, so why is it suggesting to use body-parser ?

Weird thing is this request runs fine on my local machine but gives this error on deployed server.

Could someone let me know, how to console.log body, before we query?

Regards

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
fcommented, May 5, 2020

Hey!

Can you test is by passing asJSON: true?

const graphTest = graphql("https://countries.trevorblades.com/", {
  method: "POST",
  asJSON: true
});
0reactions
mrkhancommented, May 6, 2020

In my case, my client don’t directly query graphql server. I am able to read each values (username, password) in my node server which then fires query to Graphql.

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 >
POST body missing. Did you forget use body-parser ... - GitHub
I used graphql and koa2. const Koa = require('koa') const json = require('koa-json') const bodyparser = require('koa-bodyparser') const ...
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 >
GRANDstack starter - Using Postman API to get data... - Neo4j
... 'POST body missing. Did you forget use body-parser middleware?'. Does somebody has an idea how to get Postman working with GraphQL? I ......
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