【问题标题】:SyntaxError: Unexpected token < in JSON at position 0 (gatsby and graphql)SyntaxError: Unexpected token < in JSON at position 0 (gatsby and graphql)
【发布时间】:2019-03-04 17:42:11
【问题描述】:

我正在尝试将我的 react 应用程序(使用 gatsby)连接到运行 Drupal 实例以使用 GraphQL 执行查询的 XAMPP 服务器。我不断收到有关我的配置文件的错误消息:

error Plugin gatsby-source-graphql returned an error
SyntaxError: Unexpected token < in JSON at position 0

这是我的配置文件代码:

 module.exports = {
  siteMetadata: {
   title: 'Gatsby Default Starter',
  },
  plugins: [
  {
   resolve: "gatsby-source-graphql",
   options: {
    typeName: "DRUPAL",
    fieldName: "drupal",
    url: "http://localhost:8888/graphql",
   },
  },
 ],
}

我已经尝试使用和不使用最后一个“/graphql”的 localhost,只是“localhost”,但没有任何效果。我已经重新启动了我的前端和后端服务器两次。

编辑: 当我进入“http://localhost:8888/graphql”时,它会返回:

{"errors":[{"message":"GraphQL Request must include at least one of those two parameters: \u0022query\u0022 or \u0022queryId\u0022","category":"request"}]}

【问题讨论】:

    标签: json reactjs graphql gatsby


    【解决方案1】:

    我认为包含错误的不是您的配置文件,而是http://localhost:8888/graphql 背后的服务。 当期望 JSON 时,它可能会返回 HTML 页面(错误页面?)或 XML 内容。

    【讨论】:

    • 当我进入 "localhost:8888/graphql" 时,它会返回:{"errors":[{"message":"GraphQL 请求必须至少包含这两个参数之一:\u0022query\ u0022 或 \u0022queryId\u0022","category":"request"}]}
    • 尝试找出你的 react 应用程序真正收到了什么。如果它在浏览器中运行,请使用开发人员工具中的网络选项卡查看结果。它可能取决于请求的内容类型、确切的参数等。
    猜你喜欢
    • 1970-01-01
    • 2021-09-30
    • 2017-12-15
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-04
    相关资源
    最近更新 更多