Custom database query/type in pothos-prisma-graphql backend?

259 Views Asked by At

I am using the stack prisma -> pothos -> graphql on the backend. This is nice because it makes everything typesafe etc.

I have a table, 'projects', which I want to paginate but I don't know an effective way to do this in Pothos-Prisma.

I suppose, my question is two part:

  • how do you create 'view-like' virtual types in pothos despite its type-enforcing?
  • if this isn't the correct way to go about paginating 'projects', what is?

I found this post here (https://github.com/hayes/pothos/discussions/729) which suggested I use builder.objectType("NewTypeName", ...) to create a custom type. This custom type would include conveniences such as page details. However, when I try to do the same thing, I get:

Argument of type 'string' is not assignable to parameter of type 'ObjectParam<ExtendDefaultTypes<{ Context: GraphQLContext; PrismaTypes: PrismaTypes; }>>'

as a type error. To fix it, I have to change it to builder.objectType<any, any>(...). I don't actually know if the above 'fix' -- hack -- will actually compile because I have already wasted too much time trying hacky things to get this to work. If this is the correct way to do this, however, it would be good to know.

I understand that pothos is trying to be type safe, but I often want to create custom types, as one might do with SQL views that do not exist in the prisma schema. Is there a good way to do this?

(Additionally, I found this Implement Offset-based pagination using pothos-graphql post which simply linked to the other post I listed in this question.)

0

There are 0 best solutions below