GithubHelp home page GithubHelp logo

cidem / apollo-pagination Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 28 KB

How to properly do cursor pagination with useLazyQuery

License: MIT License

Go 31.73% Nix 7.77% Dockerfile 2.02% HTML 3.69% CSS 18.14% TypeScript 36.66%

apollo-pagination's Introduction

Quick Start

$ docker compose up --build
$ open http://localhost:5137/

This will start a Golang GraphQL server that is running at http://localhost:8080/query and it will also start Vite in development mode. You can access the website that it generates at http://localhost:5137. Hot reloading should work just fine.

What's the Problem

The issue this repository demonstrates is how to use pagination in combination with useLazyQuery. If you load the page, just click "next" and observe the network requests. You'll see that it makes a network request that returns new edges, but the app does not update.

Here are the steps to reproduce the issue:

  1. docker compose up --build
  2. open http://localhost:5137/
  3. Open network tab in browser
  4. Click "next"

The POST request returns the following two edges:

  • { node: "bus station", cursor: "bus station", __typename: "FooEdge" }
  • { node: "bus terminal", cursor: "bus terminal", __typename: "FooEdge" }

The app does not update though and still shows the first two edges.

Requirements

When the app loads, "bus" is already entered into the input field.

When a user now clicks "next", the list should show the following, two results:

  • bus station
  • bus terminal

When a user clicks "next" again, the list should show the following result:

  • bus tires

Solution

By adding ["query"] to the list of keyArgs Apollo now correctly updates the cache. Furthermore, make sure to return incoming and not incoming.edges from the merge function.

apollo-pagination's People

Contributors

cidem avatar

Watchers

 avatar  avatar

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.