GraphQL is a query language for APIs. It is often used as an alternative to RESTful APIs, but can also be used as an additional "gateway" layer on top of existing RESTful services.

With Prisma, you can build GraphQL servers that connect to a database. Prisma is completely agnostic to the GraphQL tools you use. When building as GraphQL server, you can combine Prisma with tools like Apollo Server, express-graphql, TypeGraphQL, GraphQL.js, or pretty much any tool or library that you're using in your GraphQL server setup.

GraphQL servers under the hood

A GraphQL server consists of two major components:

  • GraphQL schema (type definitions + resolvers)
  • HTTP server

Note that a GraphQL schema can be written code-first or SDL-first. Check out this article to learn more about these two approaches. If you like the SDL-first approach but still want to make your code type-safe, check out GraphQL Code Generator to generate various type definitions based on SDL.

The GraphQL schema and HTTP server are typically handled by separate libraries. Here is an overview of current GraphQL server tools and their purpose:

Library (npm package)PurposeCompatible with PrismaPrisma integration
graphqlGraphQL schema (code-first)YesNo
graphql-toolsGraphQL schema (SDL-first)YesNo
type-graphqlGraphQL schema (code-first)Yestypegraphql-prisma
@nexus/schemaGraphQL schema (code-first)Yesnexus-plugin-prisma
apollo-serverHTTP serverYesn/a
express-graphqlHTTP serverYesn/a
fastify-gqlHTTP serverYesn/a
graphql-yogaHTTP serverYesn/a

In addition to these standalone and single-purpose libraries, there are several projects building integrated application frameworks:

FrameworkStackBuilt byPrismaDescription
Redwood.jsFullstackTom Preston-WernerBuilt on top of PrismaBringing full-stack to the JAMstack.
BlitzFullstackBrandon BayerBuilt on top of PrismaRails-like framework for monolithic, full-stack React apps — built on Next.js.

Note: If you notice any GraphQL libraries/frameworks missing from the list, please let us know.

Prisma & GraphQL examples

Below you find several ready-to-run examples that showcase how to use Prisma with different combinations of the tools mentioned in the table above.

TypeScript

DemoHTTP ServerGraphQL schemaDescription
GraphQL APIgraphql-yoga@nexus/schemaGraphQL server based on graphql-yoga
GraphQL API (Apollo Server)apollo-server@nexus/schemaGraphQL server based on apollo-server
GraphQL API (SDL-first)graphql-yogagraphql-toolsGraphQL server based on the SDL-first approach of graphql-tools (Apollo)
GraphQL API (TypeGraphQL)graphql-yogatype-graphqlGraphQL server based on the code-first approach of TypeGraphQL
GraphQL API (Auth)graphql-yoga@nexus/schemaGraphQL server with email-password authentication & permissions
Fullstack appapollo-server@nexus/schemaFullstack app with Next.js (React), Apollo Client, Apollo Server and Nexus Schema
GraphQL subscriptionsapollo-server@nexus/schemaGraphQL server implementing realtime GraphQL subscriptions

JavaScript (Node.js)

DemoHTTP ServerGraphQL schemaDescription
GraphQL APIgraphql-yoga@nexus/schemaGraphQL server based on graphql-yoga
GraphQL API (Apollo Server)apollo-server@nexus/schemaGraphQL server based on apollo-server
GraphQL API (SDL-first)graphql-yogagraphql-toolsGraphQL server based on the SDL-first approach of graphql-tools (Apollo)
GraphQL API (Auth)graphql-yoga@nexus/schemaGraphQL server with email-password authentication & permissions

FAQ

What is Prisma's role in a GraphQL server?

No matter which of the above GraphQL tools/libraries you use, Prisma is used inside your GraphQL resolvers to connect to your database. It has the same role that any other ORM or SQL query builder would have inside your resolvers.

In the resolver of a GraphQL query, Prisma typically reads data from the database to return it in the GraphQL response. In the resolver of a GraphQL mutation, Prisma typically also writes data to the database (e.g. creating new or updating existing records).

Other GraphQL Resources

Prisma curates GraphQL Weekly, a newsletter highlighting resources and updates from the GraphQL community. Subscribe to keep up-to-date with GraphQL articles, videos, tutorials, libraries, and more.

Edit this page on GitHub