【发布时间】:2020-07-03 08:58:25
【问题描述】:
我在开始使用 React、Apollo 和 AWS-AppSync 时遇到了问题。我无法解决此错误消息:
TypeError: this.currentObservable.query.getCurrentResult is not a function
我正在使用 @apollo/react-hooks 和 aws-appsync 的更新包。
我当前的设置如下所示。
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import config from './aws-exports';
import AWSAppSyncClient from 'aws-appsync';
import { ApolloProvider } from '@apollo/react-hooks';
const client = new AWSAppSyncClient({
url: config.aws_appsync_graphqlEndpoint,
region: config.aws_appsync_region,
auth: {
type: config.aws_appsync_authenticationType,
apiKey: config.aws_appsync_apiKey
}
});
ReactDOM.render(
<ApolloProvider client={client}>
<React.StrictMode>
<App />
</React.StrictMode>
</ApolloProvider>,
document.getElementById('root')
);
我有一个函数可以进行如下查询:
import React from 'react';
import { useQuery } from '@apollo/react-hooks';
import gql from 'graphql-tag';
const Flavors = () => {
const GET_FLAVORS = gql`
query listAll {
items {
name,
image
}
}
`;
const { loading, error, data } = useQuery(GET_FLAVORS);
if(loading) return <p>loading...</p>
if(error) return <p>Something went wrong...</p>
return (
<div>
{
data.listIceCreamTypes.items.map(type => {
return <div key={type.name}>
<img src={type.image} alt={type.name} />
<h1>{type.name}</h1>
</div>
})
}
</div>
)
}
export default Flavors;
我经历了https://github.com/apollographql/react-apollo/issues/3148 中描述的各种解决方案,例如添加:
"resolutions": {
"apollo-client": "2.6.3"
}
到 package.json。然后重新运行 npm install 并重新启动服务器。
似乎没有什么能解决我的问题。
编辑**这里是重现问题的回购:https://github.com/Rynebenson/IceCreamQL
【问题讨论】:
标签: graphql react-apollo apollo-client aws-appsync