f / f/graphql.js

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

Open
#58 8 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2.3k
Forks
88
PR merge metrics
No merged PRs in 30d

Description

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 ()
at IncomingMessage. (/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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.