使用aws-appsync获取实时数据。但是,当我关闭模拟器的Internet连接时,会出现这样的错误。我做了很多研究,但没有。我在等你的帮助。我通过Google翻译将本文翻译成英文。
const client = new AWSAppSyncClient({
url: appSyncConfig.graphqlEndpoint,
region: appSyncConfig.region,
auth: {
type: appSyncConfig.authType,
apiKey: appSyncConfig.apiKey,
},
offlineConfig : {
callback : ( err ) => {
if (err) {
console.warn('error');
}
},
},DisableOffline: false
},);
export default class App extends Component {
constructor(props) {
super(props);
this.state = { name: "", link: "" ,veri:[],loading:false};
}
componentDidMount(){
client.onConnectionLost = ({ errorCode, ...args }) => {
if (errorCode !== 0) {
console.warn('error1');
}
else
{
console.warn('error2');
}
};
}
render(){
return(
<ApolloProvider client={client}>
<Rehydrated>
<Appy />
</Rehydrated>
</ApolloProvider>
)
}
}
其他文件
const ListAppps = gql`query listAppps {
listAppps {
items {
id
name
link
__typename
}
}
}`;
const OnCreateAppp = gql`subscription onCreateAppp {
onCreateAppp {
id
name
link
}
}`;
class Appy extends Component {
componentDidMount() {
this.props.data.subscribeToMore(
buildSubscription(OnCreateAppp, ListAppps)
)
}
render() {
return (
<View>
{
this.props.posts.map((post, index) => (
<Text key={index}>{JSON.stringify(post.name)}</Text>
))
}
</View>
)
}
}
export default graphql(ListAppps, {
options: {
fetchPolicy: 'cache-and-network'
},
props: props => ({
posts: props.data ? props.data.listAppps.items : [],
data: props.data
}),
})(Appy)