0
votes

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

1 Answers

1
votes

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