Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

limit `cache` methods to be within operations and add discloser (#1726)

authored by

Jovi De Croock and committed by
GitHub
b9e173ee db28dda4

+35 -10
+35 -10
docs/graphcache/local-resolvers.md
··· 385 385 a separate virtual operation in our resolvers. When we call `cache.readQuery` with a query and 386 386 variables we can execute an entirely new GraphQL query against our cached data: 387 387 388 - ```js 389 - cache.readQuery({ query: Todos, variables: { from: 0, limit: 10 } })` 388 + ```js 389 + import { gql } from '@urql/core'; 390 + import { cacheExchange } from '@urql/exchange-graphcache'; 391 + 392 + const cache = cacheExchange({ 393 + updates: { 394 + Mutation: { 395 + addTodo: (result, args, cache) => { 396 + const data = cache.readQuery({ query: Todos, variables: { from: 0, limit: 10 } }); 397 + } 398 + } 399 + } 400 + }) 390 401 ``` 391 402 392 403 This way we'll get the stored data for the `TodosQuery` for the given `variables`. ··· 400 411 401 412 ```js 402 413 import { gql } from '@urql/core'; 414 + import { cacheExchange } from '@urql/exchange-graphcache'; 403 415 404 - const data = cache.readFragment( 405 - gql` 406 - fragment _ on Todo { 407 - id 408 - text 416 + const cache = cacheExchange({ 417 + resolvers: { 418 + Query: { 419 + Todo: (parent, args, cache) => { 420 + return cache.readFragment( 421 + gql` 422 + fragment _ on Todo { 423 + id 424 + text 425 + } 426 + `, 427 + { id: 1 } 428 + ); 429 + } 409 430 } 410 - `, 411 - { id: 1 } 412 - ); 431 + } 432 + }) 413 433 ``` 414 434 415 435 > **Note:** In the above example, we've used ··· 420 440 case `{ id: 1 }`. 421 441 422 442 [Read more about `cache.readFragment` in the Graphcache API docs.](../api/graphcache.md#readfragment) 443 + 444 + ### Cache methods outside of `resolvers` 445 + 446 + The cache read methods are not possible outside of GraphQL operations. This means these methods will 447 + be limited to the different `Graphcache` configuration methods. 423 448 424 449 ## Pagination 425 450