Questions tagged [apollo-cache-inmemory]

the default caching mechanism for apollo-server. For other questions related to caching with Apollo, please use the [apollo-server] tag.

Apollo Server natively let you cache responses in memory. To allow this type of cache, just add

cacheControl: {
    defaultMaxAge: <seconds>,
  },

to your Apollo Server configuration. Refer to the official Documentation about caching with Apollo Server for more informations about the available plugins and caching tecniques

64 questions
9
votes
1 answer

Apollo Client v3 Delete cache entries after given time period

I am wondering if there is a way to expire cached items after a certain time period, e.g., 24 hours. I know that Apollo Client v3 provides methods such as cache.evict and cache.gc which are a good start and I am already using; however, I want a way…
4
votes
1 answer

Apollo Graphql relayStylePagination prevents query to refetch on variables change

When I use relayStylePagination helper funtion in Apollo Client cache type policies, changing the variables passed to the query doesn't call the query again even if I call the refetch function manually. It perfectly does the fetchMore behavior and…
Mohammad K.
  • 238
  • 3
  • 12
4
votes
0 answers

Apollo Client: best practice to initialize cache with default values?

I've searched for a lot of tutorials about local state management with Apollo Client. To initialize the cache with some init values, from this example, I can do it with typePolicies. By defining reactive variables like this: const todosInitialValue…
4
votes
2 answers

How can I avoid "auto-update" cache when using `react-apollo-hooks` and `useSubscription` hook

I have some Apollo-Hooks code that uses useSubscription to listen for event changes in a subscription: useSubscription(MySubscription, { onSubscriptionData: async ({ client, subscriptionData: { data } }) => { if…
Brett
  • 11,637
  • 34
  • 127
  • 213
3
votes
0 answers

Leverage Apollo Cache

When upgrading to Apollo client 3.3, we decided to enable the caching in order to reduce network traffic and save computation power. We tried to implement something like this : cache: new InMemoryCache({ typePolicies: { VegaSpecification: { …
3
votes
2 answers

in apollo client pagination configuration with "merge" function, existing cached data always is empty even after calling fetchMore

I'm new to Apollo Client and I'm trying to implement pagination for my product list. but I can't figure out why the existing parameter in the merge function always returns empty. my incoming parameter always updates with a new list each time I call…
3
votes
0 answers

Is there a way to preload Apollo's cache-inmemory with raw data?

We don't have server currently. We're using Apollo client purely on client side with apollo-link-state and apollo-link-rest. I want to prevent the loading state of the application as I can have the raw data I would get from the REST endpoint during…
wintercounter
  • 7,500
  • 6
  • 32
  • 46
3
votes
0 answers

Do Apollo cache resolvers work for aliases?

Take these queries: query Foo(id: ID!) { foo(id: $id) { id bar { id } } } query Bar(id: ID!) { bar(id: $id) { id } } query Qux(id: ID!) { qux: bar(id: $id) { id } } As you can see, qux is an alias for…
3
votes
1 answer

Apollo GraphQL client doesn't return cached nested types in a query

I'm performing a query to get PowerMeter details in which contains another type inside called Project. I write the query this way: query getPowerMeter($powerMeterId: ID!) { powerMeter: powerMeter(powerMeterId: $powerMeterId) { id …
Pedro Arantes
  • 5,113
  • 5
  • 25
  • 60
3
votes
1 answer

How to disable InMemoryCache for Apollo GraphQL client?

I am trying to completely disable caching on the apollo-client but its not working. I have tried to set the fetchPolicy to 'network-only' or 'no-cache'. Is there something that I am missing?
Deepack
  • 77
  • 5
2
votes
1 answer

How to update nested structures in apollo cache using cache.modify

fragment commentFragment on Comment { id text galleryId commentUser { id firstName lastName } } fragment galleryFragment on Gallery { id path label comments { ...commentFragment } } We first retrieve the…
j10
  • 2,009
  • 3
  • 27
  • 44
2
votes
0 answers

React Apollo Cache updating delay after mutation to load new image

I do mutation to upload image as a result one url of type string changes to another in Apollo Cache. Delay is taking around 0,5 sec to update client cache. Problem: we show loader during image mutation is loading, after loading is done - old picture…
2
votes
1 answer

Graphql type with id property that can have different values for same id

I was wondering if an object type that has an id property has to have the same content given the same id. At the moment the same id can have different content. The following query: const query = gql` query products( $priceSelector:…
HMR
  • 37,593
  • 24
  • 91
  • 160
2
votes
0 answers

WriteQuery not writing object to apollo cache

I am trying to use Apollo Cache specifically for local state management. I am using Apollo Client 3. I am trying to write default state ( a simple object ) using writeQuery in the cache, but it doesn't get written in the cache. I can't find what I…
2
votes
0 answers

Apollo Cache ignoring Field Alias as key (MockedProvider)

I am seeing some differences in behaviour between ApolloProvider and MockedProvider and it's throwing an error in testing. Assuming I have the following query: query { Author { id: authorID name } } In ApolloProvider this query creates…
1
2 3 4 5