DEV Community

Cover image for GraphQL: Schema first or Code first
Sajjad Shirazy
Sajjad Shirazy

Posted on

GraphQL: Schema first or Code first

Schema first is more meaningful because you describe business logic in GraphQl (which is human readable and could be the shared document between developers and Scrum product owner) and then resolve queries and mutations in typescript.
But Implementing in code first is faster for developers. you define resolvers and Apollo generates the schema based on them.

Prisma is a type-safe GraphQL based alternative for mongoose or any other js ORM which I think is awesome progress. It works just with a GraphQl data model file. prisma-bindings helps to connect NestJS to Prisma in a schema first approach:

https://www.prisma.io/features/bindings

NestJS tutorial for prisma-binding:

https://docs.nestjs.com/recipes/prisma

but if you want to connect to Prisma using The code first approach, you can use:

https://www.prisma.io/docs/prisma-client/

Still, there is something about Prisma, The current version will deprecate soon, and the next version Prisma2 is totally different, in a nutshell:

  • Prisma 1: A stand-alone server: Type-Safe ORM (prisma-bindings or prisma-client)+ GraphQL API + Admin panel

  • Prisma 2: A npm package: Type-Safe ORM (only prisma-client) + Admin panel + Migration tool

In Prisma 2 there is nothing related to GraphQL and they suggest the code first approach using:

https://github.com/prisma-labs/nexus-prisma

Top comments (0)