nuwave / nuwave/lighthouse

Add interface to implementations of paginator

Open
#2,150 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.