SlideShare a Scribd company logo
Code-first
GraphQL Server Development
with Prisma
@nikolasburk
Nikolas Burk
Based in Berlin
Developer Relations at @prisma
@nikolasburk@nikolasburk
Introduction: What are we talking about?
SDL-first & code-first GraphQL schema construction
Code-first GraphQL server development with Prisma
Agenda
1
2
3
What are we
talking about?
1
Anatomy of a GraphQL server
Server (e.g. HTTP)
Process HTTP requests, extract
operation, return HTTP response ...
GraphQL schema
Operations + Data structures
(types, inputs, enums, ...)
GraphQL schemas come
● Type definitions
(root) types, inputs, enums, …
● Resolver functions
CONSISTS OF
graphql-jsfrom
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
user: {
type: UserType,
resolve: () => ({
id: 1,
name: "Alice"
})
}
A GraphQL schema is at the
core of every GraphQL server
graphql-js
const UserType = new GraphQLObjectType({
name: 'User',
fields: {
id: { type: GraphQLID },
name: { type: GraphQLString }
}
})
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
user: {
type: UserType,
resolve: () => ({ id: 1, name: "Alice" })
}
}
})
})
express-graphql
const app = express()
app.use(‘/graphql’, graphqlHTTP({ schema }))
app.listen(4000, () => {
console.log(“Server ready at http://localhost:4000”)
})
graphql-yoga
const server = new GraphQLServer({ schema })
server.start(() => {
console.log(“Server ready at http://localhost:4000”)
})
apollo-server
const server = new ApolloServer({ schema })
server.listen({ port: 4000 }, () =>
console.log(“Server ready at http://localhost:4000”)
)
GRAPHQL SCHEMA GRAPHQL SERVERS (HTTP)
This talk is about the
different ways to create a
GraphQLSchema
SDL-first & code-first
GraphQL schema construction
2
Schema Definition Language
type User {
id: ID!
name: String
}
SDL
a GraphQLSchema
How do I create
?
🤔
Schema-first & code-first
CLARIFYING TERMINOLOGY
Schema-first
GraphQL schema is defined as a string
and resolvers are mapped to it
Code-first (resolver-first)
GraphQL schema is defined and
implemented programmatically
Schema-first
GraphQL schema is defined as a string
and resolvers are mapped to it
Code-first (resolver-first)
GraphQL schema is defined and
implemented programmatically
CLARIFYING TERMINOLOGY
SDL
Schema-driven
Schema design is a priority in the development process
SDL-first & code-first
Schema-driven development can
be applied to both approaches:
SDL-first and Code-first
Illustrating code-first & SDL-first
graphql-js
const User = new GraphQLObjectType({
name: 'User',
fields: {
id: { type: GraphQLID },
name: { type: GraphQLString }
}
})
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
users: {
type: new GraphQLList(User),
resolve: () => ([{
id: 1,
name: "Alice"
}])
}
}
})
})
const typeDefs = `
type User {
id: ID!
name: String
}
type Query {
users: [User]
}
`
const resolvers = {
Query: {
users: () => ([{ id: 1, name: “Alice” }])
}
}
const schema = makeSchema({
typeDefs,
resolvers
})
graphql-tools
const User = objectType({
name: "User",
definition(t) {
t.id("id")
t.string("name")
},
})
const Query = queryType({
definition(t) {
t.list.field("users", {
type: "User",
resolve: () => ([{ id: 1, name: 'Alice' }])
})
},
})
const schema = makeSchema({
types: [Query, User]
})
nexus
SDL-first has great benefits ...
✓ Schema definition as API documentation
✓ Schema definition as cross-team communication tool
✓ Schema definition enables quick mocking of an API
✓ GraphQL schema-design is not an afterthought
… but also some issues
How many errors can you find
in this GraphQL schema
implementation?
AUDIENCE PARTICIPATION
SOLUTION 💡
https://pris.ly/b/graphqlgen
SDL-first problems & tools to fix them
Problem
✘ Inconsistencies
✘ Modularization
✘ Importing
✘ Composition
✘ Tooling / IDE support
Solution
✓ Static analysis, code generation
(e.g. graphql-code-generator, ...)
✓ graphql-modules
✓ graphql-import
✓ Schema stitching/federation, ...
✓ VS Code plugins, graphql-tag, ...
Workarounds, workarounds, workarounds, ...
We already have a
solution! 💡
The only tool you need is your
programming language
Problem
✘ Inconsistencies
✘ Modularization
✘ Importing
✘ Composition
✘ Tooling / IDE support
Solution (SDL-first)
✓ Static analysis, code generation
(e.g. graphql-code-generator, ...)
✓ graphql-modules
✓ graphql-import
✓ Schema stitching/federation, ...
✓ VS Code plugins, graphql-tag, ...
✓ Programming language
Solution (Code-first)
✓ Programming language
✓ Programming language
✓ Programming language
✓ Programming language
SDL doesn’t go away when
using a code-first approach!
(It just becomes a generated artifact instead of
being manually maintained)
Reviewing SDL-first benefits
Benefit
Schema definition as API documentation
SDL-first Code-first
Schema definition as cross-team communication tool
Schema definition enables quick mocking of an API
GraphQL schema-design is not an afterthought ��
Code-first is idiotiomatic to
programming languages
Scala
(Sangria)
Python
(graphene)
Ruby
(graphql-ruby)
3
Code-first in practice
with Prisma
GraphQLSchema
to connect it to a database
The different ways to create
THIS TALK IS ABOUT
a and how
Code-first  GraphQL Server Development with Prisma
Code-first  GraphQL Server Development with Prisma
Prisma is not opinionated on
code-first & SDL-first! 🤷
Nexus + Prisma = ❤
✓ Saves tons of boilerplate (CRUD, type definitions, ...)
✓ Flexible API design
✓ End-to-end type safety
🍿 Demo
Data Access
(ORM)
GraphQL
schema
GraphQL
server (HTTP)
Database
The Demo Stack
WHAT WE’LL BUILD
Code-first  GraphQL Server Development with Prisma
prisma.io/blog
READ MORE ON
Thank you 🙏
@nikolasburk@nikolasburk

More Related Content

PDF
GraphQL & Prisma from Scratch
PDF
Next-generation API Development with GraphQL and Prisma
PDF
GraphQL Schema Stitching with Prisma & Contentful
PDF
Building GraphQL Servers with Node.JS & Prisma
PDF
Managing GraphQL servers with AWS Fargate & Prisma Cloud
PDF
GraphQL Meetup Bangkok 3.0
PDF
Performant APIs with GraphQL and PHP (Dutch PHP 2019)
PDF
Integrating React.js Into a PHP Application: Dutch PHP 2019
GraphQL & Prisma from Scratch
Next-generation API Development with GraphQL and Prisma
GraphQL Schema Stitching with Prisma & Contentful
Building GraphQL Servers with Node.JS & Prisma
Managing GraphQL servers with AWS Fargate & Prisma Cloud
GraphQL Meetup Bangkok 3.0
Performant APIs with GraphQL and PHP (Dutch PHP 2019)
Integrating React.js Into a PHP Application: Dutch PHP 2019

What's hot (20)

PDF
Getting Started with GraphQL && PHP
PDF
PDF
Graph Database Prototyping made easy with Graphgen
PPTX
Building a GraphQL API in PHP
PDF
Webinar about Spring Data Neo4j 4
PDF
DIとトレイとによるAndroid開発の効率化
PDF
All About GRAND Stack: GraphQL, React, Apollo, and Neo4j (Mark Needham) - Gre...
PDF
Hadoop User Group Ireland (HUG) Ireland - Eddie Baggot Presentation April 2016
PDF
Boost your APIs with GraphQL 1.0
PPTX
GraphQL Misconfiguration
PPTX
Attacking GraphQL
PDF
Neo4j Data Loading with Kettle
PDF
Apollo Server III
PDF
The GraphQL Ecosystem in 2018
PDF
NyaruDBにゃるものを使ってみた話 (+Realm比較)
PDF
Introducing Arc: A Common Intermediate Language for Unified Batch and Stream...
PPT
Theads services
PDF
Boost your API with GraphQL
PDF
The Apollo and GraphQL Stack
PDF
Power of Polyglot Search
Getting Started with GraphQL && PHP
Graph Database Prototyping made easy with Graphgen
Building a GraphQL API in PHP
Webinar about Spring Data Neo4j 4
DIとトレイとによるAndroid開発の効率化
All About GRAND Stack: GraphQL, React, Apollo, and Neo4j (Mark Needham) - Gre...
Hadoop User Group Ireland (HUG) Ireland - Eddie Baggot Presentation April 2016
Boost your APIs with GraphQL 1.0
GraphQL Misconfiguration
Attacking GraphQL
Neo4j Data Loading with Kettle
Apollo Server III
The GraphQL Ecosystem in 2018
NyaruDBにゃるものを使ってみた話 (+Realm比較)
Introducing Arc: A Common Intermediate Language for Unified Batch and Stream...
Theads services
Boost your API with GraphQL
The Apollo and GraphQL Stack
Power of Polyglot Search
Ad

Similar to Code-first GraphQL Server Development with Prisma (20)

PDF
APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...
PDF
Graphql usage
PDF
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
PDF
MongoDB World 2019: Building a GraphQL API with MongoDB, Prisma, & TypeScript
PPTX
GraphQL - The new "Lingua Franca" for API-Development
PDF
GraphQL and its schema as a universal layer for database access
PPTX
GraphQl Introduction
PDF
GraphQL with .NET Core Microservices.pdf
PDF
GraphQL the holy contract between client and server
PDF
Nikita Galkin "Looking for the right tech stack for GraphQL application"
PDF
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
PDF
APIdays Paris 2019 - Turning your Database into a GraphQL API with Prisma & N...
PPTX
GraphQL Introduction with Spring Boot
PDF
Apollo Server
PPTX
Introduction to GraphQL Presentation.pptx
PPTX
Intro to GraphQL for Database Developers
PDF
DEVOXX UK 2018 - GraphQL as an alternative approach to REST
PDF
Simplify Access to Data from Pivotal GemFire Using the GraphQL (G2QL) Extension
PDF
GraphQL for Native Apps
PPTX
Introduction to GraphQL
APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...
Graphql usage
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
MongoDB World 2019: Building a GraphQL API with MongoDB, Prisma, & TypeScript
GraphQL - The new "Lingua Franca" for API-Development
GraphQL and its schema as a universal layer for database access
GraphQl Introduction
GraphQL with .NET Core Microservices.pdf
GraphQL the holy contract between client and server
Nikita Galkin "Looking for the right tech stack for GraphQL application"
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
APIdays Paris 2019 - Turning your Database into a GraphQL API with Prisma & N...
GraphQL Introduction with Spring Boot
Apollo Server
Introduction to GraphQL Presentation.pptx
Intro to GraphQL for Database Developers
DEVOXX UK 2018 - GraphQL as an alternative approach to REST
Simplify Access to Data from Pivotal GemFire Using the GraphQL (G2QL) Extension
GraphQL for Native Apps
Introduction to GraphQL
Ad

More from Nikolas Burk (11)

PDF
React & GraphQL
PDF
Building Serverless GraphQL Backends
PDF
GraphQL Subscriptions
PDF
The Serverless GraphQL Backend Architecture
PDF
State Management & Unidirectional Data Flow
PDF
Diving into GraphQL, React & Apollo
PDF
Authentication, Authorization & Error Handling with GraphQL
PDF
Getting Started with Relay Modern
PDF
Building a Realtime Chat with React Native (Expo) & GraphQL Subscriptions
PDF
Building a Realtime Chat with React & GraphQL Subscriptions
PDF
REST in Peace - Using GraphQL with Apollo on iOS
React & GraphQL
Building Serverless GraphQL Backends
GraphQL Subscriptions
The Serverless GraphQL Backend Architecture
State Management & Unidirectional Data Flow
Diving into GraphQL, React & Apollo
Authentication, Authorization & Error Handling with GraphQL
Getting Started with Relay Modern
Building a Realtime Chat with React Native (Expo) & GraphQL Subscriptions
Building a Realtime Chat with React & GraphQL Subscriptions
REST in Peace - Using GraphQL with Apollo on iOS

Recently uploaded (20)

PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Transform Your Business with a Software ERP System
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Nekopoi APK 2025 free lastest update
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Introduction to Artificial Intelligence
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
System and Network Administraation Chapter 3
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
CHAPTER 2 - PM Management and IT Context
PPTX
L1 - Introduction to python Backend.pptx
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Transform Your Business with a Software ERP System
Upgrade and Innovation Strategies for SAP ERP Customers
2025 Textile ERP Trends: SAP, Odoo & Oracle
Odoo POS Development Services by CandidRoot Solutions
Nekopoi APK 2025 free lastest update
Navsoft: AI-Powered Business Solutions & Custom Software Development
Introduction to Artificial Intelligence
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
System and Network Administraation Chapter 3
How to Choose the Right IT Partner for Your Business in Malaysia
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PTS Company Brochure 2025 (1).pdf.......
Understanding Forklifts - TECH EHS Solution
CHAPTER 2 - PM Management and IT Context
L1 - Introduction to python Backend.pptx
wealthsignaloriginal-com-DS-text-... (1).pdf

Code-first GraphQL Server Development with Prisma

  • 2. Nikolas Burk Based in Berlin Developer Relations at @prisma @nikolasburk@nikolasburk
  • 3. Introduction: What are we talking about? SDL-first & code-first GraphQL schema construction Code-first GraphQL server development with Prisma Agenda 1 2 3
  • 5. Anatomy of a GraphQL server Server (e.g. HTTP) Process HTTP requests, extract operation, return HTTP response ... GraphQL schema Operations + Data structures (types, inputs, enums, ...)
  • 6. GraphQL schemas come ● Type definitions (root) types, inputs, enums, … ● Resolver functions CONSISTS OF graphql-jsfrom const schema = new GraphQLSchema({ query: new GraphQLObjectType({ name: 'Query', fields: { user: { type: UserType, resolve: () => ({ id: 1, name: "Alice" }) }
  • 7. A GraphQL schema is at the core of every GraphQL server graphql-js const UserType = new GraphQLObjectType({ name: 'User', fields: { id: { type: GraphQLID }, name: { type: GraphQLString } } }) const schema = new GraphQLSchema({ query: new GraphQLObjectType({ name: 'Query', fields: { user: { type: UserType, resolve: () => ({ id: 1, name: "Alice" }) } } }) }) express-graphql const app = express() app.use(‘/graphql’, graphqlHTTP({ schema })) app.listen(4000, () => { console.log(“Server ready at http://localhost:4000”) }) graphql-yoga const server = new GraphQLServer({ schema }) server.start(() => { console.log(“Server ready at http://localhost:4000”) }) apollo-server const server = new ApolloServer({ schema }) server.listen({ port: 4000 }, () => console.log(“Server ready at http://localhost:4000”) ) GRAPHQL SCHEMA GRAPHQL SERVERS (HTTP)
  • 8. This talk is about the different ways to create a GraphQLSchema
  • 9. SDL-first & code-first GraphQL schema construction 2
  • 10. Schema Definition Language type User { id: ID! name: String } SDL
  • 11. a GraphQLSchema How do I create ? 🤔
  • 12. Schema-first & code-first CLARIFYING TERMINOLOGY Schema-first GraphQL schema is defined as a string and resolvers are mapped to it Code-first (resolver-first) GraphQL schema is defined and implemented programmatically
  • 13. Schema-first GraphQL schema is defined as a string and resolvers are mapped to it Code-first (resolver-first) GraphQL schema is defined and implemented programmatically CLARIFYING TERMINOLOGY SDL Schema-driven Schema design is a priority in the development process SDL-first & code-first
  • 14. Schema-driven development can be applied to both approaches: SDL-first and Code-first
  • 15. Illustrating code-first & SDL-first graphql-js const User = new GraphQLObjectType({ name: 'User', fields: { id: { type: GraphQLID }, name: { type: GraphQLString } } }) const schema = new GraphQLSchema({ query: new GraphQLObjectType({ name: 'Query', fields: { users: { type: new GraphQLList(User), resolve: () => ([{ id: 1, name: "Alice" }]) } } }) }) const typeDefs = ` type User { id: ID! name: String } type Query { users: [User] } ` const resolvers = { Query: { users: () => ([{ id: 1, name: “Alice” }]) } } const schema = makeSchema({ typeDefs, resolvers }) graphql-tools const User = objectType({ name: "User", definition(t) { t.id("id") t.string("name") }, }) const Query = queryType({ definition(t) { t.list.field("users", { type: "User", resolve: () => ([{ id: 1, name: 'Alice' }]) }) }, }) const schema = makeSchema({ types: [Query, User] }) nexus
  • 16. SDL-first has great benefits ... ✓ Schema definition as API documentation ✓ Schema definition as cross-team communication tool ✓ Schema definition enables quick mocking of an API ✓ GraphQL schema-design is not an afterthought
  • 17. … but also some issues How many errors can you find in this GraphQL schema implementation? AUDIENCE PARTICIPATION SOLUTION 💡 https://pris.ly/b/graphqlgen
  • 18. SDL-first problems & tools to fix them Problem ✘ Inconsistencies ✘ Modularization ✘ Importing ✘ Composition ✘ Tooling / IDE support Solution ✓ Static analysis, code generation (e.g. graphql-code-generator, ...) ✓ graphql-modules ✓ graphql-import ✓ Schema stitching/federation, ... ✓ VS Code plugins, graphql-tag, ...
  • 20. We already have a solution! 💡
  • 21. The only tool you need is your programming language Problem ✘ Inconsistencies ✘ Modularization ✘ Importing ✘ Composition ✘ Tooling / IDE support Solution (SDL-first) ✓ Static analysis, code generation (e.g. graphql-code-generator, ...) ✓ graphql-modules ✓ graphql-import ✓ Schema stitching/federation, ... ✓ VS Code plugins, graphql-tag, ... ✓ Programming language Solution (Code-first) ✓ Programming language ✓ Programming language ✓ Programming language ✓ Programming language
  • 22. SDL doesn’t go away when using a code-first approach! (It just becomes a generated artifact instead of being manually maintained)
  • 23. Reviewing SDL-first benefits Benefit Schema definition as API documentation SDL-first Code-first Schema definition as cross-team communication tool Schema definition enables quick mocking of an API GraphQL schema-design is not an afterthought ��
  • 24. Code-first is idiotiomatic to programming languages Scala (Sangria) Python (graphene) Ruby (graphql-ruby)
  • 26. GraphQLSchema to connect it to a database The different ways to create THIS TALK IS ABOUT a and how
  • 29. Prisma is not opinionated on code-first & SDL-first! 🤷
  • 30. Nexus + Prisma = ❤ ✓ Saves tons of boilerplate (CRUD, type definitions, ...) ✓ Flexible API design ✓ End-to-end type safety