Open sfegsetsfe opened 5 years ago
@sfegsetsfe how did you configured the client (link)?
I used the exact config from @manueliglesias (except the client.mutation
testing part ). Which was:
import { ApolloLink } from 'apollo-link';
import { withClientState } from 'apollo-link-state';
import AWSAppSyncClient, { createAppSyncLink, createLinkWithCache } from "aws-appsync";
const stateLink = createLinkWithCache(cache => withClientState({
cache,
resolvers: {
Mutation: {
updateNetworkStatus: (_, { isConnected }, { cache }) => {
const data = {
networkStatus: {
__typename: 'NetworkStatus',
isConnected
},
};
cache.writeData({ data });
return null
},
},
},
defaults: {
networkStatus: {
__typename: 'NetworkStatus',
isConnected: false
}
}
}));
const appSyncLink = createAppSyncLink({
url: appSyncConfig.graphqlEndpoint,
region: appSyncConfig.region,
auth: {
type: appSyncConfig.authenticationType,
apiKey: appSyncConfig.apiKey
}
});
const link = ApolloLink.from([stateLink, appSyncLink]);
const client = new AWSAppSyncClient({}, { link });
const result = await client.mutate({
mutation: gql`mutation updateNetworkStatus($isConnected: Boolean) {
updateNetworkStatus(isConnected: $isConnected) @client {
isConnected
}
}`,
variables: { isConnected: true }
});
console.log(result);
Is this ever going to be fixed?
@usmansbk we are still researching Apollo Link State, which at this time isn't fully supported in the SDK due to how cache can be manipulated out of the standard process. We have some ideas here and some prototype code but it will still take some time to fully support. In the meantime we recommend using the SDK without Apollo Link State.
Follow instruction of this post https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/24#issuecomment-382066010.
If we delete the
client.mutate(...)
part at the bottom, but do aconsole.log(client.cache.data.data)
, which supposed to hold the default value set inwithClientState
, it will be an empty object. But if we add back theclient.mutate(...)
, the default value set will appear in the `console.log(client.cache.data.data)`` call.Also, changing
client.mutate(...)
toto query the
networkStatus
field will result in errorNetwork error: Cannot read property 'networkStatus' of null
.