React-Native + Apollo-Link-State + AWS Appsync:默认值不存储在缓存中 [英] React-Native + Apollo-Link-State + AWS Appsync : Defaults are not stored in cache

查看:96
本文介绍了React-Native + Apollo-Link-State + AWS Appsync:默认值不存储在缓存中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为此苦苦挣扎了几天.

I'm struggling with this for days.

一个月前,我已经使用AppSync成功配置了Apollo-Link-State,并开始添加默认值和解析器,如下所示:

I've successfully configure Apollo-Link-State with AppSync a month ago and start adding defaults and resolvers like this :

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变异并进行查询).

So long it worked (I'm calling the @client mutation and query around my app).

但是现在我试图在链接状态"中添加其他数据,因为这(其他所有内容保持不变):

But now I'm trying to add other data in my Linked State as this (everything else stayed the same):

 
defaults: {
    currentUser: {
        __typename: 'CurrentUser',
        username: '',
        thumbnailUrl: '',
        foo: 'bar',
    },
    hello: 'world',
    userSettings: {
        __typename: 'userSettings',
        isLeftHanded: true
    }
}

我的缓存没有更新.我的意思是:

And my cache doesn't update. I mean :

currentUser仍然包含__typename: 'CurrentUser', username: '', thumbnailUrl: ',但不包含foo: 'bar'. And the cache doensn't contains hello:"bar" or userSettings`.

currentUser still contains __typename: 'CurrentUser', username: '', thumbnailUrl: ' but doesn't contains foo: 'bar'. And the cache doensn't containshello: 'bar'oruserSettings`.

更令人困惑的事实是,如果我给usernamethumbnailUrl一个值,例如username: 'joe',则缓存实际上反映了这一变化! (而忽略了我所有其他修改)

More confusing is the fact that if I give a value to username or thumbnailUrl like username: 'joe', the cache actually reflect that change! (while ignoring all my other modifications)

我尝试了该实验的所有变体,并清除了所有缓存(甚至在新同事的计算机上运行它,以确保它们不涉及脏缓存).

I tried all variation of this experiment and cleared all caches (even running it on a fresh colleague computer to be sure they were no dirty cache involved).

我完全一无所知.

上下文:

  • 它在iOS模拟器中发生
  • 我正在调试中观看appsync的redux缓存
  • apollo-cache-memory:1.2.8
  • 阿波罗客户端:2.3.5
  • 阿波罗链接:1.2.2
  • apollo-link-state:0.4.1
  • aws-appsync:1.3.2

更新:实际上,从默认值开始都不存储currentUser.当突变被调用时,它进入缓存.

Update : Actually currentUser is not stored neither from defaults. It get into the cache when the mutation is called.

推荐答案

好吧,我的问题毕竟不是问题(浪费了2天).

Ok my issue wasn't an issue after all (2 days wasted).

问题是缺少适当的调试工具(不得不观察缓存通过redux演变). 缓存实际上已正确写入,但未在任何地方显示.

The lack of proper debug tools (had to watch the cache evolving thru redux) was the issue. The cache is actually written correctly but doesn't show anywhere.

当我开始查询该缓存时,一切正常.

As soon as I start querying that cache, everything worked.

不能等待react-native-debugger集成适当的apollo/graphql分析器

Can't wait for react-native-debugger to integrate a proper apollo/graphql analyser

这篇关于React-Native + Apollo-Link-State + AWS Appsync:默认值不存储在缓存中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆