React-Native + Apollo-Link-State + AWS Appsync : Defaults are not stored in cache

元气小坏坏 提交于 2019-12-25 00:16:05

问题


I'm struggling with this for days.

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 })

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 still contains __typename: 'CurrentUser', username: '', thumbnailUrl: ' but doesn't contains foo: 'bar'. And the cache doensn't containshello: 'bar'oruserSettings`.

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).

I'm completely clueless.

Context :

  • It happens in the iOS simulator
  • I'm debugging watching the redux cache of appsync
  • apollo-cache-inmemory: 1.2.8
  • apollo-client: 2.3.5
  • apollo-link: 1.2.2
  • apollo-link-state: 0.4.1
  • aws-appsync: 1.3.2

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


回答1:


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

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.

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



来源:https://stackoverflow.com/questions/52293930/react-native-apollo-link-state-aws-appsync-defaults-are-not-stored-in-cach

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!