5

刚刚更新到 'graphql-server-express' 版本 1.3.0,现在运行任何突变时出现此错误:

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

初始化服务器时,我包含了“body-parser”包,所以我不确定这里发生了什么。有任何想法吗?

服务器配置:

    //GraphQL Server
    graphQLServer.use(

        //GRAPHQL Endpoint
        `/${settings.public.graphql.endpoint}`,

        //Parse JSON
        bodyParser.json(),

        //authenticate
        authenticateRequest,

        //GRAPHQL Server
        graphqlExpress(req => {

            return {
                schema: schema,
                context: req
            }
        })

    );

示例请求:

curl 'http://localhost:5050/graphql' \
  -H 'authorization: Bearer xxxxxxxxxxx.xxxxxxxxxxx' \
  -d '{
    "query": "mutation { sensorData(sensorValue: \u0027asdasdasdasd \u0027)}",
    "variables": {}
    }
  }'
4

1 回答 1

7

Content-Type: application/json在请求中设置标头(文档

curl 'http://localhost:5050/graphql' \
  -H "Content-Type: application/json" \
  -H 'authorization: Bearer xxxxxxxxxxx.xxxxxxxxxxx' \
  -d '{
    "query": "mutation { sensorData(sensorValue: \u0027asdasdasdasd \u0027)}",
    "variables": {}
    }
  }'
于 2017-12-18T06:55:27.703 回答