SlideShare une entreprise Scribd logo
1  sur  23
A GAME OF DATA AND
GRAPHQL
Michael Hunger, Head of Developer Relations, Neo4j (@mesirii)
GraphQL Meetup Berlin, Aug 24 2017
Looking for
GoT Data
AN API OF ICE AND
FIRE
https://anapioficeandfire.com/About
https://github.com/joakimskoog/AnApiOfIceAndFire
An API of
Ice and Fire
• Data sourced fromWiki of Ice And Fire (AWOIAF)
• Well documented .Net powered API
• Data on
– Books (5)
– Characters (2400)
– Houses (444)
• 100 entries per page
An API of
Ice and Fire
– https://www.anapioficeandfire.com/api/characters/1303
GRAPHQL
Quick Graphql Schema
type Seat {
name: String!
houses: [House] @relation(name:"SEAT_OF")
}
type Region {
name: String!
houses: [House] @relation(name:"IN_REGION",
direction:IN)
}
type House {
id: ID!
name: String!
founded: String
titles: [String]
ancestralWeapons: [String]
coatOfArms: String
words: String
seats: [Seat] @relation(name:"SEAT_OF",
direction:IN)
region: Region @relation(name:"IN_REGION")
leader: Person @relation(name:"LED_BY")
founder: Person @relation(name:"FOUNDED_BY")
allies: [House] @relation(name:"ALLIED_WITH",
direction:IN)
follows: House @relation(name:"SWORN_TO")
followers: [House] @relation(name:"SWORN_TO",
direction:IN)
heir: [Person] @relation(name:"HEIR_TO",
direction:IN)
}
type Person {
id: ID!
name: String!
aliases: [String]
books: [Int]
tvSeries: [String]
playedBy: [String]
isFemale: Boolean
culture: String
died: String
titles: [String]
founded: [House] @relation(name:"FOUNDED_BY",
direction:IN)
leads: [House] @relation(name:"LED_BY",
direction:IN)
inherits: [House] @relation(name:"HEIR_TO")
spouse: [Person] @relation(name:"SPOUSE",
direction:BOTH)
parents: [Person] @relation(name:"PARENT_OF",
direction:IN)
children: [Person] @relation(name:"PARENT_OF")
houses: [House] @relation(name:"ALLIED_WITH")
}
SPIN UP AN ENDPOINT
$ npm install –g neo4j-graphql-cli
$ neo4j-graphql got-schema.graphql
# configure graphql-cli
$ npm install –g graphql-cli
$ graphql init
# add Auth Headers
Visualize Schema
call graphql.schema();
Visualize Schema
$ graphql voyager
LOADING THE
DATA
LOAD VIA
API
• Iterate over batches of pages
• Data cleanup
• Replace URLs with IDs
• Throttle
• INSERT COMPLEX SCRIPT HERE
unwind range(1,43) as page
call apoc.util.sleep(1)
with page, 'characters' as type
call apoc.load.jsonArray('https://www.anapioficeandfire.com/api/'+type+'?pageSize=50&page='+page) yield value
with apoc.convert.toMap(value) as data
MERGE (p:Person {id:split(data.url,"/")[-1]})
SET
p += apoc.map.clean(data, ['allegiances','books','father','spouse','mother'],['',[''],[]]),
p.books = [b in data.books | split(b,'/')[-1]],
p.name = colaesce(p.name,head(p.aliases))
FOREACH (a in data.allegiances | MERGE (h:House {id:split(a,'/')[-1]}) MERGE (p)-[:SWORN_TO]->(h))
FOREACH (f in case coalesce(data.father,"") when "" then [] else [data.father] end | MERGE (o:Person {id:split(f,'/')[-1]})
MERGE (o)-[:PARENT_OF {type:'father'}]->(p))
FOREACH (f in case coalesce(data.mother,"") when "" then [] else [data.mother] end | MERGE (o:Person {id:split(f,'/')[-1]})
MERGE (o)-[:PARENT_OF {type:'mother'}]->(p))
FOREACH (f in case coalesce(data.spouse,"") when "" then [] else [data.spouse] end | MERGE (o:Person {id:split(f,'/')[-1]})
MERGE (o)-[:SPOUSE]-(p))
return p.id, p.name;
BETTER!
FULL
JSON
DATA
• Full JSON data in Github Repository
• Load all characters and houses in one go
• No URL conversion
• But lowercasing keys
• Offline and much faster
call apoc.load.jsonArray('https://raw.githubusercontent.com/joakimskoog/AnApiOfIceAndFire/master/data/houses.json') yield value
with apoc.convert.toMap(value) as data
with apoc.map.clean(data, [],['',[''],[],null]) as data
with apoc.map.fromPairs([k in keys(data) | [toLower(substring(k,0,1))+substring(k,1,length(k)), data[k]]]) as data
MERGE (h:House {id:data.id})
SET
h += apoc.map.clean(data, ['overlord','swornMembers','currentLord','heir','founder','cadetBranches'],['',[''],[],null])
FOREACH (id in data.swornMembers | MERGE (o:Person {id:id}) MERGE (o)-[:ALLIED_WITH]->(h))
FOREACH (s in data.seats | MERGE (seat:Seat {name:s}) MERGE (seat)-[:SEAT_OF]->(h))
FOREACH (id in data.cadetBranches | MERGE (b:House {id:id}) MERGE (b)-[:BRANCH_OF]->(h))
FOREACH (id in case data.overlord when null then [] else [data.overlord] end | MERGE (o:House {id:id}) MERGE (h)-[:SWORN_TO]->(o))
FOREACH (id in case data.currentLord when null then [] else [data.currentLord] end | MERGE (o:Person {id:id}) MERGE (h)-[:LED_BY]->(o))
FOREACH (id in case data.founder when null then [] else [data.founder] end | MERGE (o:Person {id:id}) MERGE (h)-[:FOUNDED_BY]->(o))
FOREACH (id in case data.heir when null then [] else [data.heir] end | MERGE (o:Person {id:id}) MERGE (o)-[:HEIR_TO]->(h))
FOREACH (r in case data.region when null then [] else [data.region] end | MERGE (o:Region {name:r}) MERGE (h)-[:IN_REGION]->(o))
return h.id, h.name;
ITS A GRAPH
ITS A
GRAPH
QuERY Data with Cypher
MISSING DATA !?
MATCH (p:Person)
WHERE size(p.tvSeries) > 1
AND NOT exists((p)-[:PARENT_OF]-())
RETURN p LIMIT 10;
• Walder
• The waif
• High Septon
• MargaeryTyrell
• Tywin Lannister
• Unella
• AemonTargaryen
• AlliserThorne
• Arya Stark
• Asha Greyjoy
QuERY Data
WITH
Graphql
RESOURCES
Code and instructions for
todays presentation
• GitHub
– https://github.com/neo4j-examples/game-of-thrones
• Medium Post
– medium.com/@mesirii/a-game-of-data-and-graphql-97ee2ca297ce
• Graph ofThrones 7 week contest
– https://neo4j.com/blog/graph-of-thrones/
• An API of Ice and Fire
– https://github.com/joakimskoog/AnApiOfIceAndFire
– https://anapioficeandfire.com/About
• GraphQL CLI Load
– https://npmjs.org/package/graphql-cli-load
Neo 4J GraphQL
• http://neo4j.com/developer/graphql
• https://npmjs.org/package/neo4j-graphql-cli
• http://communitygraph.org/graphql
• http://github.com/neo4j-graphql
– graphiql4all
– graphql-cli-load
– neoj4-graphql-cli
– community graph
– ...
More Fun
with Graphs and
Game of Thrones
• Character Interactions
– https://networkofthrones.wordpress.com/
– :play https://guides.neo4j.com/got
• GraphAnalytics of Character Interactions
– http://www.lyonwj.com/2016/06/26/graph-of-thrones-neo4j-
social-network-analysis/
• NLP on the book texts
– https://graphaware.com/neo4j/2017/07/24/reverse-
engineering-book-stories-nlp.html
• The Maths of Game ofThrones
– https://anthonybonato.com/2016/04/13/the-mathematics-of-
game-of-thrones/
• Kaggle GoT Data (Battles)
– https://tbgraph.wordpress.com/?s=Game+of+Thrones
QUESTIONS
@mesirii | neo4j.com/slack

Contenu connexe

Plus de jexp

Looming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdfLooming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdfjexp
 
Easing the daily grind with the awesome JDK command line tools
Easing the daily grind with the awesome JDK command line toolsEasing the daily grind with the awesome JDK command line tools
Easing the daily grind with the awesome JDK command line toolsjexp
 
Looming Marvelous - Virtual Threads in Java
Looming Marvelous - Virtual Threads in JavaLooming Marvelous - Virtual Threads in Java
Looming Marvelous - Virtual Threads in Javajexp
 
GraphConnect 2022 - Top 10 Cypher Tuning Tips & Tricks.pptx
GraphConnect 2022 - Top 10 Cypher Tuning Tips & Tricks.pptxGraphConnect 2022 - Top 10 Cypher Tuning Tips & Tricks.pptx
GraphConnect 2022 - Top 10 Cypher Tuning Tips & Tricks.pptxjexp
 
Neo4j Connector Apache Spark FiNCENFiles
Neo4j Connector Apache Spark FiNCENFilesNeo4j Connector Apache Spark FiNCENFiles
Neo4j Connector Apache Spark FiNCENFilesjexp
 
How Graphs Help Investigative Journalists to Connect the Dots
How Graphs Help Investigative Journalists to Connect the DotsHow Graphs Help Investigative Journalists to Connect the Dots
How Graphs Help Investigative Journalists to Connect the Dotsjexp
 
The Home Office. Does it really work?
The Home Office. Does it really work?The Home Office. Does it really work?
The Home Office. Does it really work?jexp
 
Polyglot Applications with GraalVM
Polyglot Applications with GraalVMPolyglot Applications with GraalVM
Polyglot Applications with GraalVMjexp
 
Neo4j Graph Streaming Services with Apache Kafka
Neo4j Graph Streaming Services with Apache KafkaNeo4j Graph Streaming Services with Apache Kafka
Neo4j Graph Streaming Services with Apache Kafkajexp
 
How Graph Databases efficiently store, manage and query connected data at s...
How Graph Databases efficiently  store, manage and query  connected data at s...How Graph Databases efficiently  store, manage and query  connected data at s...
How Graph Databases efficiently store, manage and query connected data at s...jexp
 
APOC Pearls - Whirlwind Tour Through the Neo4j APOC Procedures Library
APOC Pearls - Whirlwind Tour Through the Neo4j APOC Procedures LibraryAPOC Pearls - Whirlwind Tour Through the Neo4j APOC Procedures Library
APOC Pearls - Whirlwind Tour Through the Neo4j APOC Procedures Libraryjexp
 
Refactoring, 2nd Edition
Refactoring, 2nd EditionRefactoring, 2nd Edition
Refactoring, 2nd Editionjexp
 
New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...
New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...
New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...jexp
 
GraphQL - The new "Lingua Franca" for API-Development
GraphQL - The new "Lingua Franca" for API-DevelopmentGraphQL - The new "Lingua Franca" for API-Development
GraphQL - The new "Lingua Franca" for API-Developmentjexp
 
A whirlwind tour of graph databases
A whirlwind tour of graph databasesA whirlwind tour of graph databases
A whirlwind tour of graph databasesjexp
 
Intro to Graphs and Neo4j
Intro to Graphs and Neo4jIntro to Graphs and Neo4j
Intro to Graphs and Neo4jjexp
 
Class graph neo4j and software metrics
Class graph neo4j and software metricsClass graph neo4j and software metrics
Class graph neo4j and software metricsjexp
 
New Neo4j Auto HA Cluster
New Neo4j Auto HA ClusterNew Neo4j Auto HA Cluster
New Neo4j Auto HA Clusterjexp
 
Spring Data Neo4j Intro SpringOne 2012
Spring Data Neo4j Intro SpringOne 2012Spring Data Neo4j Intro SpringOne 2012
Spring Data Neo4j Intro SpringOne 2012jexp
 
Intro to Cypher
Intro to CypherIntro to Cypher
Intro to Cypherjexp
 

Plus de jexp (20)

Looming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdfLooming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdf
 
Easing the daily grind with the awesome JDK command line tools
Easing the daily grind with the awesome JDK command line toolsEasing the daily grind with the awesome JDK command line tools
Easing the daily grind with the awesome JDK command line tools
 
Looming Marvelous - Virtual Threads in Java
Looming Marvelous - Virtual Threads in JavaLooming Marvelous - Virtual Threads in Java
Looming Marvelous - Virtual Threads in Java
 
GraphConnect 2022 - Top 10 Cypher Tuning Tips & Tricks.pptx
GraphConnect 2022 - Top 10 Cypher Tuning Tips & Tricks.pptxGraphConnect 2022 - Top 10 Cypher Tuning Tips & Tricks.pptx
GraphConnect 2022 - Top 10 Cypher Tuning Tips & Tricks.pptx
 
Neo4j Connector Apache Spark FiNCENFiles
Neo4j Connector Apache Spark FiNCENFilesNeo4j Connector Apache Spark FiNCENFiles
Neo4j Connector Apache Spark FiNCENFiles
 
How Graphs Help Investigative Journalists to Connect the Dots
How Graphs Help Investigative Journalists to Connect the DotsHow Graphs Help Investigative Journalists to Connect the Dots
How Graphs Help Investigative Journalists to Connect the Dots
 
The Home Office. Does it really work?
The Home Office. Does it really work?The Home Office. Does it really work?
The Home Office. Does it really work?
 
Polyglot Applications with GraalVM
Polyglot Applications with GraalVMPolyglot Applications with GraalVM
Polyglot Applications with GraalVM
 
Neo4j Graph Streaming Services with Apache Kafka
Neo4j Graph Streaming Services with Apache KafkaNeo4j Graph Streaming Services with Apache Kafka
Neo4j Graph Streaming Services with Apache Kafka
 
How Graph Databases efficiently store, manage and query connected data at s...
How Graph Databases efficiently  store, manage and query  connected data at s...How Graph Databases efficiently  store, manage and query  connected data at s...
How Graph Databases efficiently store, manage and query connected data at s...
 
APOC Pearls - Whirlwind Tour Through the Neo4j APOC Procedures Library
APOC Pearls - Whirlwind Tour Through the Neo4j APOC Procedures LibraryAPOC Pearls - Whirlwind Tour Through the Neo4j APOC Procedures Library
APOC Pearls - Whirlwind Tour Through the Neo4j APOC Procedures Library
 
Refactoring, 2nd Edition
Refactoring, 2nd EditionRefactoring, 2nd Edition
Refactoring, 2nd Edition
 
New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...
New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...
New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...
 
GraphQL - The new "Lingua Franca" for API-Development
GraphQL - The new "Lingua Franca" for API-DevelopmentGraphQL - The new "Lingua Franca" for API-Development
GraphQL - The new "Lingua Franca" for API-Development
 
A whirlwind tour of graph databases
A whirlwind tour of graph databasesA whirlwind tour of graph databases
A whirlwind tour of graph databases
 
Intro to Graphs and Neo4j
Intro to Graphs and Neo4jIntro to Graphs and Neo4j
Intro to Graphs and Neo4j
 
Class graph neo4j and software metrics
Class graph neo4j and software metricsClass graph neo4j and software metrics
Class graph neo4j and software metrics
 
New Neo4j Auto HA Cluster
New Neo4j Auto HA ClusterNew Neo4j Auto HA Cluster
New Neo4j Auto HA Cluster
 
Spring Data Neo4j Intro SpringOne 2012
Spring Data Neo4j Intro SpringOne 2012Spring Data Neo4j Intro SpringOne 2012
Spring Data Neo4j Intro SpringOne 2012
 
Intro to Cypher
Intro to CypherIntro to Cypher
Intro to Cypher
 

Dernier

A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedDelhi Call girls
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxalwaysnagaraju26
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 

Dernier (20)

A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 

A Game of Data and GraphQL

  • 1. A GAME OF DATA AND GRAPHQL Michael Hunger, Head of Developer Relations, Neo4j (@mesirii) GraphQL Meetup Berlin, Aug 24 2017
  • 3. AN API OF ICE AND FIRE https://anapioficeandfire.com/About https://github.com/joakimskoog/AnApiOfIceAndFire
  • 4. An API of Ice and Fire • Data sourced fromWiki of Ice And Fire (AWOIAF) • Well documented .Net powered API • Data on – Books (5) – Characters (2400) – Houses (444) • 100 entries per page
  • 5. An API of Ice and Fire – https://www.anapioficeandfire.com/api/characters/1303
  • 7. Quick Graphql Schema type Seat { name: String! houses: [House] @relation(name:"SEAT_OF") } type Region { name: String! houses: [House] @relation(name:"IN_REGION", direction:IN) } type House { id: ID! name: String! founded: String titles: [String] ancestralWeapons: [String] coatOfArms: String words: String seats: [Seat] @relation(name:"SEAT_OF", direction:IN) region: Region @relation(name:"IN_REGION") leader: Person @relation(name:"LED_BY") founder: Person @relation(name:"FOUNDED_BY") allies: [House] @relation(name:"ALLIED_WITH", direction:IN) follows: House @relation(name:"SWORN_TO") followers: [House] @relation(name:"SWORN_TO", direction:IN) heir: [Person] @relation(name:"HEIR_TO", direction:IN) } type Person { id: ID! name: String! aliases: [String] books: [Int] tvSeries: [String] playedBy: [String] isFemale: Boolean culture: String died: String titles: [String] founded: [House] @relation(name:"FOUNDED_BY", direction:IN) leads: [House] @relation(name:"LED_BY", direction:IN) inherits: [House] @relation(name:"HEIR_TO") spouse: [Person] @relation(name:"SPOUSE", direction:BOTH) parents: [Person] @relation(name:"PARENT_OF", direction:IN) children: [Person] @relation(name:"PARENT_OF") houses: [House] @relation(name:"ALLIED_WITH") }
  • 8. SPIN UP AN ENDPOINT $ npm install –g neo4j-graphql-cli $ neo4j-graphql got-schema.graphql # configure graphql-cli $ npm install –g graphql-cli $ graphql init # add Auth Headers
  • 12. LOAD VIA API • Iterate over batches of pages • Data cleanup • Replace URLs with IDs • Throttle • INSERT COMPLEX SCRIPT HERE unwind range(1,43) as page call apoc.util.sleep(1) with page, 'characters' as type call apoc.load.jsonArray('https://www.anapioficeandfire.com/api/'+type+'?pageSize=50&page='+page) yield value with apoc.convert.toMap(value) as data MERGE (p:Person {id:split(data.url,"/")[-1]}) SET p += apoc.map.clean(data, ['allegiances','books','father','spouse','mother'],['',[''],[]]), p.books = [b in data.books | split(b,'/')[-1]], p.name = colaesce(p.name,head(p.aliases)) FOREACH (a in data.allegiances | MERGE (h:House {id:split(a,'/')[-1]}) MERGE (p)-[:SWORN_TO]->(h)) FOREACH (f in case coalesce(data.father,"") when "" then [] else [data.father] end | MERGE (o:Person {id:split(f,'/')[-1]}) MERGE (o)-[:PARENT_OF {type:'father'}]->(p)) FOREACH (f in case coalesce(data.mother,"") when "" then [] else [data.mother] end | MERGE (o:Person {id:split(f,'/')[-1]}) MERGE (o)-[:PARENT_OF {type:'mother'}]->(p)) FOREACH (f in case coalesce(data.spouse,"") when "" then [] else [data.spouse] end | MERGE (o:Person {id:split(f,'/')[-1]}) MERGE (o)-[:SPOUSE]-(p)) return p.id, p.name;
  • 13. BETTER! FULL JSON DATA • Full JSON data in Github Repository • Load all characters and houses in one go • No URL conversion • But lowercasing keys • Offline and much faster call apoc.load.jsonArray('https://raw.githubusercontent.com/joakimskoog/AnApiOfIceAndFire/master/data/houses.json') yield value with apoc.convert.toMap(value) as data with apoc.map.clean(data, [],['',[''],[],null]) as data with apoc.map.fromPairs([k in keys(data) | [toLower(substring(k,0,1))+substring(k,1,length(k)), data[k]]]) as data MERGE (h:House {id:data.id}) SET h += apoc.map.clean(data, ['overlord','swornMembers','currentLord','heir','founder','cadetBranches'],['',[''],[],null]) FOREACH (id in data.swornMembers | MERGE (o:Person {id:id}) MERGE (o)-[:ALLIED_WITH]->(h)) FOREACH (s in data.seats | MERGE (seat:Seat {name:s}) MERGE (seat)-[:SEAT_OF]->(h)) FOREACH (id in data.cadetBranches | MERGE (b:House {id:id}) MERGE (b)-[:BRANCH_OF]->(h)) FOREACH (id in case data.overlord when null then [] else [data.overlord] end | MERGE (o:House {id:id}) MERGE (h)-[:SWORN_TO]->(o)) FOREACH (id in case data.currentLord when null then [] else [data.currentLord] end | MERGE (o:Person {id:id}) MERGE (h)-[:LED_BY]->(o)) FOREACH (id in case data.founder when null then [] else [data.founder] end | MERGE (o:Person {id:id}) MERGE (h)-[:FOUNDED_BY]->(o)) FOREACH (id in case data.heir when null then [] else [data.heir] end | MERGE (o:Person {id:id}) MERGE (o)-[:HEIR_TO]->(h)) FOREACH (r in case data.region when null then [] else [data.region] end | MERGE (o:Region {name:r}) MERGE (h)-[:IN_REGION]->(o)) return h.id, h.name;
  • 16. QuERY Data with Cypher
  • 17. MISSING DATA !? MATCH (p:Person) WHERE size(p.tvSeries) > 1 AND NOT exists((p)-[:PARENT_OF]-()) RETURN p LIMIT 10; • Walder • The waif • High Septon • MargaeryTyrell • Tywin Lannister • Unella • AemonTargaryen • AlliserThorne • Arya Stark • Asha Greyjoy
  • 20. Code and instructions for todays presentation • GitHub – https://github.com/neo4j-examples/game-of-thrones • Medium Post – medium.com/@mesirii/a-game-of-data-and-graphql-97ee2ca297ce • Graph ofThrones 7 week contest – https://neo4j.com/blog/graph-of-thrones/ • An API of Ice and Fire – https://github.com/joakimskoog/AnApiOfIceAndFire – https://anapioficeandfire.com/About • GraphQL CLI Load – https://npmjs.org/package/graphql-cli-load
  • 21. Neo 4J GraphQL • http://neo4j.com/developer/graphql • https://npmjs.org/package/neo4j-graphql-cli • http://communitygraph.org/graphql • http://github.com/neo4j-graphql – graphiql4all – graphql-cli-load – neoj4-graphql-cli – community graph – ...
  • 22. More Fun with Graphs and Game of Thrones • Character Interactions – https://networkofthrones.wordpress.com/ – :play https://guides.neo4j.com/got • GraphAnalytics of Character Interactions – http://www.lyonwj.com/2016/06/26/graph-of-thrones-neo4j- social-network-analysis/ • NLP on the book texts – https://graphaware.com/neo4j/2017/07/24/reverse- engineering-book-stories-nlp.html • The Maths of Game ofThrones – https://anthonybonato.com/2016/04/13/the-mathematics-of- game-of-thrones/ • Kaggle GoT Data (Battles) – https://tbgraph.wordpress.com/?s=Game+of+Thrones