【发布时间】:2021-04-01 09:07:10
【问题描述】:
我建立了一个 gastby 项目。我想和 apollo-client 一起工作。我安装了插件“gatsby-plugin-apollo”,我也将它插入到配置文件的插件数组中。我创建了一个客户端并将其添加到 ApolloProvider。当我尝试将它与现有查询一起使用时,出现错误:
这是我的客户:
//client.js
import fetch from 'isomorphic-fetch';
import { ApolloClient, InMemoryCache, HttpLink } from '@apollo/client';
import { backendUrl } from "../constants/constants"
const client = new ApolloClient({
cache: new InMemoryCache(),
link: new HttpLink({
uri: backendUrl,
fetch
})
});
export default client
这是我在 gatsby-ssr 和 gatsby-browser 文件中导出的 wrapRootElement
import React from 'react';
import { ApolloProvider } from '@apollo/client';
import client from "./client"
import AuthProvider from '../context/auth';
export const wrapRootElement = ({ element }) => {
return (
<ApolloProvider client={client}>{element}</ApolloProvider>
)
};
【问题讨论】:
标签: node.js graphql gatsby apollo apollo-client