Javascript 获取graphql列表时获取错误

Javascript 获取graphql列表时获取错误,javascript,reactjs,graphql,fetch,Javascript,Reactjs,Graphql,Fetch,在react应用程序中尝试使用graphql获取列表时,我总是遇到相同的错误 我的问题如下: const query = `{ getConstructionNumberListing(filter: "{\"subProject__id\": \"36\"}") { edges { node { id, constructionNumber, indicative

在react应用程序中尝试使用graphql获取列表时,我总是遇到相同的错误

我的问题如下:

const query = `{
  getConstructionNumberListing(filter: "{\"subProject__id\": \"36\"}") {
    edges {
      node {
        id,
        constructionNumber,
        indicativePrice,
        definitivePrice,
        isDefinitive,
        housingType {
          ... on object_HousingType {
            id,
            description
          }
        }
      }
    },
    totalCount
  }
}`

const url = constants.api.url;
  const body = JSON.stringify({
    query: query,
  })
 
  return new Promise((resolve) => {

    fetch(url, {
      method: 'POST',
      headers: new Headers(),
      body: body
    })

      // Parse the response
      .then(res => res.json())

      // Trigger the callback if no errors were thrown
      .then(res => {
        console.log('res', res)
        resolve(res);
      })
      .catch(er => resolve(er))
  })
获取react时出现以下错误:

{message: "Syntax Error: Expected :, found String \": \"", extensions: {category: "graphql"}, locations: [{line: 2, column: 57}]}
谁能帮我解决这个问题?其他类似于以下的查询可以正常工作

{
  getProjectListing(after: 0) {
      edges {
          node {
              id
              projectName
          }
      }
  }
}
还要提到的是,查询在Postman中运行良好,语法来自文档:


您可以使用apollo client之类的库在react中发送graphql查询:

{message: "Syntax Error: Expected :, found String \": \"", extensions: {category: "graphql"}, locations: [{line: 2, column: 57}]}

您的
过滤器
值不是有效的语法,不确定要执行什么操作,但它可能看起来像:

{
  getConstructionNumberListing(filter: "{ subProject__id: 36 }") {
    ...
  }
}

谢谢你的帮助。如果我尝试这样做,那么我会得到以下错误:res对象数据:Object getConstructionNumberList:null对象原型错误:数组(1)0对象扩展:{category:“pimcore.datahub”}位置:[{line:2,column:3}](1)消息:“无法解码筛选器”路径:[“getConstructionNumberList”](1)对象原型语法来自文档:感谢您的awnser,但我只想使用fetch。应该可能是“内容类型”:“应用程序/json”。。此外,您还应该使用“查询变量”传递参数(参见文档),在操场中测试(使用变量),然后在代码中重新创建,在遇到问题时比较原始请求的详细信息