Skip to content

Updated syntax in book/text/1.md #6

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

  1. git clone https://github.com/GraphQLGuide/graphql-rest-api-demo.git
  2. node graphql-server.js
  3. 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.

Activity

  1. lorensr commented on Jun 14, 2018

    @lorensr
    Member

    Oh thanks, that would be great! We updated the content-type from application/graphql but neglected to update the body

  2. ghost closed this as completedon Jun 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions