【发布时间】:2021-10-03 13:07:50
【问题描述】:
我正在 Shopify 上开发一个应用程序,我包含了 GraphQL,但我开始遇到相关错误。以前我还遇到了网络错误,在添加了几行之后,我摆脱了“网络错误”,但我仍然遇到了麻烦。请帮帮我!
_app.js
import React from 'react';
import App from 'next/app';
import Head from 'next/head';
import { AppProvider } from "@shopify/polaris";
import translations from "@shopify/polaris/locales/en.json";
import "@shopify/polaris/dist/styles.css";
import { ApolloClient, HttpLink, ApolloLink, InMemoryCache, concat } from '@apollo/client';
//import { ApolloClient } from 'apollo-client';
import { createHttpLink } from 'apollo-link-http';
//import { InMemoryCache } from 'apollo-cache-inmemory';
import {ApolloProvider} from 'react-apollo'
const client = new ApolloClient({
link: new createHttpLink({
credentials: 'include',
headers: {
'Content-Type': 'application/graphql',
},
}),
cache: new InMemoryCache(),
})
/*
import ApolloClient from 'apollo-boost';
import {ApolloProvider} from 'react-apollo'
const client = new ApolloClient({
fetchOptions: {
uri:'/graphql',
credentials: 'include'
},
});
*/
class MyApp extends App {
render()
{
const {Component, pageProps} = this.props;
return(
<React.Fragment>
<Head>
<title>Elena App</title>
<meta charSet="utf-8"/>
</Head>
<AppProvider i18n={translations}>
<ApolloProvider client={client}>
<Component {...pageProps} />
</ApolloProvider>
</AppProvider>
</React.Fragment>
);
}
}
export default MyApp;
【问题讨论】:
-
如果需要 server.js,我是相当新的,我可以在那里发布
-
是的,请发布 server.js
-
感谢您的关心,问题似乎已解决 const client = new ApolloClient({ uri:'/graphql', fetchOptions:{ credentials:'include' }, cache: new InMemoryCache(),//I添加了这一行,问题似乎现在已经解决了。});
标签: node.js reactjs graphql shopify