0

I have a GraphQL server using Node, Knew and Objection.

I have the following in my model:

  totalCount = async () => {
    const totalCount = await Request
      .query()
      .count();
    console.log(totalCount);
    return totalCount;
  }

The above is supposed to return an Int but is currently erroring with: "Int cannot represent non 32-bit signed integer value: [object Object]",

The console.log:

[ Request { totalCount: [Function], count: 14 } ]

The number 14 in the console log is correct. How can I get the func above to return an Int with the count?

halfer
  • 19,824
  • 17
  • 99
  • 186
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012

1 Answers1

0

Presumably, the totalCount field is defined as an integer in your schema. As your log indicates, your call is returning an object. Your resolver for an integer field must return an integer; if it returns an object, GraphQL doesn't know what to do with it and throws that error.

Just extract the count from the query result, like this:

totalCount = () => {
  return Request
    .query()
    .count()
    .then(([res]) => res && res.count)
}
Daniel Rearden
  • 80,636
  • 11
  • 185
  • 183