Comments (15)
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:-
- https://www.apollographql.com/docs/react/pagination/overview
- https://www.apollographql.com/docs/react/pagination/core-api
- https://www.apollographql.com/docs/react/pagination/cursor-based#relay-style-cursor-pagination
- https://commerce.nearform.com/open-source/urql/docs/basics/ui-patterns/#infinite-scrolling
- https://commerce.nearform.com/open-source/urql/docs/graphcache/local-resolvers/#pagination
from talawa-api.
@aashimawadhwa @rishav-jha-mech @DMills27 PTAL and comment
from talawa-api.
@xoldd This was discussed frequently in the past, however related to news feeds. PTAL too
from talawa-api.
@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.
@palisadoes For the mobile part the UI should be tweaked to accomodate the pagination.
from talawa-api.
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.
- That's what I figured. We don't want to break the apps.
- Will we need to modify the newsfeed and its infinite scrolling?
from talawa-api.
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.
Related Issues (20)
- Bug: Unable to Delete Fundraising Campaigns as Superadmin or Admin HOT 1
- Tests: src/setup/MongoDB.ts HOT 1
- Improve Setup: Better prompts for loading data HOT 2
- API Setup should prompt for the TCP listening port HOT 1
- Query returns null for the image field of the likedBy object of the post. HOT 4
- Fix `ExperimentalWarning` on starting API HOT 1
- Clarify the installation process using Docker HOT 5
- Setup script doesn't handle Docker intuitively HOT 8
- Migration to fastify and graphql-yoga HOT 1
- API fails if the `SERVER_PORT` variable is not in the `.env` file HOT 12
- Setup doesn't detect a pre-existing `SERVER_PORT` value in the `.env` file HOT 5
- Error invoking getFundraisingById Resolver HOT 1
- Error populating pledges & user details in getFundraisingCampaignById Resolver HOT 3
- Add Search/Sort & Refac for Fund, Campaigns & Pledge resolvers HOT 7
- YAML config for CodeRabbit AI
- Superadmin Access Issue in Organizations with User-Posted Media HOT 12
- Feature Request: Query for AgendaItemCategories by Organization
- Bug Report: Agenda Item & Section Mutation and Query not working
- Upgrade package mongoose from 8.3.2 to 8.4.4 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from talawa-api.