SlideShare ist ein Scribd-Unternehmen logo
1 von 31
Downloaden Sie, um offline zu lesen
▪
▪
▪
▪
▪
▪
▪
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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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.*
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
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
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
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
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
(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
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
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
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
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
 

Kürzlich hochgeladen (20)

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
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!
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
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
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
(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...
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
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
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
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
 

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])