如何使用内置缓存在AppSyncClient中保持“默认”本地状态

时间:2019-01-20 05:58:36

标签: react-native aws-appsync

AWSAppSyncClient不持久localstate。先前更新的本地状态将丢失。应用重新启动后,本地状态将重置为defaults。即 登录后使用客户端突变成功更新me状态。 重新启动应用程序后,me状态将恢复为默认的Offline user

网络QueryMutation正常工作。

在将apollo-persist-cache传递给withClientState之前,我曾尝试使用InMemoryCache,但它破坏了离线功能并引入了不一致的数据。 使用自定义import { defaults, resolvers } from '../graphql/localstate'; // Before login // { // me: { // __typename: 'User', // id: '1', // name: 'Offline user', // email: 'help@problems.com', // pictureUrl: null // }, // } // After login // { // me: { // __typename: 'User', // id: 'aws-cognito-idenitity-id', // name: 'Gnu user', // email: 'my@example.com', // pictureUrl: "https://s3.amazon..." // }, // } const stateLink = createLinkWithCache(cache => withClientState({ cache, resolvers, defaults })); const appSyncLink = createAppSyncLink({ url: aws_config.aws_appsync_graphqlEndpoint, region: aws_config.aws_appsync_region, auth: { type: aws_config.aws_appsync_authenticationType, credentials: () => Auth.currentCredentials() } }); const link = ApolloLink.from([stateLink, appSyncLink]); const client = new AWSAppSyncClient({}, { link }); client.onResetStore(stateLink.writeDefaults); export default client; 也会破坏离线功能。

// Inside App.js

<ApolloProvider client={client}>
    <Rehydrated>
        <AppContainer/>
    </Rehydrated>
</ApolloProvider>
AWSAppSync

我希望localstate脱机功能能够处理aws-appsync-react的持久性,并使用Rehydrated style = window.getComputedStyle(dom, null) 组件对其进行还原。

更新

  

@usmansbk我们仍在研究Apollo链接状态,由于无法在标准过程中操纵缓存,因此目前SDK中尚未完全支持该状态。我们在这里有一些想法和一些原型代码,但是仍然需要一些时间才能完全支持。同时,我们建议使用不带Apollo链接状态的SDK。

0 个答案:

没有答案
相关问题