【发布时间】: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