I just finished the State of Graphql survey and the Schema Builders questions got me thinking if I shouldn't be using Nexus? I'm not a huge fan of the errors or the API to write custom types. I'm also using Prisma, so it feels like I'm typing out my types twice every time I add a query or a mutation.
It's okay, but is there a better option? What's your favorite? Why?
These were the options in the survey:
-
Nexus
-
TypeGraphQL
-
Pothos
-
Strawberry
-
Sangria
-
gqlgen
-
Graphql Zeus
-
Genql
-
Graphql Code Generator
https://medium.com/@pencilflip/graphql-js-vs-typegraphql-vs-graphql-nexus-2a8036deb851
Here are my thoughts on choosing a JavaScript GraphQL implementation. I talk about three popular options - GraphQL.js, TypeGraphQL, and GraphQL Nexus - and why I prefer using GraphQL.js.
» npm install nexus
I've been looking for a backend framework for graphql for a while and I'll list the main ones I've tried with the problems I've faced
Nestjs(Graphql) - Not really well documented, had many troubles setting up different stuff, ex: dataloaders, file upload, imported custom scalars, had to bring in a decorator orm, has some code duplication, current choices are TypeORM (which is slowly dying) and MikroORM (which is not very much used compared to typeorm, but seems fine).
Typegraphql - Better documentations and probably bigger community (graphql-wise), same problem as above with the orms and code duplication, has many built-in features that I don't like/use and is relatively slow (or at least it has been in the past, I think it kind of got better now).
Postgraphile - seems like a great option, is perfectly customizable, amazing performance, makes you design the database in a great way and autogenerates logic for crud operations, It's generally definitely a good choice, problem being the tooling around building custom resolvers/gql and postgres which doesn't help too much with the autocomplete (you CAN do it but requires some workarounds from what I understood).
----
Now, what I was looking for was a typescript-first framework that could auto-generate crud mutations/queries but remaining fully customizable while being type-safe and have the possibility to do custom queries to the db with its db layer with as less boilerplate as possible.
Nexus Graphql - nexus uses (with its main plugin at least) prisma2 for its database access, which I personally love, the api is a joy to work with imo. It does have a crud plugin for easily generating FULLY CUSTOMIZABLE crud operations, by fully customizable I mean that you can easily change the input shape as you want, make computed properties or reutilize the full generate query wrapped by your resolver SUPER EASILY, you can reuse the same crud generator with different aliases and customization ,you can pretty much make the vast majority (if not all) of your api by just reutilizing the crud api making nested relations and connections (relay connections as well) easy even in custom resolvers. The api seems a little strange at first but I've started preferring it over decorators after not much, it removes a lot of code duplication while remaining simple and type-safe without even explicitly declaring types, same goes for context and whatever else.
The only part where there is some code duplication is between defining the schema (in the prisma model file) and defining your graphql api (for example, you want to omit the password field in the api), this remains type-safe and with code completion tho, not really a pain.
There are other useful plugins that are easy and with near 0 boilerplate to use, for example authorizing fields, or adding complexity calculator.
It is backed by prisma, the negative part is that it is still not stable (0.26), so it has some breaking changes often, and documentation is not full yet
TLDR: Overall what I love about it is how easy and super fast to build with no boilerplate everything seems to be, while being fully customizable like any other custom server and type-safe db access. Really, seems like everything I was looking for in the past months.
Really, if you like the prisma2 api definitely try this one out, it'll be a joy https://nexusjs.org/, the api seems strange at first, but I promise you'll prefer it over decorators after realizing how much it simplifies things.
DISCLAIMER: I'm not related to nexus or prisma in any way, just a random guy who is loving the framework and hopes its community will grow