Updated syntax in book/text/1.md #6
Copy link
Copy link
Closed
Description
Chapter 1 - line 231
Current syntax leads to "errors":[{"message":"POST body sent invalid JSON."}]}
Expected Behavior
$ curl -X POST -H "Content-Type:application/json" \
> -d '{user(id: "123"){_id, username}}' \
> http://localhost:3000/graphql
{"data":{"user":{"_id":"123","username":"jeresig"}}}Current Behavior
$ curl -X POST -H "Content-Type:application/json" \
> -d '{user(id: "123"){_id, username}}' \
> http://localhost:3000/graphql
{"errors":[{"message":"POST body sent invalid JSON."}]}Possible Solution
$ curl -X POST -H "Content-Type:application/json" \
> -d '{"query": "{user(id: \"123\"){_id username}}"}' \
> http://localhost:3000/graphql
{"data":{"user":{"_id":"123","username":"jeresig"}}}Steps to Reproduce
git clone https://github.com/GraphQLGuide/graphql-rest-api-demo.gitnode graphql-server.js- Execute query from Chapter 1 line 231
Environment
node: v10.4.1
npm list report for graphql:
├─┬ express-graphql@0.6.12
│ ├── accepts@1.3.5 deduped
│ ├── content-type@1.0.4 deduped
│ ├─┬ http-errors@1.6.3
│ │ ├── depd@1.1.2 deduped
│ │ ├── inherits@2.0.3
│ │ ├── setprototypeof@1.1.0 deduped
│ │ └── statuses@1.4.0 deduped
│ └─┬ raw-body@2.3.2
│ ├── bytes@3.0.0 deduped
│ ├─┬ http-errors@1.6.2
│ │ ├── depd@1.1.1
│ │ ├── inherits@2.0.3 deduped
│ │ ├── setprototypeof@1.0.3
│ │ └── statuses@1.4.0 deduped
│ ├── iconv-lite@0.4.19 deduped
│ └── unpipe@1.0.0 deduped
├─┬ graphql@0.13.2
│ └── iterall@1.2.2
Possible Implementation
I can make a quick pr to update this to the proposed possible solution if you want.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
lorensr commentedon Jun 14, 2018
Oh thanks, that would be great! We updated the content-type from
application/graphqlbut neglected to update the body