SlideShare a Scribd company logo
1 of 31
Download to read offline
▪
▪
▪
▪
▪
▪
▪
type User {
id: Int!
name: String!
friends: [User!]!
}
type Query {
user(id: Int!): User
}
type Mutation {
setUserName(id: Int!, name: String!): User
}
query {
user(id: 1) {
id
name
}
}
{
"data": {
"user": {
"id": 1,
"name": "Luke Skywalker"
}
}
}
const app = express();
app.use( "/graphql", graphqlHTTP({
schema,
rootValue,
graphiql: true
}));
app.listen(
4000,
() => console.log("Listening on port 4000")
);
query {
user(id: 1) {
id
name
friends {
id
name
}
}
}
const rootValue = {
user: ({ id }) => {
const dummyUser = {
id: () => id,
name: "dummy-user",
friends: () => [dummyUser, dummyUser],
};
return dummyUser;
},
};
query {
user(id: 1) {
id
name
friends {
id
name
}
}
}
const rootValue = {
user: ({ id }) => {
const dummyUser = {
id: () => id,
name: "dummy-user",
friends: () => [dummyUser, dummyUser],
};
return dummyUser;
},
};
query {
user(id: 1) {
id
name
friends {
id
name
}
}
}
const rootValue = {
user: ({ id }) => {
const dummyUser = {
id: () => id,
name: "dummy-user",
friends: () => [dummyUser, dummyUser],
};
return dummyUser;
},
};
query {
user(id: 1) {
id
name
friends {
id
name
}
}
}
const rootValue = {
user: ({ id }) => {
const dummyUser = {
id: () => id,
name: "dummy-user",
friends: () => [dummyUser, dummyUser],
};
return dummyUser;
},
};
query {
user(id: 1) {
id
name
friends {
id
name
}
}
}
const rootValue = {
user: ({ id }) => {
const dummyUser = {
id: () => id,
name: "dummy-user",
friends: () => [dummyUser, dummyUser],
};
return dummyUser;
},
};
const rootValue = {
user: ({ id }) => {
const dummyUser = {
id: () => id,
name: "dummy-user",
friends: () => [dummyUser, dummyUser],
};
return dummyUser;
},
};
query {
user(id: 1) {
id
name
friends {
id
name
}
}
}
const rootValue = {
user: ({ id }) => {
const dummyUser = {
id: () => id,
name: "dummy-user",
friends: () => [dummyUser, dummyUser],
};
return dummyUser;
},
};
query {
user(id: 1) {
id
name
friends {
id
name
}
}
}
const rootValue = {
user: ({ id }) => {
const dummyUser = {
id: () => id,
name: "dummy-user",
friends: () => [dummyUser, dummyUser],
};
return dummyUser;
},
};
query {
user(id: 1) {
id
name
friends {
id
name
}
}
}
const rootValue = {
user: ({ id }) => {
const dummyUser = {
id: () => id,
name: "dummy-user",
friends: () => [dummyUser, dummyUser],
};
return dummyUser;
},
};
query {
user(id: 1) {
id
name
friends {
id
name
}
}
}
const rootValue = {
user: ({ id }) => {
const dummyUser = {
id: () => id,
name: "dummy-user",
friends: () => [dummyUser, dummyUser],
};
return dummyUser;
},
};
query {
user(id: 1) {
id
name
friends {
id
name
}
}
}
const rootValue = {
user: ({ id }) => {
const dummyUser = {
id: () => id,
name: "dummy-user",
friends: () => [dummyUser, dummyUser],
};
return dummyUser;
},
};
query {
user(id: 1) {
id
name
friends {
id
name
}
}
}
const rootValue = {
user: async ({ id }) => {
const userRow = await userQueries.getById(id);
return {
id: id,
name: userRow.name,
friends: () => getFriendsOfUser(id),
};
},
};
async function getFriendsOfUser(id) {
const friendIds = await userQueries.getFriendIds(id);
const friendUserRows = await userQueries.getByIds(friendIds);
return friendUserRows.map((friend) => ({
id: friend.id,
name: friend.name,
friends: () => getFriendsOfUser(friend.id),
}));
}
▪
▪
▪
▪
▪
▪ ▪
▪
▪
▪
▪
function getByIds(ids) {
return db.all(
`
SELECT *
FROM user
WHERE id IN (${new Array(ids.length).fill("?").join(", ")})
`,
ids,
);
}
async function preloadUsersById() {
usersById = {};
const userRows = await userQueries.getAll();
userRows.forEach((u) => {
usersById[u.id] = { ...u, friends: [] };
});
const friendPairs = await userQueries.getFriendPairs();
friendPairs.forEach(([a, b]) => {
usersById[a].friends.push(usersById[b]);
usersById[b].friends.push(usersById[a]);
});
return usersById;
}
const dataLoader = new DataLoader(async (userIds) => {
const userRows = await userQueries.getByIds(userIds);
return userRows.map((userRow) => ({
...userRow,
friends: () => this.friendsByUserIdDataLoader.load(userRow.id),
}));
});
// later
dataLoader.loadMany([1, 2, 3])
dataLoader.loadMany([2, 4, 5])
▪ ▪
▪
▪
▪
▪
▪ →
Andreas Roth - GraphQL erfolgreich im Backend einsetzen

More Related Content

What's hot

Logging your node.js application
Logging your node.js applicationLogging your node.js application
Logging your node.js applicationMd. Sohel Rana
 
Kick start with j query
Kick start with j queryKick start with j query
Kick start with j queryMd. Ziaul Haq
 
Paris js extensions
Paris js extensionsParis js extensions
Paris js extensionserwanl
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutesSimon Willison
 
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móvilesDesarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móvilesLuis Curo Salvatierra
 
Steam Learn: Javascript and OOP
Steam Learn: Javascript and OOPSteam Learn: Javascript and OOP
Steam Learn: Javascript and OOPinovia
 
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
jQuery UI Widgets, Drag and Drop, Drupal 7 JavascriptjQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
jQuery UI Widgets, Drag and Drop, Drupal 7 JavascriptDarren Mothersele
 
Testing Web Applications with GEB
Testing Web Applications with GEBTesting Web Applications with GEB
Testing Web Applications with GEBHoward Lewis Ship
 
Php 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the GoodPhp 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the GoodJeremy Kendall
 
Native json in the Cache' ObjectScript 2016.*
Native json in the Cache' ObjectScript 2016.*Native json in the Cache' ObjectScript 2016.*
Native json in the Cache' ObjectScript 2016.*Timur Safin
 

What's hot (15)

Logging your node.js application
Logging your node.js applicationLogging your node.js application
Logging your node.js application
 
jQuery
jQueryjQuery
jQuery
 
Kick start with j query
Kick start with j queryKick start with j query
Kick start with j query
 
Php
PhpPhp
Php
 
Paris js extensions
Paris js extensionsParis js extensions
Paris js extensions
 
jQuery Basic API
jQuery Basic APIjQuery Basic API
jQuery Basic API
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
 
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móvilesDesarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móviles
 
Django - sql alchemy - jquery
Django - sql alchemy - jqueryDjango - sql alchemy - jquery
Django - sql alchemy - jquery
 
Steam Learn: Javascript and OOP
Steam Learn: Javascript and OOPSteam Learn: Javascript and OOP
Steam Learn: Javascript and OOP
 
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
jQuery UI Widgets, Drag and Drop, Drupal 7 JavascriptjQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
 
Testing Web Applications with GEB
Testing Web Applications with GEBTesting Web Applications with GEB
Testing Web Applications with GEB
 
BVJS
BVJSBVJS
BVJS
 
Php 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the GoodPhp 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the Good
 
Native json in the Cache' ObjectScript 2016.*
Native json in the Cache' ObjectScript 2016.*Native json in the Cache' ObjectScript 2016.*
Native json in the Cache' ObjectScript 2016.*
 

Similar to Andreas Roth - GraphQL erfolgreich im Backend einsetzen

Redis Developer Day TLV - Redis Stack & RedisInsight
Redis Developer Day TLV - Redis Stack & RedisInsightRedis Developer Day TLV - Redis Stack & RedisInsight
Redis Developer Day TLV - Redis Stack & RedisInsightGuy Korland
 
[2019-07] GraphQL in depth (serverside)
[2019-07] GraphQL in depth (serverside)[2019-07] GraphQL in depth (serverside)
[2019-07] GraphQL in depth (serverside)croquiscom
 
Next-generation API Development with GraphQL and Prisma
Next-generation API Development with GraphQL and PrismaNext-generation API Development with GraphQL and Prisma
Next-generation API Development with GraphQL and PrismaNikolas Burk
 
async/await in Swift
async/await in Swiftasync/await in Swift
async/await in SwiftPeter Friese
 
Developing Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginnersDeveloping Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginnersSaeid Zebardast
 
TDD in the wild
TDD in the wildTDD in the wild
TDD in the wildBrainhub
 
Typescript - why it's awesome
Typescript - why it's awesomeTypescript - why it's awesome
Typescript - why it's awesomePiotr Miazga
 
Real Time App with Node.js
Real Time App with Node.jsReal Time App with Node.js
Real Time App with Node.jsJxck Jxck
 
Server Side Swift with Swag
Server Side Swift with SwagServer Side Swift with Swag
Server Side Swift with SwagJens Ravens
 
Intro programacion funcional
Intro programacion funcionalIntro programacion funcional
Intro programacion funcionalNSCoder Mexico
 
Test du futur avec Spock
Test du futur avec SpockTest du futur avec Spock
Test du futur avec SpockCARA_Lyon
 
Opa presentation at GamesJs
Opa presentation at GamesJsOpa presentation at GamesJs
Opa presentation at GamesJsHenri Binsztok
 
Coming to Terms with GraphQL
Coming to Terms with GraphQLComing to Terms with GraphQL
Coming to Terms with GraphQLBruce Williams
 
Map/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDBMap/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDBUwe Printz
 
The State of Lithium
The State of LithiumThe State of Lithium
The State of LithiumNate Abele
 

Similar to Andreas Roth - GraphQL erfolgreich im Backend einsetzen (20)

Redis Developer Day TLV - Redis Stack & RedisInsight
Redis Developer Day TLV - Redis Stack & RedisInsightRedis Developer Day TLV - Redis Stack & RedisInsight
Redis Developer Day TLV - Redis Stack & RedisInsight
 
[2019-07] GraphQL in depth (serverside)
[2019-07] GraphQL in depth (serverside)[2019-07] GraphQL in depth (serverside)
[2019-07] GraphQL in depth (serverside)
 
Swift & JSON
Swift & JSONSwift & JSON
Swift & JSON
 
Next-generation API Development with GraphQL and Prisma
Next-generation API Development with GraphQL and PrismaNext-generation API Development with GraphQL and Prisma
Next-generation API Development with GraphQL and Prisma
 
async/await in Swift
async/await in Swiftasync/await in Swift
async/await in Swift
 
Developing Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginnersDeveloping Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginners
 
Dev Day Andreas Roth.pdf
Dev Day Andreas Roth.pdfDev Day Andreas Roth.pdf
Dev Day Andreas Roth.pdf
 
TDD in the wild
TDD in the wildTDD in the wild
TDD in the wild
 
Typescript - why it's awesome
Typescript - why it's awesomeTypescript - why it's awesome
Typescript - why it's awesome
 
Real Time App with Node.js
Real Time App with Node.jsReal Time App with Node.js
Real Time App with Node.js
 
SQLAlchemy Seminar
SQLAlchemy SeminarSQLAlchemy Seminar
SQLAlchemy Seminar
 
Server Side Swift with Swag
Server Side Swift with SwagServer Side Swift with Swag
Server Side Swift with Swag
 
Intro programacion funcional
Intro programacion funcionalIntro programacion funcional
Intro programacion funcional
 
Test du futur avec Spock
Test du futur avec SpockTest du futur avec Spock
Test du futur avec Spock
 
Android and REST
Android and RESTAndroid and REST
Android and REST
 
Opa presentation at GamesJs
Opa presentation at GamesJsOpa presentation at GamesJs
Opa presentation at GamesJs
 
Coming to Terms with GraphQL
Coming to Terms with GraphQLComing to Terms with GraphQL
Coming to Terms with GraphQL
 
Drupal Mobile
Drupal MobileDrupal Mobile
Drupal Mobile
 
Map/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDBMap/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDB
 
The State of Lithium
The State of LithiumThe State of Lithium
The State of Lithium
 

More from DevDay Dresden

The Architecture of Uncertainty - Kevlin Henney
The Architecture of Uncertainty - Kevlin HenneyThe Architecture of Uncertainty - Kevlin Henney
The Architecture of Uncertainty - Kevlin HenneyDevDay Dresden
 
Dev Day 2021 - Stephan Pirnbaum - Anwendungsmodernisierung
Dev Day 2021 - Stephan Pirnbaum - AnwendungsmodernisierungDev Day 2021 - Stephan Pirnbaum - Anwendungsmodernisierung
Dev Day 2021 - Stephan Pirnbaum - AnwendungsmodernisierungDevDay Dresden
 
Tobias Nebel - Herausforderungen und Changen in Full-Stack-IoT-Projekten
Tobias Nebel - Herausforderungen und Changen in Full-Stack-IoT-ProjektenTobias Nebel - Herausforderungen und Changen in Full-Stack-IoT-Projekten
Tobias Nebel - Herausforderungen und Changen in Full-Stack-IoT-ProjektenDevDay Dresden
 
Alexander Reelsen - Seccomp for Developers
Alexander Reelsen - Seccomp for DevelopersAlexander Reelsen - Seccomp for Developers
Alexander Reelsen - Seccomp for DevelopersDevDay Dresden
 
DevDay 19 Accessibility: Praxistipps für Entwickler
DevDay 19 Accessibility: Praxistipps für EntwicklerDevDay 19 Accessibility: Praxistipps für Entwickler
DevDay 19 Accessibility: Praxistipps für EntwicklerDevDay Dresden
 
Dev Day 2019: Phillip Krenn – Aggregierte Logging Patterns
Dev Day 2019: Phillip Krenn – Aggregierte Logging PatternsDev Day 2019: Phillip Krenn – Aggregierte Logging Patterns
Dev Day 2019: Phillip Krenn – Aggregierte Logging PatternsDevDay Dresden
 
Dev Day 2019: Mirko Seifert – Next Level Integration Testing mit Docker und T...
Dev Day 2019: Mirko Seifert – Next Level Integration Testing mit Docker und T...Dev Day 2019: Mirko Seifert – Next Level Integration Testing mit Docker und T...
Dev Day 2019: Mirko Seifert – Next Level Integration Testing mit Docker und T...DevDay Dresden
 
Dev Day 2019: Nathan Mattes – Kommunikation ist wichtig, scheiße wichtig und ...
Dev Day 2019: Nathan Mattes – Kommunikation ist wichtig, scheiße wichtig und ...Dev Day 2019: Nathan Mattes – Kommunikation ist wichtig, scheiße wichtig und ...
Dev Day 2019: Nathan Mattes – Kommunikation ist wichtig, scheiße wichtig und ...DevDay Dresden
 
Dev Day 2019: Stephan Birnbaum – Die Glaskugel hat ausgedient, wir machen Sof...
Dev Day 2019: Stephan Birnbaum – Die Glaskugel hat ausgedient, wir machen Sof...Dev Day 2019: Stephan Birnbaum – Die Glaskugel hat ausgedient, wir machen Sof...
Dev Day 2019: Stephan Birnbaum – Die Glaskugel hat ausgedient, wir machen Sof...DevDay Dresden
 
Dev Day 2019: Markus Winand – Die Mutter aller Abfragesprachen: SQL im 21. Ja...
Dev Day 2019: Markus Winand – Die Mutter aller Abfragesprachen: SQL im 21. Ja...Dev Day 2019: Markus Winand – Die Mutter aller Abfragesprachen: SQL im 21. Ja...
Dev Day 2019: Markus Winand – Die Mutter aller Abfragesprachen: SQL im 21. Ja...DevDay Dresden
 
Dev Day 2019: Kay Grebenstein – Wie wir müssen das noch testen? - design for ...
Dev Day 2019: Kay Grebenstein – Wie wir müssen das noch testen? - design for ...Dev Day 2019: Kay Grebenstein – Wie wir müssen das noch testen? - design for ...
Dev Day 2019: Kay Grebenstein – Wie wir müssen das noch testen? - design for ...DevDay Dresden
 
Dev Day 2019: Kathrin Friedrich/Michael Kunze – Design better together - Styl...
Dev Day 2019: Kathrin Friedrich/Michael Kunze – Design better together - Styl...Dev Day 2019: Kathrin Friedrich/Michael Kunze – Design better together - Styl...
Dev Day 2019: Kathrin Friedrich/Michael Kunze – Design better together - Styl...DevDay Dresden
 
Dev Day 2019: Benjamin Wolf – "Some fixes" - Commit Message 101
Dev Day 2019: Benjamin Wolf – "Some fixes" - Commit Message 101Dev Day 2019: Benjamin Wolf – "Some fixes" - Commit Message 101
Dev Day 2019: Benjamin Wolf – "Some fixes" - Commit Message 101DevDay Dresden
 
Dev Day 2019: Lucas Fiedler – DevOps-Dashboard: Transparenz für DevOps-Teams
Dev Day 2019: Lucas Fiedler – DevOps-Dashboard: Transparenz für DevOps-TeamsDev Day 2019: Lucas Fiedler – DevOps-Dashboard: Transparenz für DevOps-Teams
Dev Day 2019: Lucas Fiedler – DevOps-Dashboard: Transparenz für DevOps-TeamsDevDay Dresden
 
Dev Day 2019: Ulrich Deiters – Offene Daten und IT-Lösungen für den Radverkehr
Dev Day 2019: Ulrich Deiters – Offene Daten und IT-Lösungen für den RadverkehrDev Day 2019: Ulrich Deiters – Offene Daten und IT-Lösungen für den Radverkehr
Dev Day 2019: Ulrich Deiters – Offene Daten und IT-Lösungen für den RadverkehrDevDay Dresden
 
Dev Day 2019: Alexander Lichter - JAMstack - Eine neuartige Webanwendungs-Arc...
Dev Day 2019: Alexander Lichter - JAMstack - Eine neuartige Webanwendungs-Arc...Dev Day 2019: Alexander Lichter - JAMstack - Eine neuartige Webanwendungs-Arc...
Dev Day 2019: Alexander Lichter - JAMstack - Eine neuartige Webanwendungs-Arc...DevDay Dresden
 
Dev Day 2019: Martin Schurz - Manual Work Is A Bug!
Dev Day 2019: Martin Schurz - Manual Work Is A Bug!Dev Day 2019: Martin Schurz - Manual Work Is A Bug!
Dev Day 2019: Martin Schurz - Manual Work Is A Bug!DevDay Dresden
 
Dev Day 2019: Stefan Schleyer: How to build an cloud-based IoT application“
Dev Day 2019: Stefan Schleyer: How to build an cloud-based IoT application“Dev Day 2019: Stefan Schleyer: How to build an cloud-based IoT application“
Dev Day 2019: Stefan Schleyer: How to build an cloud-based IoT application“DevDay Dresden
 
Dev Day 2019: Mirko Zeibig – "Hallo " <> "Elixir"
Dev Day 2019: Mirko Zeibig – "Hallo " <> "Elixir"Dev Day 2019: Mirko Zeibig – "Hallo " <> "Elixir"
Dev Day 2019: Mirko Zeibig – "Hallo " <> "Elixir"DevDay Dresden
 
Dev Day 2019: Mike Sperber – Software Design für die Seele
Dev Day 2019: Mike Sperber – Software Design für die SeeleDev Day 2019: Mike Sperber – Software Design für die Seele
Dev Day 2019: Mike Sperber – Software Design für die SeeleDevDay Dresden
 

More from DevDay Dresden (20)

The Architecture of Uncertainty - Kevlin Henney
The Architecture of Uncertainty - Kevlin HenneyThe Architecture of Uncertainty - Kevlin Henney
The Architecture of Uncertainty - Kevlin Henney
 
Dev Day 2021 - Stephan Pirnbaum - Anwendungsmodernisierung
Dev Day 2021 - Stephan Pirnbaum - AnwendungsmodernisierungDev Day 2021 - Stephan Pirnbaum - Anwendungsmodernisierung
Dev Day 2021 - Stephan Pirnbaum - Anwendungsmodernisierung
 
Tobias Nebel - Herausforderungen und Changen in Full-Stack-IoT-Projekten
Tobias Nebel - Herausforderungen und Changen in Full-Stack-IoT-ProjektenTobias Nebel - Herausforderungen und Changen in Full-Stack-IoT-Projekten
Tobias Nebel - Herausforderungen und Changen in Full-Stack-IoT-Projekten
 
Alexander Reelsen - Seccomp for Developers
Alexander Reelsen - Seccomp for DevelopersAlexander Reelsen - Seccomp for Developers
Alexander Reelsen - Seccomp for Developers
 
DevDay 19 Accessibility: Praxistipps für Entwickler
DevDay 19 Accessibility: Praxistipps für EntwicklerDevDay 19 Accessibility: Praxistipps für Entwickler
DevDay 19 Accessibility: Praxistipps für Entwickler
 
Dev Day 2019: Phillip Krenn – Aggregierte Logging Patterns
Dev Day 2019: Phillip Krenn – Aggregierte Logging PatternsDev Day 2019: Phillip Krenn – Aggregierte Logging Patterns
Dev Day 2019: Phillip Krenn – Aggregierte Logging Patterns
 
Dev Day 2019: Mirko Seifert – Next Level Integration Testing mit Docker und T...
Dev Day 2019: Mirko Seifert – Next Level Integration Testing mit Docker und T...Dev Day 2019: Mirko Seifert – Next Level Integration Testing mit Docker und T...
Dev Day 2019: Mirko Seifert – Next Level Integration Testing mit Docker und T...
 
Dev Day 2019: Nathan Mattes – Kommunikation ist wichtig, scheiße wichtig und ...
Dev Day 2019: Nathan Mattes – Kommunikation ist wichtig, scheiße wichtig und ...Dev Day 2019: Nathan Mattes – Kommunikation ist wichtig, scheiße wichtig und ...
Dev Day 2019: Nathan Mattes – Kommunikation ist wichtig, scheiße wichtig und ...
 
Dev Day 2019: Stephan Birnbaum – Die Glaskugel hat ausgedient, wir machen Sof...
Dev Day 2019: Stephan Birnbaum – Die Glaskugel hat ausgedient, wir machen Sof...Dev Day 2019: Stephan Birnbaum – Die Glaskugel hat ausgedient, wir machen Sof...
Dev Day 2019: Stephan Birnbaum – Die Glaskugel hat ausgedient, wir machen Sof...
 
Dev Day 2019: Markus Winand – Die Mutter aller Abfragesprachen: SQL im 21. Ja...
Dev Day 2019: Markus Winand – Die Mutter aller Abfragesprachen: SQL im 21. Ja...Dev Day 2019: Markus Winand – Die Mutter aller Abfragesprachen: SQL im 21. Ja...
Dev Day 2019: Markus Winand – Die Mutter aller Abfragesprachen: SQL im 21. Ja...
 
Dev Day 2019: Kay Grebenstein – Wie wir müssen das noch testen? - design for ...
Dev Day 2019: Kay Grebenstein – Wie wir müssen das noch testen? - design for ...Dev Day 2019: Kay Grebenstein – Wie wir müssen das noch testen? - design for ...
Dev Day 2019: Kay Grebenstein – Wie wir müssen das noch testen? - design for ...
 
Dev Day 2019: Kathrin Friedrich/Michael Kunze – Design better together - Styl...
Dev Day 2019: Kathrin Friedrich/Michael Kunze – Design better together - Styl...Dev Day 2019: Kathrin Friedrich/Michael Kunze – Design better together - Styl...
Dev Day 2019: Kathrin Friedrich/Michael Kunze – Design better together - Styl...
 
Dev Day 2019: Benjamin Wolf – "Some fixes" - Commit Message 101
Dev Day 2019: Benjamin Wolf – "Some fixes" - Commit Message 101Dev Day 2019: Benjamin Wolf – "Some fixes" - Commit Message 101
Dev Day 2019: Benjamin Wolf – "Some fixes" - Commit Message 101
 
Dev Day 2019: Lucas Fiedler – DevOps-Dashboard: Transparenz für DevOps-Teams
Dev Day 2019: Lucas Fiedler – DevOps-Dashboard: Transparenz für DevOps-TeamsDev Day 2019: Lucas Fiedler – DevOps-Dashboard: Transparenz für DevOps-Teams
Dev Day 2019: Lucas Fiedler – DevOps-Dashboard: Transparenz für DevOps-Teams
 
Dev Day 2019: Ulrich Deiters – Offene Daten und IT-Lösungen für den Radverkehr
Dev Day 2019: Ulrich Deiters – Offene Daten und IT-Lösungen für den RadverkehrDev Day 2019: Ulrich Deiters – Offene Daten und IT-Lösungen für den Radverkehr
Dev Day 2019: Ulrich Deiters – Offene Daten und IT-Lösungen für den Radverkehr
 
Dev Day 2019: Alexander Lichter - JAMstack - Eine neuartige Webanwendungs-Arc...
Dev Day 2019: Alexander Lichter - JAMstack - Eine neuartige Webanwendungs-Arc...Dev Day 2019: Alexander Lichter - JAMstack - Eine neuartige Webanwendungs-Arc...
Dev Day 2019: Alexander Lichter - JAMstack - Eine neuartige Webanwendungs-Arc...
 
Dev Day 2019: Martin Schurz - Manual Work Is A Bug!
Dev Day 2019: Martin Schurz - Manual Work Is A Bug!Dev Day 2019: Martin Schurz - Manual Work Is A Bug!
Dev Day 2019: Martin Schurz - Manual Work Is A Bug!
 
Dev Day 2019: Stefan Schleyer: How to build an cloud-based IoT application“
Dev Day 2019: Stefan Schleyer: How to build an cloud-based IoT application“Dev Day 2019: Stefan Schleyer: How to build an cloud-based IoT application“
Dev Day 2019: Stefan Schleyer: How to build an cloud-based IoT application“
 
Dev Day 2019: Mirko Zeibig – "Hallo " <> "Elixir"
Dev Day 2019: Mirko Zeibig – "Hallo " <> "Elixir"Dev Day 2019: Mirko Zeibig – "Hallo " <> "Elixir"
Dev Day 2019: Mirko Zeibig – "Hallo " <> "Elixir"
 
Dev Day 2019: Mike Sperber – Software Design für die Seele
Dev Day 2019: Mike Sperber – Software Design für die SeeleDev Day 2019: Mike Sperber – Software Design für die Seele
Dev Day 2019: Mike Sperber – Software Design für die Seele
 

Recently uploaded

A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your Queries
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your QueriesExploring ChatGPT Prompt Hacks To Maximally Optimise Your Queries
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your QueriesSanjay Willie
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your Queries
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your QueriesExploring ChatGPT Prompt Hacks To Maximally Optimise Your Queries
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your Queries
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

Andreas Roth - GraphQL erfolgreich im Backend einsetzen

  • 1.
  • 3.
  • 4. type User { id: Int! name: String! friends: [User!]! } type Query { user(id: Int!): User } type Mutation { setUserName(id: Int!, name: String!): User }
  • 5. query { user(id: 1) { id name } } { "data": { "user": { "id": 1, "name": "Luke Skywalker" } } }
  • 6.
  • 7. const app = express(); app.use( "/graphql", graphqlHTTP({ schema, rootValue, graphiql: true })); app.listen( 4000, () => console.log("Listening on port 4000") );
  • 8. query { user(id: 1) { id name friends { id name } } } const rootValue = { user: ({ id }) => { const dummyUser = { id: () => id, name: "dummy-user", friends: () => [dummyUser, dummyUser], }; return dummyUser; }, };
  • 9. query { user(id: 1) { id name friends { id name } } } const rootValue = { user: ({ id }) => { const dummyUser = { id: () => id, name: "dummy-user", friends: () => [dummyUser, dummyUser], }; return dummyUser; }, };
  • 10. query { user(id: 1) { id name friends { id name } } } const rootValue = { user: ({ id }) => { const dummyUser = { id: () => id, name: "dummy-user", friends: () => [dummyUser, dummyUser], }; return dummyUser; }, };
  • 11. query { user(id: 1) { id name friends { id name } } } const rootValue = { user: ({ id }) => { const dummyUser = { id: () => id, name: "dummy-user", friends: () => [dummyUser, dummyUser], }; return dummyUser; }, };
  • 12. query { user(id: 1) { id name friends { id name } } } const rootValue = { user: ({ id }) => { const dummyUser = { id: () => id, name: "dummy-user", friends: () => [dummyUser, dummyUser], }; return dummyUser; }, };
  • 13. const rootValue = { user: ({ id }) => { const dummyUser = { id: () => id, name: "dummy-user", friends: () => [dummyUser, dummyUser], }; return dummyUser; }, }; query { user(id: 1) { id name friends { id name } } }
  • 14. const rootValue = { user: ({ id }) => { const dummyUser = { id: () => id, name: "dummy-user", friends: () => [dummyUser, dummyUser], }; return dummyUser; }, }; query { user(id: 1) { id name friends { id name } } }
  • 15. const rootValue = { user: ({ id }) => { const dummyUser = { id: () => id, name: "dummy-user", friends: () => [dummyUser, dummyUser], }; return dummyUser; }, }; query { user(id: 1) { id name friends { id name } } }
  • 16. const rootValue = { user: ({ id }) => { const dummyUser = { id: () => id, name: "dummy-user", friends: () => [dummyUser, dummyUser], }; return dummyUser; }, }; query { user(id: 1) { id name friends { id name } } }
  • 17. const rootValue = { user: ({ id }) => { const dummyUser = { id: () => id, name: "dummy-user", friends: () => [dummyUser, dummyUser], }; return dummyUser; }, }; query { user(id: 1) { id name friends { id name } } }
  • 18. const rootValue = { user: ({ id }) => { const dummyUser = { id: () => id, name: "dummy-user", friends: () => [dummyUser, dummyUser], }; return dummyUser; }, }; query { user(id: 1) { id name friends { id name } } }
  • 19. const rootValue = { user: async ({ id }) => { const userRow = await userQueries.getById(id); return { id: id, name: userRow.name, friends: () => getFriendsOfUser(id), }; }, };
  • 20. async function getFriendsOfUser(id) { const friendIds = await userQueries.getFriendIds(id); const friendUserRows = await userQueries.getByIds(friendIds); return friendUserRows.map((friend) => ({ id: friend.id, name: friend.name, friends: () => getFriendsOfUser(friend.id), })); }
  • 22.
  • 24.
  • 25. function getByIds(ids) { return db.all( ` SELECT * FROM user WHERE id IN (${new Array(ids.length).fill("?").join(", ")}) `, ids, ); }
  • 26.
  • 27. async function preloadUsersById() { usersById = {}; const userRows = await userQueries.getAll(); userRows.forEach((u) => { usersById[u.id] = { ...u, friends: [] }; }); const friendPairs = await userQueries.getFriendPairs(); friendPairs.forEach(([a, b]) => { usersById[a].friends.push(usersById[b]); usersById[b].friends.push(usersById[a]); }); return usersById; }
  • 28.
  • 29. const dataLoader = new DataLoader(async (userIds) => { const userRows = await userQueries.getByIds(userIds); return userRows.map((userRow) => ({ ...userRow, friends: () => this.friendsByUserIdDataLoader.load(userRow.id), })); }); // later dataLoader.loadMany([1, 2, 3]) dataLoader.loadMany([2, 4, 5])