【问题标题】:Problem querying GraphQL with Gatsby-Apollo-Postgres setup: "Network error: failed to fetch" [apollo]使用 Gatsby-Apollo-Postgres 设置查询 GraphQL 时出现问题:“网络错误:无法获取”[apollo]
【发布时间】:2020-08-16 14:55:06
【问题描述】:

我正在使用 Gatsby、Apollo 和本地 Postgres 服务器。我想将 Apollo 连接到我的本地 postgres 数据库,以通过 GraphQL 查询动态地向 Gatsby 提供数据。

我在加载 Gatsby 页面时收到错误 $Network error: Failed to fetch

我遵循了 Gatsby-Apollo 示例模板 here。我在 ApolloClient 设置的uri 部分使用了postgres address

import ApolloClient from 'apollo-boost';
import fetch from 'isomorphic-fetch';

export const client = new ApolloClient({
  uri: 'postgres://MY_USER@localhost:5432/MY_DB', // I think this part is wrong
  fetch,
  fetchOptions: {
    "Access-Control-Allow-Origin": "*"
  },
});

在 chrome 控制台中,错误显示: URL scheme must be "http" or "https" for CORS request.

这让我觉得我需要一个“http”格式的 postgres 地址。我错过了什么?我是否需要使用nodejs创建自己的Apollo服务器,将其连接到postgres,然后在上面的uri参数中设置那个服务器地址?

【问题讨论】:

    标签: reactjs graphql gatsby react-apollo


    【解决方案1】:

    您正在尝试从 PostgreSQL 端点获取。您应该在那里放置一个 GraphQL 端点,例如 Apollo Server。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-18
      • 2021-10-04
      • 1970-01-01
      • 2019-07-19
      • 2019-09-04
      • 2021-07-06
      • 2019-12-03
      • 2023-03-03
      相关资源
      最近更新 更多