10. Schema changes in the client
1m

Working directly with the cache

We can:

  • Write directly to the cache, updating data objects manually.
  • Instruct the cache how to read values from the cache, applying transformations or making modifications as needed.
  • Specify how queries work with the cache, and whether they check the cache for existing data or always make a new network request.

The plan

  1. Define how to read the numberOfLikes field from the cache (using the read function)
  2. Query for numberOfLikes as a client-only field directly in our component (using the @client directive).

read function syntax

cache: new InMemoryCache({
typePolicies: {
Book: {
// name of the type
fields: {
title: {
// name of the field
read() {
// code goes here
}
}
}
}
}
});

The @client directive

Add @client after the name of the field in your query.

Previous
Next