MichalLytek / MichalLytek/typegraphql-prisma
`_count` returning null from custom resolvers
- Dominant language
- TypeScript
- Stars
- 918
- Forks
- 130
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the Bug**
When accessed through custom resolvers, the _count field is always null.
**To Reproduce**
Considering the following schema(I'm using mongo):
```
model List {
id String @id @default(auto()) @map("_id") @db.ObjectId
items ListItem[]
}
model ListItem {
id String @id @default(auto()) @map("_id") @db.ObjectId
list List @relation(fields: [listId], references: [id])
listId String @db.ObjectId
}
```
And this sample custom resolver:
```ts
import { List } from "@generated/type-graphql";
import { Ctx, Query, Resolver } from "type-graphql";
import { Context } from "..";
@Resolver()
export class MyListResolver {
@Query(() => List)
async mylist(@Ctx() { prisma }: Context): Promise {
return await prisma.list.findFirstOrThrow();
}
}
```
With the following data:

This query:
```graphql
query Mylist {
mylist {
id
_count {
items
}
}
}
```
Returns a null count:
```json
{
"data": {
"mylist": {
"id": "6408705c0cd690ec08e5b690",
"_count": null
}
}
}
```
**Expected Behavior**
The query should return the actual count so:
```json
{
"data": {
"mylist": {
"id": "6408705c0cd690ec08e5b690",
"_count": {
"items": 2
}
}
}
}
```
**Environment (please complete the following information):**
- OS: Manjaro 22.0.4
- Node `lts/gallium`
- `typegraphql-prisma` version 0.24.2 (the issue was also there with 0.21.4)
- Prisma version 4.11 (the issue was also there with 4.3.0)
- TypeScript version 4.5.4
**Additional Context**
I'm using MongoDB with prisma.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.