Skip to main content
Prisma Documentation Docs

Search documentation

Type to search this documentation.

On this pageOverview

GraphQL (Prisma ORM v6) (/docs/orm/v6/overview/prisma-in-your-stack/graphql)

For the complete Prisma documentation index, see llms.txt. A markdown version of any docs page is available by appending .md to its URL.

This page gives explains how to build GraphQL servers with Prisma ORM. It shows how Prisma ORM fits into the GraphQL ecosystem and provides practical examples.

Location: ORM > v6 > Core Concepts > Prisma in Your Stack > GraphQL

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 ORM, you can build GraphQL servers that connect to a database. Prisma ORM is completely agnostic to the GraphQL tools you use. When building a GraphQL server, you can combine Prisma ORM with tools like Apollo Server, GraphQL Yoga, TypeGraphQL, GraphQL.js, or any other tool or library in your GraphQL server setup.

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) Purpose Compatible with Prisma ORM Prisma integration
graphql GraphQL schema (code-first) Yes No
graphql-tools GraphQL schema (SDL-first) Yes No
type-graphql GraphQL schema (code-first) Yes typegraphql-prisma
nexus GraphQL schema (code-first) Yes nexus-prisma Early Preview
apollo-server HTTP server Yes n/a
express-graphql HTTP server Yes n/a
fastify-gql HTTP server Yes n/a
graphql-yoga HTTP server Yes n/a

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

Framework Stack Built by Prisma ORM Description
Redwood.js Fullstack Tom Preston-Werner Built on top of Prisma ORM Bringing full-stack to the JAMstack.

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

The following table lists several ready-to-run examples that show how to use Prisma ORM with different combinations of the tools mentioned in the table above.

Example HTTP Server GraphQL schema Description
GraphQL API (Pothos) graphql-yoga pothos GraphQL server based on graphql-yoga
GraphQL API (SDL-first) graphql-yoga n/a GraphQL server based on the SDL-first approach
GraphQL API -- NestJs @nestjs/apollo n/a GraphQL server based on NestJS
GraphQL API -- NestJs (SDL-first) @nestjs/apollo n/a GraphQL server based on NestJS
GraphQL API (Nexus) @apollo/server nexus GraphQL server based on @apollo/server
GraphQL API (TypeGraphQL) apollo-server type-graphql GraphQL server based on the code-first approach of TypeGraphQL
GraphQL API (Auth) apollo-server nexus GraphQL server with email-password authentication & permissions
Fullstack app graphql-yoga pothos Fullstack app with Next.js (React), Apollo Client, GraphQL Yoga and Pothos
GraphQL subscriptions apollo-server nexus GraphQL server implementing realtime GraphQL subscriptions
GraphQL API -- Hapi apollo-server-hapi nexus GraphQL server based on Hapi
GraphQL API -- Hapi (SDL-first) apollo-server-hapi graphql-tools GraphQL server based on Hapi
GraphQL API -- Fastify fastify & mercurius n/a GraphQL server based on Fastify and Mercurius
GraphQL API -- Fastify (SDL-first) fastify Nexus GraphQL server based on Fastify and Mercurius

What is Prisma ORM's role in a GraphQL server?

Section titled “What is Prisma ORM's role in a GraphQL server?”

No matter which of the above GraphQL tools/libraries you use, Prisma ORM 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 ORM typically reads data from the database to return it in the GraphQL response. In the resolver of a GraphQL mutation, Prisma ORM typically also writes data to the database (e.g. creating new or updating existing records).

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.

  • Fullstack: This page gives explains how to build fullstack applications with Prisma. It shows how Prisma fits in with fullstack frameworks and provides practical examples
  • Is Prisma ORM an ORM?: Learn about how Prisma ORM implements the Data Mapper ORM pattern and how it achieves the same goal as traditional ORMs without requiring you to map classes to tables as traditional ORMs do.
  • REST: This page gives an overview of the most important things when building REST APIs with Prisma. It shows practical examples and the supported libraries.
Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu