Git Product home page Git Product logo

Comments (4)

knaeckeKami avatar knaeckeKami commented on June 16, 2024 1

The cache will cache all queries, but it will cache them together with the arguments for paging, and if you read only the first page, it will only return the first page.

But you can add configuration to merge all pages together, like described here:

https://ferrygraphql.com/docs/cache-configuration#the-fields-property

from ferry.

knaeckeKami avatar knaeckeKami commented on June 16, 2024 1

For this, you will have to use the 'read' parameter on the FieldPolicy in order to execute your query based on the variables passed to your query.

from ferry.

GP4cK avatar GP4cK commented on June 16, 2024

Looking at the code, I think the issue comes from the FetchPolicyTypedLink that calls _writeToCache/cache.writeQuery which calls normalizeOperation but never passes the requestId.

@knaeckeKami do you think it'd be ok to pass the requestId in the data of resolveDataId? Then we could use the typePolicies to group the requests together.

from ferry.

rostaingc avatar rostaingc commented on June 16, 2024

In my use case, I have a table view and i can go to the first page, next page, previous page and last page, also I can apply filters and sorting.

So based on this documentation, I should be setting my ['filter', 'sorting'] as keyArgs as I do not want results of queries with different filters/sorting to be merged together.

How to handle the fact that the user may navigate to the first page, then the last page, then press previous etc.
All the results will be added in some random order to my cache ?

Also I will need to not only merge the edges together in my result but also compute the pageInfo to get the startCursor, endCursor and hasNextPage.

query ProjectPhotos(
  $filter: ProjectPhotoFilter!
  $paging: CursorPaging!
  $sorting: [ProjectPhotoSort!]
) {
  projectPhotos(filter: $filter, paging: $paging, sorting: $sorting) {
    edges {
      node {
        id
        name
      }
    }
    pageInfo {
      startCursor
      endCursor
      hasNextPage
    }
    totalCount
  }
}

    'Query': TypePolicy(
      fields: {
        'projectPhotos': FieldPolicy(
          keyArgs: const ['filter', 'sorting'],
          merge: (existing, incoming, option) {
            if (existing == null) return incoming;
            final existingEdges = (existing['edges'] as List<dynamic>?) ?? [];
            final incomingEdges = (incoming['edges'] as List<dynamic>?) ?? [];
            final mergedEdges = (LinkedHashSet<dynamic>(equals: jsonMapEquals, hashCode: const DeepCollectionEquality().hash)
                  ..addAll(existingEdges)
                  ..addAll(incomingEdges))
                .toList();
            return incoming['edges'] = mergedEdges;
          },
        ),
      },
    ),

from ferry.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.