Hi! I'm building a project with next.js/prisma/apollo/graphql/typescript stack. I'm relatively new at this stuff, but I'm determined to learn all these technologies.
I keep seeing examples of people using nexus along with this stack, but I don't entirely understand the value it adds. On one hand, I don't need yet another unfamiliar tech to deal with, on another, if it makes things better/easier somehow, I'd do it.
Could someone ELI5 this for me? Should I be learning it and using it in my project?
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
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
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.
For whatever, reason, I don't have permission to do a link post so I'll just post the link here. If an admin sees this, can you please give me access? Thanks.
https://www.youtube.com/watch?v=ReVzCfpvmsI&list=PLucG_ap4Oxzi3EWR9HVuuOP2wQQAflzhl
We are trying to have more of a discussion around topics and want to raise the quality of posts. Therefore link posts are disabled. Why not tell us more about the linked video. Are you the author of the tutorial?
Finally someone for promoting and explaining Prisma Nexus, thanks for your awesome work!
Let's go round two of weekly discussions. I want to hear your opinions on how you write your GraphQL API.
Graphql SDL
Website • Docs • Github
type-graphql
Website • Docs • Github
TypeGraphQL makes developing a GraphQL API an enjoyable process, i.e. by defining the schema using only classes and a bit of decorator magic.
GraphQL Nexus
Website • Docs • Github
Declarative, code-first and strongly typed GraphQL schema construction for TypeScript & JavaScript
Others:
decapi: decapi is set of decorators for creating GraphQL APIs quickly and in type-safe way. Write your types and GQL schema at once killing two birds with one stone.
Next 🚀 Weekly Discussion will be on Apollo and Relay!
I'm currently using type-graphql and there's 3 things I really like about it:
Works well with Typescript
You can use database models as GraphQL types when paired with TypeORM
You can programmatically generate GraphQL types/resolvers
I've tried GraphQL Nexus and I think it might have more potential. The type inference is better, #2 can be achieved with Prisma, and it uses objects/functions which are easier to programmatically create than classes. It does feel a little more verbose to write, but not by much.
I am using nexus and nexus-prisma with a new GraphQL+Prisma API (first time user) and honestly it feels like cheating, because it takes so much work off of you and just works.
Hi! I'm building a project with next.js/prisma/apollo/graphql/typescript stack. I'm relatively new at this stuff, but I'm determined to learn all these technologies.
I keep seeing examples of people using nexus along with this stack, but I don't entirely understand the value it adds. On one hand, I don't need yet another unfamiliar tech to deal with, on another, if it makes things better/easier somehow, I'd do it.
Could someone ELI5 this for me? Should I be learning it and using it in my project?
Hey guys!
I recently started using GraphQL with TypeORM and Type-GraphQL and absolutely loved it!
Now I stumbled upon NestJS and thought it looked interesting aswell.
What tech-stack would you recommend for NodeJS projects with GraphQL in 2021?
Has anyone a good way to use directives with nexus?
I'm a little new to nexus and I'm a bit confused about what objectType() is meant for. My assumption was that it's simply meant for defining a scheme type but I've seen a lot of examples where a resolver is included in the object type. For example:
const User = objectType({
name: 'User',
definition(t) {
t.int('id', { description: 'Id of the user' })
t.string('fullName', { description: 'Full name of the user' })
t.field('status', { type: StatusEnum })
t.list.field('posts', {
type: Post, // or "Post"
resolve(root, args, ctx) {
return ctx.getUser(root.id).posts()
},
})
},
})Why would we include a resolver here? Shouldn't we do that in a separate queryType()? Any help would be appreciated.
I'm not talking Apollo vs Yoga. There's a handful of higher level frameworks out there, and I'd like to see them all compared. For instance: Vesper, TypeGraphql, Loopback, Prisma, and Nestjs all seem to be duking it out.
I'm not sure exactly what the value propositions are for these different options - or if they're even comparable.
Prismsa Nexus looks promising
hey, buddy just want to clarify that a framework is not as same as an ORM, an ORM is an interface to execute functions over a database. ORMs are very complex just have a look at Prisma, it is written in Scala and maintains very high efficiency. Whereas frameworks go there are written in typescript or any other language which you want to develop in. Frameworks make developing backends or frontends easier at the cost of efficiency.
As of choosing the right framework goes, it depends upon the approach you make for developing your API. If you want a Schema-first approach then Graphql-yoga and vesper are the options. And for a Code-first approach, Typegraphql is amazing.
All frameworks mostly have the same stuff running in the background, like express and apollo-server-express. It not about choosing X over Y but know how X and Y works and what will work the best for the given job.
I personally, love using GraphQL-Yoga with Prisma and Type-GraphQL with Postgres (typeORM).
I just recently started using Nexus and Prisma. Loving it so far, but have had a tough time figuring out cursor pagination. Does anyone have any examples/tutorials they're willing to share? The only tutorial I've really been able to find is this: https://www.youtube.com/watch?v=Pr2nee9aBKw