Add interface to implementations of paginator
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 3.5k
- Forks
- 468
- Avg merge
- 3h 9m
- Merged PRs (30d)
- 2
Description
What problem does this feature proposal attempt to solve?
The @paginate directive has a standard pattern which would sometimes benefit from an "interface" but this is not provided natively by Lighthouse. An interface would permit use of GraphQL features like fragments.
Which possible solutions should be considered?
the @paginate directive ought to provide an interface based on the type of paginator implemented.
interface SimplePaginator {
paginatorInfo: SimplePaginatorInfo!
}
interface Paginator {
paginatorInfo: PaginatorInfo!
}
The generated paginator type for a hypothetical "users" query would look something like this:
type UserSimplePaginator implements SimplePaginator {
paginatorInfo: SimplePaginatorInfo!
data: [User!]!
}
An example fragment might look like this, note the use of a client-side generated field just to highlight some of the utility in doing this:
const PaginatorFragment = gql`
fragment standardPaginator on SimplePaginator {
paginatorInfo {
hasMorePages
lastPage @client
}
}
`;
const usersList = gql`
query usersList(
$page: Int
$first: Int!
) {
users(
page: $page
first: $first
)
data {
id
name
email
}
...standardPaginator
}
${PaginatorFragment}
`;
So imagine a standard infinite scroll UI used for multiple data models for which we want the paginator response data to be defined at a single point. An interface is necessary to implement this way.
I tried looking in to the code implementation for paginators but it's not clear to me how or where to modify the implementation to add this interface proposal. I'd like to offer to prepare a PR but I think I'd be lost.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the @paginate directive and the generated paginator types, since the issue does not identify specific files or tests. Compare the simple and standard paginator types with the proposed GraphQL interfaces; done means generated paginator types implement the appropriate interface and client fragments can target it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, laravel, php
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100