aws-mobile-appsync-sdk-js
aws-mobile-appsync-sdk-js copied to clipboard
disabling __typename in responses
A __typename field was being included in all my query responses which was causing crashes in mutation when the same data was passed to mutation. It would be time consuming to manually remove all __typename field or to add __typename in all input types in mutation schema in server. After digging into the aws-appsync code a bit I found ApolloReducerConfig which accepts something called 'addTypename'. So this is how I'm initialising my client now with cacheOptions addTypename = false:
const AppSyncConfig = {
url: appSyncUrl,
region: aws_config.AppSync.Default.Region,
auth: {
type: aws_config.AppSync.Default.AuthMode,
jwtToken: token,
cacheOptions: {
addTypename: false
}
};
client = new AWSAppSyncClient(AppSyncConfig, {
link: createAppSyncLink({
...AppSyncConfig,
resultsFetcherLink: ApolloLink.from([
setContext(setHeaders),
createHttpLink({
uri: AppSyncConfig.url
})
])
})
});
Will removing that field cause any unexpected behaviour?
Version: aws-appsync: 1.7.1
If you're only using basic caching, it shouldn't impact your results. It will impact any uses of Fragments or Unions, which are more advanced Apollo features. addTypeName: false fixed a lot of my app's caching issues.
Does anyone know if this can be disabled at a query/mutation level, rather than globally?