Open grvhi opened 5 years ago
GraphQL provides pagination support in Relay but does not give an independent component. Pygraphy may take a long time to support Relay, and I also do not want to extend GraphQL. So it is sorry for supporting the pagination query now, you can still make some custom tools to support it.
I'm not sure if this will be useful to the library, but I've created a
paginated_field
decorator for my project to make it easier to create fields which support pagination in a consistent yet DRY manner. Essentially, the decorator wraps anObject
inside a dynamically-generatedObject
class; the originalObject
becomes thedata
field and apage_info
field is added.Before:
After:
Usage:
Note that the method's return annotation is
Tuple[List[MyObjectSchema], str]
: this allows IDEs to correctly type hint and accept the method's return type. Thepaginated_field
decorator (see below) changes the field's return type to reflect the correct GraphQL schema when the schema is generated.So far, this is working well for me (although it is currently un-tested). If @ethe thinks it would be a useful addition to the library, I can update the code below to be more generic and to add support for more fields on
PageInfo
.Suggestions welcome!