Coder Social home page Coder Social logo

Comments (4)

solher avatar solher commented on August 27, 2024 1

I'm going to work on it ;)

from relay.

solher avatar solher commented on August 27, 2024

There is an issue as a lot of databases doesn't support the backward pagination.

The simplest solution would be to sort the results backward before applying the limit/offset.
We would maybe need a third return boolean parameter reverse.
Or maybe use negative offset and limit values.

from relay.

sogko avatar sogko commented on August 27, 2024

hi @solher thanks for taking your time to look into this project, appreciate it very much 👍🏻

If the client asks for the first two elements, we potentially query 10000 documents from the database before throwing away the 9998 we don't want.

So the example solution you gave seems about right and it would address your issue, except that current relay-go library is missing a couple of pieces that would help to make it work

  • relay.computeOffset: Actually there is already relay.getOffset().
    It translates a connection cursor string to an offset value that you can use to construct your query for your data source (SQL, Mongo etc)
    This is currently a private method. This should be exposed and make it available.
  • relay.ConnectionFromArray() assume that the input data is static or representative of the whole data collection. Thats why currently your implementation might have to get every data for it to return correct cursor Connection value. And you are right to think that this is not ideal.

The missing piece is actually relay.ConnectionFromSliceArray() introduced a couple of months back in relay-js.
This has not been ported to relay-go

{ConnectionFromSliceArray} effectively allows you to fetch the data for a subset of a connection, and pass that in with some metadata indicating where the subsequence starts and how long the total array would be if materialized, and get a connection object back.

I can't personally commit when these changes would be made available but PRs are greatly welcomed!

Hope this answers your question!

TODO:

  • Expose relay.GetOffset()
  • Port and expose relay.ConnectionFromSliceArray()
  • Secondary todo: Port latest changes from relay-js to relay-go (From 0.3.2 to 0.3.6)

from relay.

sogko avatar sogko commented on August 27, 2024

Merged PR #22
Thanks @solher 👍🏻

from relay.

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.