【发布时间】:2019-02-17 00:30:51
【问题描述】:
我为此苦苦挣扎了好几天。
一个月前,我已经成功地使用 AppSync 配置了 Apollo-Link-State,并开始像这样添加默认值和解析器:
const cache = new InMemoryCache() //create the cache to be shared by appsync and apollo-link-state
const appSyncAtrributes = {
//...
//setup appSync
}
const stateLink = createLinkWithCache(() => withClientState({
cache,
resolvers: {
Mutation: {
updateCurrentUser: (_, { username, thumbnailUrl }, { cache }) => {
// ...
// working mutation that store the login information when user authenticate.
}
}
},
defaults: {
currentUser: {
__typename: 'CurrentUser',
username: '',
thumbnailUrl: ''
}
}
}))
const appSyncLink = createAppSyncLink({
url: appSyncAtrributes.graphqlEndpoint,
region: appSyncAtrributes.region,
auth: appSyncAtrributes.auth,
complexObjectsCredentials: () => Auth.currentCredentials()
})
const link = ApolloLink.from([stateLink, appSyncLink])
const client = new AWSAppSyncClient({}, { link })
它工作了这么久(我正在调用 @client 突变并围绕我的应用进行查询)。
但现在我正尝试在我的链接状态中添加其他数据(其他一切都保持不变):
defaults: {
currentUser: {
__typename: 'CurrentUser',
username: '',
thumbnailUrl: '',
foo: 'bar',
},
hello: 'world',
userSettings: {
__typename: 'userSettings',
isLeftHanded: true
}
}
而且我的缓存没有更新。我的意思是:
currentUser 仍然包含 __typename: 'CurrentUser', username: '', thumbnailUrl: ' 但不包含 foo: 'bar'. And the cache doensn't containshello: 'bar'oruserSettings`。
更令人困惑的是,如果我给username 或thumbnailUrl 赋值,比如username: 'joe',缓存实际上反映了这种变化! (忽略我所有的其他修改)
我尝试了这个实验的所有变体并清除了所有缓存(甚至在新同事的计算机上运行它以确保它们不涉及脏缓存)。
我一无所知。
上下文:
- 它发生在 iOS 模拟器中
- 我正在调试查看 appsync 的 redux 缓存
- apollo-cache-inmemory:1.2.8
- apollo 客户端:2.3.5
- 阿波罗链接:1.2.2
- 阿波罗链路状态:0.4.1
- aws-appsync:1.3.2
更新:实际上 currentUser 既不是从默认值存储的。调用突变时它会进入缓存。
【问题讨论】:
标签: ios react-native apollo apollo-client apollo-link-state