Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add interface to implementations of paginator #2150

Open
GregPeden opened this issue May 25, 2022 · 1 comment
Open

Add interface to implementations of paginator #2150

GregPeden opened this issue May 25, 2022 · 1 comment
Labels
enhancement A feature or improvement

Comments

@GregPeden
Copy link
Contributor

GregPeden commented May 25, 2022

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.

@GregPeden GregPeden changed the title Add interface to implementations of paginator Proposed feature: Add interface to implementations of paginator May 25, 2022
@spawnia spawnia added the enhancement A feature or improvement label May 25, 2022
@spawnia
Copy link
Collaborator

spawnia commented May 25, 2022

@spawnia spawnia changed the title Proposed feature: Add interface to implementations of paginator Add interface to implementations of paginator Jun 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A feature or improvement
Projects
None yet
Development

No branches or pull requests

2 participants