Having trouble creating a GraphQL query that can collect multiple counts in a React project? Unsure about the data type to use in this scenario?
Here's the code snippet:
import { GraphQLInt, GraphQLNonNull } from 'graphql' import * as moment from 'moment' import orm from '../../orm' import authDecorator from '../helpers/auth-decorator'
interface IQueryMissionCountArgs { authToken: string }
export default authDecorator({ requireAdmin: true, requireAuth: true })({ type: Object(new GraphQLNonNull(GraphQLInt)), async resolve (
args: IQueryMissionCountArgs ) {
const lastWeekAcceptedMissionsCount = await orm.models.Mission.count({
where: {
createdAt: {
$between: [moment().subtract(7, 'days').toDate(), new Date()]
},
status: 'accepted'
}
})
const lastWeekPostedMissionsCount = await orm.models.Mission.count({
where: {
createdAt: {
$between: [moment().subtract(7, 'days').toDate(), new Date()]
}
}
})
return {
lastWeekPostedMissions: lastWeekPostedMissionsCount,
lastWeekAcceptedMissions: lastWeekAcceptedMissionsCount,
} } })
This is causing the following error message:
Int cannot represent non 32-bit signed integer value: [object Object]\n