How to query a date/time field using pothos with prisma and postgresql

How to query a date/time field using pothos with prisma and postgresql


0

I’ve got my pothos set up using Prisma and postgresql. I’m trying to expose the createdAt and updatedAt fields from prisma in my builder:

Prisma schema:

model Course {
  id          Int      @id @unique @default(autoincrement())
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt
  // removed fields for brevity. 
}

My builder:

builder.prismaObject('Course', {
  fields: (t) => ({
    id: t.exposeID('id'),
    createdAt: t.expose('createdAt', {
      type: 'DateTime' as any,
    })
  })
})

I have also tried this way:

builder.prismaObject('Course', {
      fields: (t) => ({
        id: t.exposeID('id'),
        createdAt: t.expose('createdAt', {
          type: Date, // simply set this as a Date type
        })
      })
    })

These two ways causes the same/similar error:

- error node_modules/@pothos/core/esm/config-store.js (210:18) @ ConfigStore.onTypeConfig
- error Error [PothosSchemaError]: Ref DateTime has not been implemented

I’ve also tried this which works, but obviously hacky (I don’t want to leave it this way):

// @ts-ignore
    createdAt: t.exposeString('createdAt', {
      type: Date
    })


Load 6 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *