2017-12-18 310 views
1

剛剛更新爲「graphql服務器-Express的1.3.0版本和運行任何突變時,現在我收到此錯誤:GraphQL突變體分析器

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": {} 
    } 
    }' 

回答

0

的請求(docs

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

謝謝祝福設置Content-Type: application/json頭球攻門!添加Content-Type爲我工作。欣賞您的意見:) – matt

+0

不客氣,不受歡迎。很高興提供幫助,如果此答案解決了您的問題,請通過單擊答案旁邊的複選標記將其標記爲已接受。請參閱:[如何接受答案的工作?](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)瞭解更多信息 – Bless