typeorm-cursor-pagination: unknown type in cursor: [object]

Hi there! This library is awesome. It’s working great for most use cases I’ve encountered. However, I’m getting a weird error from the internals of the library occasionally when querying against test fixtures that were inserted into my local database by other tests prior to my test running. The column on which I’m trying to paginate has the PG type timestamp.

The entity is defined as follows:

    @Column({
        type: 'timestamp',
        nullable: true,
    })
    videoDisplayTime!: Date | null;

Here’s the error coming out of the test run, with internals snipped out.

    Error: unknown type in cursor: [object]Mon Nov 23 2020 18:23:15 GMT+0000 (Coordinated Universal Time),at Object.encodeByType ([snip]/node_modules/typeorm-cursor-pagination/src/utils.ts:23:13),at payload.paginationKeys.map ([snip]/node_modules/typeorm-cursor-pagination/src/Paginator.ts:178:21),at Array.map (<anonymous>),at Paginator.encode ([snip]/node_modules/typeorm-cursor-pagination/src/Paginator.ts:176:41),at Paginator.<anonymous> ([snip]/node_modules/typeorm-cursor-pagination/src/Paginator.ts:92:35),at Generator.next (<anonymous>),at fulfilled ([snip]/node_modules/typeorm-cursor-pagination/lib/Paginator.js:5:58),at process._tickCallback (internal/process/next_tick.js:68:7)
    --
    body: {
      "status": 500,
      "errorName": "Error",
      "message": "unknown type in cursor: [object]Mon Nov 23 2020 18:23:15 GMT+0000 (Coordinated Universal Time)",
      "stack": [
        "at Object.encodeByType ([snip]/node_modules/typeorm-cursor-pagination/src/utils.ts:23:13)",
        "at payload.paginationKeys.map ([snip]/node_modules/typeorm-cursor-pagination/src/Paginator.ts:178:21)",
        "at Array.map (<anonymous>)",
        "at Paginator.encode ([snip]/node_modules/typeorm-cursor-pagination/src/Paginator.ts:176:41)",
        "at Paginator.<anonymous> ([snip]/node_modules/typeorm-cursor-pagination/src/Paginator.ts:92:35)",
        "at Generator.next (<anonymous>)",
        "at fulfilled ([snip]/node_modules/typeorm-cursor-pagination/lib/Paginator.js:5:58)",
        "at process._tickCallback (internal/process/next_tick.js:68:7)"
      ]
    }

Any ideas on what I we may be doing wrong would be greatly appreciated!

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 20 (7 by maintainers)

Most upvoted comments

I set up a contrived example. I believe the issue is with the naming strategy. This pagination library doesn’t seem to use the naming strategy set in the TypeOrm configuration to derive proper column names for its pagination keys.

https://github.com/mividtim/pagination-test

Repro steps:

  • Clone the repo.
  • Run yarn or npm install.
  • Create a local DB and a PG user/password for the sample to own.
  • Copy sample.env to .env.
  • Edit the values in .env to point to your local DB
  • Run yarn start:dev
  • Hit http://localhost:3000 to generate the DB table. The output should be an object with an empty construed array.
  • Run yarn migration:up to populate the construed table with some test data.
  • Refresh http://localhost:3000 to see the new data (7 values in the construed property)
  • Hit http://localhost:3000?limit=3 to run into the error.