Hey all
So by now you have probably read this article, introducing us to Prisma Nexus.
I wanted to take a chance to ask the community about their first reaction?
Does this look like the way to go? Why? Why not?
I’ll start by sharing my own first impressions, keep in mind this is just from reading the article and docs, not from actual use!
Pros of the Code-First approach:
- All the code in one place. You define your object and it’s resolvers in the same place.
- Abillity to dynamically generate your api.
Pros of the SDL-first approach:
- Less clutter in the SDL. Makes your schema easier to reason with.
- Easier to make your api be a simple layer over an existing graphql api.
This last point is very big plus for me. With the SDL first approach, you can easily import your whole schema from a file generated from an existing graphql api, and then overwrite what needs be. I’ve found this to be very fast.
Lets say I want to make a simple change to an existing datamodel: add an email field to an existing User type
type User {
id: ID! @unique
username: String! @unique
email: String @unique # we want to add this field
}
With the current SDL-first aproach this is very simple
- Add the field to the
User
type in the prisma datamodel - Run
prisma deploy
- Run
prisma generate
Done!
Since we import our schema from the generated file, we do not have to worry about adding that field to the relevant types. Granted, it can be more complex (maybe we redefined the User type to hide a password field? In that case we only need to worry about the object type, not the input types).
Now lets take a look at the steps needed to apply the same change in a nexus powered API:
- Add the field to the
User
type in the prisma datamodel - Run
prisma deploy
- Add the field to the
User
type - Add the field to the
UserCreateInput
type - Add the field to the
UserUpdateInput
type - Add the field to the
UserWhereInput
type - Add the field to the
UserWhereUniqueInput
type - Add the field to the
UserOrderByInput
type - I’m forgetting about subscriptions…
As you can see that’s a lot more steps. So many more chances to make mistakes.
This graphic is from the prisma documentation and shows how prisma expands your data model into multiple types.
With Nexus, it seems like I would need to redefine each and everyone of those types. So I’m not managing two different but related versions of my schema: the database layer (prisma) and the business layer (nexus). The fact those two are in completely different formats makes things harder to understand and compare.
Conclusion
I’ve become a big fan of the “trim the bad parts” approach the SDL-first approach has allowed me. I’m pretty sure that approach is not feasible with Nexus, but I know the documentation is probably incomplete, so I’m wondering if I’m missing something?
What about you? What do you think?