slingshotlabs / nestjs-graphql-cursor-pagination-starter

22 stars 4 forks source link

Upgrading Nest and GraphQL dependencies breaks pagination #1

Open cjmyles opened 2 years ago

cjmyles commented 2 years ago

It appears the code in this repository breaks when upgrading to the latest version of NestJS and GraphQL.

I created a new NestJS project (by cloning https://github.com/nestjs/typescript-starter.git) which uses NestJS v8. I then installed the GraphQL dependencies and copied over most of the code from this repository. However, when I run the code I get the following error:

[Nest] 14858  - 14/01/2022, 12:32:09   ERROR [ExceptionsHandler] args.pagingParams is not a function
TypeError: args.pagingParams is not a function
    at AppResolver.getZips (/Users/craig/dev/serenade/experiments/nestjs-graphql-cursor-pagination-v2/src/app.resolver.ts:26:36)
    at /Users/craig/dev/serenade/experiments/nestjs-graphql-cursor-pagination-v2/node_modules/@nestjs/core/helpers/external-context-creator.js:70:33
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at target (/Users/craig/dev/serenade/experiments/nestjs-graphql-cursor-pagination-v2/node_modules/@nestjs/core/helpers/external-context-creator.js:77:28)
    at /Users/craig/dev/serenade/experiments/nestjs-graphql-cursor-pagination-v2/node_modules/@nestjs/core/helpers/external-proxy.js:9:24

It looks like NestJS v8 or the latest GraphQL libraries are somehow stripping the getZips args in app.resolver.ts down to a plain javascript object rather than an instance of the ConnectionArgs class.

Please see https://github.com/cjmyles/nestjs-graphql-cursor-pagination-starter to reproduce the error.

jingp-ofload commented 1 year ago

@cjmyles I ended up this with calling the function getPagingParameters explicitly from resolver like

const { limit = 10, offset = 10 } = getPagingParameters(connectArgs);