【问题标题】:Unexpected EOF on graphql POST requestgraphql POST 请求上出现意外的 EOF
【发布时间】:2016-07-05 08:08:29
【问题描述】:

我正在使用fetch api 发出POST 请求发送GraphQL

fetch( dbUrl, {
        method : 'post',
        body   : JSON.stringify( {
            graphql : "mutation M {saveUser(name:'Avraam')}"
        } )
    } )

在请求正文上我可以看得很清楚:

在我使用 restify 的服务器上,我有:

server.use( restify.bodyParser() );

import { GraphQLAnimationSchema } from '../schemas/GraphQLAnimationSchema';

const requestBuilder = query => graphql( GraphQLAnimationSchema, query )

...
...

export default {
    '/data' : {
        post : ( req, res ) => requestHandler( requestBuilder( req.body.graphql ), res )
};

GraphQL 响应与 {"errors":[{"message":"Syntax Error GraphQL request (1:1) Unexpected EOF\n\n1: \n ^\n"}]}

我应该使用特定类型的Headers,(我尝试过使用各种标题)但它似乎没有解决问题。

【问题讨论】:

    标签: javascript http-headers fetch restify graphql


    【解决方案1】:

    使用FormData解决

    const data = new FormData()
    data.append( 'graphql',  "mutation M {saveUser(name:'Avraam')}" )
    
    fetch( dbUrl, {
            method  : 'post',
            body : data
        } )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-22
      • 1970-01-01
      • 2022-12-06
      • 1970-01-01
      • 2014-01-01
      • 2022-07-08
      • 1970-01-01
      • 2018-04-18
      相关资源
      最近更新 更多