Zendro-dev / graphql-server-model-codegen

Command line utility to auto-generate the structure files for a graphql server
MIT License
1 stars 2 forks source link

Make pagination mandatory in readMany resolvers. #145

Closed coeit closed 4 years ago

coeit commented 4 years ago

Problem

With the implementation of #142 we will not do a count before any readMany operation. This means we do not know how many records a query returns before actually running the query. The consequence being, that we cannot reduce the recordsLimit variable inside the graphQl context object by the number of returned records to check if a query is allowed because we don't know the number of returned records.

Solution

WIth the implementation of #142 the idea was to setting the pagination Limit to the global environment Variable globals.LIMIT_RECORDS, to ensure a query still runs, even if no pagination arguments are given.

The problem here is that running multiple queries or field Resolvers (without pagination arguments) automatically exceeds the record limit.

To circumvent this, make pagination a mandatory argument to any readMany resolver. (<modelPlural>, <modelPlural>Connection) and the corresponding field Resolvers.

By doing this we ensure that the user specifies the number of records he wants to be returned and we can adjust the current record limit, stored in the context, accordingly.