lighthouse icon indicating copy to clipboard operation
lighthouse copied to clipboard

Add `Paginator` interface to all paginated fields

Open Vynlar opened this issue 6 years ago • 1 comments

I am willing to work on this feature if someone could provide the necessary context to get me going.

Is your feature request related to a problem? Please describe. I am trying to use fragments to extract information from the paginatorInfo field on multiple paginated fields but, as it stands, Lighthouse generates a unique type for each paginated field:

# Example of such a type
type VideoPaginator {
  paginatorInfo: PaginatorInfo!
  data: [Video!]!
}

Describe the solution you'd like I suggest we add an interface to the generated types called Paginator:

union Paginated = Video | Post | ... #all fields with @paginated would appear here

interface Paginator {
  paginatorInfo: PaginatorInfo!
  data: [Paginated!]!
}

type VideoPaginator implements Paginator {
  paginatorInfo: PaginatorInfo!
  data: [Video!]!
}

Describe alternatives you've considered

I have not considered any other solutions but would love to hear other's ideas.

A brief outline of how to approach this problem in the context of the internal workings of Lighthouse would be helpful as I am not familiar with how things work.

Vynlar avatar Aug 27 '19 14:08 Vynlar

I was actually surprised to learn that GraphQL allows for covariant subtyping when implementing interfaces. Nice!

The schema you propose would be optimal, but it might be hard to construct the union Paginated, since it has to be built dynamically. So for getting your feet wet, you could try and add just the interface Paginator with the field paginatorInfo.

Review the following classes and tests as a starting point:

  • https://github.com/nuwave/lighthouse/blob/master/src/Schema/Directives/PaginateDirective.php
  • https://github.com/nuwave/lighthouse/blob/master/src/Pagination/PaginationManipulator.php
  • https://github.com/nuwave/lighthouse/blob/master/tests/Integration/Schema/Directives/PaginateDirectiveTest.php
  • https://github.com/nuwave/lighthouse/blob/master/tests/Unit/Schema/Directives/PaginateDirectiveTest.php

spawnia avatar Aug 27 '19 20:08 spawnia