Is there any way to use the generated prisma types...
# orm-help
r
Is there any way to use the generated prisma types (housed under
@prisma/client
) as rootTypings for nexus@next? Right now, Nexus doesn't handle interfaces and subtypes without having an explicit rootType present.
n
Maybe @weakky or @jasonkuhrt can help out here?
w
The rootTypings should be automatically set for types that matches the name of your prisma model. If you need some custom types derived from the client types, for now you can import/re-export them in your project. They'll become available in the rootTyping property of output type builders such s objectType/interfaceType etc
👍 1
What is it you're trying to achieve?
r
I'm not changing any types, I'm just trying to use the Prisma generated clients but they are not added.
w
Do you have the nexus-plugin-prisma enabled?
r
I do yup
w
What do you mean by using the types exactly? Do you just want to set the root typings of your output types or use them in elsewhere (eg: function params)?
r
well I have a prisma generated type that in my api layer is split up in an interface with the same name and 3 subtypes. These subtypes do not get access to the root type the same way the interface type does. So I wanted to explicitly add it as roottype but there are no types that I can use.
w
I see. Just give me 2mn!
So, while it’s not ideal yet, it’s how you should do that right now:
Copy code
// types.ts
import * as Prisma from '@prisma/client'

export type YourType = Prisma.YourType

//schema.ts
import { schema } from 'nexus'

schema.objectType({
  name: 'something',
  rootTyping: 'YourType'
})
Note that your type export can be anywhere in your app, not just in a
types.ts
We should make the client generated types available in the backing types by default. Meanwhile, re-exporting the types is your best shot
r
That would be great! And yeah, I tried solving it like that atm.
w
There’s already an issue about that btw. You can track it here https://github.com/graphql-nexus/nexus/issues/462
In the meantime, does the workaround work for you?
r
yup, thanks for the help!
w
Awesome, good luck with project 🙏
r
thanks!
j
Thanks @weakky!
@weakky if you think there is anything here that is recipe worthy go for it (website pr)
w
We could go with a recipe, but I think #462 is what we should do. Maybe a recipe could do the job in the meantime but I’d consider it a workaround
👌🏻 1