【问题标题】:GraphQL Mutation Body ParserGraphQL 变异体解析器
【发布时间】:2018-05-31 09:24:35
【问题描述】:

刚刚更新到 '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": {}
    }
  }'

【问题讨论】:

    标签: curl post graphql express-graphql


    【解决方案1】:

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

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

    【讨论】:

    • 感谢保佑!添加 Content-Type 对我有用。感谢您的意见:)
    猜你喜欢
    • 2019-03-21
    • 2019-12-12
    • 1970-01-01
    • 2019-08-03
    • 2018-09-07
    • 2020-01-18
    • 2019-02-08
    • 2018-08-25
    • 2017-07-17
    相关资源
    最近更新 更多