node.js - GraphQL JSON输入的意外结束
问题描述
我正在 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;
解决方案
const client = new ApolloClient({
uri:'/graphql',
fetchOptions:{
credentials:'include'
},
cache: new InMemoryCache(),//I add this line and problem fixed
});
另外,我将graphql的api版本更改为October20
推荐阅读
- php - 如何从php中的文本文件在数组中创建数组
- python - 如何在 Pycharm 中显示官方 sphinx 示例和模块文档
- javascript - 在 Electron 中包含两个窗口的两个 html 文件
- flutter - 在颤动中使用导航器后黑屏
- javascript - 如何将拆分数字合并为一个数字?
- flutter - Flutter 向 StatefulWidget 传递数据
- android - 调用 Geocoder 方法时如何显示进度对话框
- scala - 在scala中传递函数调用作为参数,函数首先评估吗?
- java - 我在发送屏幕截图时遇到错误
- java - 使用扫描仪读取“干净”文本文件时是否有任何解析?