Prisma generate error: Property 'X' does not exist on type 'Y'

29 Views Asked by At

These errors are throw on the following Prisma resolvers when run next build. Type error: Property 'details' does not exist on type '{ id: number; name: string; }' Type error: Property 'values' does not exist on type '{ id: number; item_id: number; desc: string; }'

Item: {
    async details(parent: item, args: {}, context: GraphQLContext) {
        return parent.details.filter(d => d.values.length > 0)
    }
},
Detail: {
    async values(parent: detail, args: {}, context: GraphQLContext) {
        return parent.values
    }
}

Where the details comes as result of this resolver:

Query: {
    async items(parent: unknown, args: { name: string }, context: GraphQLContext) {
        return context.prisma.product.findMany({
            where: { 
                name: args.name
            },
            include: {
                details: {
                    include: {
                        values: true
                    }
                }
            }
        })
    }
}

And this is the schema:

model item {
  id              Int               @id @default(autoincrement())
  name            String
  details         detail[]
}

model detail {
  id            Int             @id @default(autoincrement())
  item_id       Int
  item          item            @relation(fields: [item_id], references: [id])
  desc          String
  values        value[]
}

model value {
  id            Int             @id @default(autoincrement())
  detail_id     Int
  value         Int
  detail        detail          @relation(fields: [detail_id], references: [id])
}

The error appears when I try to build the project. It seems that the related objects are not available in generated types. But when I run the project in dev mode (next command) it runs successfully and the properties (details in item and values in detail) are actually available where I expect them.

What I did wrong and how I should access the related data?

0

There are 0 best solutions below