Coder Social home page Coder Social logo

Comments (15)

xoldd avatar xoldd commented on September 18, 2024 1

Would depend on how the query is modified in the backend. A proper approach should be established first.

I've documented the standard approach to be followed throughout talawa-api for implementing pagination using the graphql connections:- https://docs.talawa.io/docs/developers/talawa-api/pagination

Implement pagination for EventsByOrganization

Again, REST like patterns should not to be followed with graphql, relationships and fetching patterns should be expressed in the graph. This is an anti-pattern:-

type Query {
  eventsByOrganization(organizationID: ID!): EventsConnection
}

The events associated to an organization should be exposed like this:-

type Organization {
  events: EventsConnection
}

On the client side querying for the events within an organization would look like this:-

type OrganizationEventsQuery($cursor: String, $limit: Int!, $organizationID: ID!) {
  organization(id: $organizationID) {
    address
    phoneNumber
    events(first: $limit, after: $cursor) {
      edges {
        cursor
        node {
          id
          ...other event fields
        }
      }
      pageInfo {
      ... fields
      }
    }
  }
  name
}

The advantage here is that you can fetch other fields like address, phoneNumber, name etc., that exist on the organization along with the events associated to that organization. This is more efficient because the client only sends 1 network request to fetch everything that is needed. The server takes care of resolving everything listed in the query.

When the next set of events are to be fetched(connection is to be traversed further) a new network request would be made with a non-null value for the $cursor variable. This time there's no need to fetch the organization fields like address, phoneNumber, name etc., because they were already fetched by the very first network request. This would look like this:-

type OrganizationEventsQuery($cursor: String, $limit: Int!, $organizationID: ID!) {
  organization(id: $organizationID) {
    events(first: $limit, after: $cursor) {
      edges {
        cursor
        node {
          id
          ...other event fields
        }
      }
      pageInfo {
      ... fields
      }
    }
  }
}

To understand how the client implementation would work, take a read:-

  1. https://www.apollographql.com/docs/react/pagination/overview
  2. https://www.apollographql.com/docs/react/pagination/core-api
  3. https://www.apollographql.com/docs/react/pagination/cursor-based#relay-style-cursor-pagination
  4. https://commerce.nearform.com/open-source/urql/docs/basics/ui-patterns/#infinite-scrolling
  5. https://commerce.nearform.com/open-source/urql/docs/graphcache/local-resolvers/#pagination

from talawa-api.

Azad99-9 avatar Azad99-9 commented on September 18, 2024 1

Yes kindly do it. Thanks.

from talawa-api.

palisadoes avatar palisadoes commented on September 18, 2024

@aashimawadhwa @rishav-jha-mech @DMills27 PTAL and comment

from talawa-api.

palisadoes avatar palisadoes commented on September 18, 2024

@xoldd This was discussed frequently in the past, however related to news feeds. PTAL too

from talawa-api.

palisadoes avatar palisadoes commented on September 18, 2024

@Azad99-9 @meetulr Do you think this can be implemented without the UI/UX functionality being affected for both Admin and Mobile?

from talawa-api.

Azad99-9 avatar Azad99-9 commented on September 18, 2024

@palisadoes For the mobile part the UI should be tweaked to accomodate the pagination.

from talawa-api.

meetulr avatar meetulr commented on September 18, 2024

Both the admin and mobile will need to be updated simultaneously according to the changes in the API. We'll need contributors for both. Would depend on how the query is modified in the backend. A proper approach should be established first.

from talawa-api.

palisadoes avatar palisadoes commented on September 18, 2024
  1. That's what I figured. We don't want to break the apps.
  2. Will we need to modify the newsfeed and its infinite scrolling?

from talawa-api.

Azad99-9 avatar Azad99-9 commented on September 18, 2024

When the next set of events are to be fetched(connection is to be traversed further) a new network request would be made with a non-null value for the $cursor variable. This time there's no need to fetch the organization fields like address, phoneNumber, name etc., because they were already fetched by the very first network request. This would look like this:-

Yes we already use a similar approach in organizationsConnection query.

from talawa-api.

palisadoes avatar palisadoes commented on September 18, 2024

@Azad99-9 Are you working on this?

from talawa-api.

Azad99-9 avatar Azad99-9 commented on September 18, 2024

@palisadoes I am not working on this. But this needs to be addressed. To resolve client side performance issues.

from talawa-api.

xoldd avatar xoldd commented on September 18, 2024

Should I do it?

from talawa-api.

Maniii97 avatar Maniii97 commented on September 18, 2024

hey, is this issue up? can i be assigned to do this?.

from talawa-api.

Cioppolo14 avatar Cioppolo14 commented on September 18, 2024

@Maniii97 Thank you for your interest. Please keep looking, as I'm sure we have open issues and we'd love your help. If any issue is already assigned, please don't ask to be assigned. We want everyone to get a chance.

from talawa-api.

github-actions avatar github-actions commented on September 18, 2024

This issue did not get any activity in the past 10 days and will be closed in 180 days if no update occurs. Please check if the develop branch has fixed it and report again or close the issue.

from talawa-api.

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.