menu

Apollo

A community of developers, designers and others who love Apollo and GraphQL. 🚀

Channels
# All channels
view-forward
# General
view-forward
# Apollo Angular
view-forward
# Announcements
view-forward
# Apollo Android
view-forward
# Apollo Client
view-forward
# Apollo iOS
view-forward
# Apollo Link
view-forward
# Apollo Link Rest
view-forward
# Local State
view-forward
# Apollo Studio
view-forward
# Apollo Server
view-forward
# Apollo Tooling
view-forward
# Contributing
view-forward
# Docs
view-forward
# Events
view-forward
# GraphQL Tools
view-forward
# Jobs
view-forward
# Random
view-forward
# React Apollo
view-forward
# Showcase
view-forward
# Subscriptions
view-forward
# Testing
view-forward
# Vue Apollo
view-forward
Team

What's the best way to read / write cache data

July 22, 2020 at 10:36am

What's the best way to read / write cache data

July 22, 2020 at 10:36am (Edited 2 months ago)
I'm currently building an app using apollo-angular and I want to cache logged in user data. Currently, I'm using mutation for the login process and adding a customId in thememoryCache like this
const cache = new InMemoryCache({
dataIdFromObject(responseObject) {
switch(responseObject.__typename){
case 'User': return 'CurrentUser'
default: return defaultDataIdFromObject(responseObject)
}
}
})
and then when I need to get that data I use the readFragment() method like so:
return this.apollo.getClient().readFragment({
id: 'CurrentUser',
fragment: ReaderDataFragmentDoc,
fragmentName: 'userData'
})
I do have a couple fragment setup, and the userData is one of them.
Is there a better way to do this process?
No messages yet