Last active
February 3, 2019 22:15
-
-
Save jexp/4622680a49853f4cd6863c36ce915311 to your computer and use it in GitHub Desktop.
graphql load example https://medium.com/@mesirii/better-data-import-with-graphql-548084a35dfd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install -g neo4j-graphql graphql-cli graphql-cli-load | |
mkdir movies; cd movies | |
graphql init | |
neo4j-graphql movies-schema.graphql | |
graphql fetch-schema | |
grep -e "\(create\|add\)" schema.graphql | |
# addMovieActors(id: ID!, actors: [ID!]!): String | |
# createMovie(id: ID!, title: String, year: Long): String | |
# createActor(id: ID!, name: String): String | |
graphql load -m createMovie -file movies.json | |
graphql load -m createPerson -file people.json | |
graphql load -m addMovieActors -file actors.csv -mapping '{movieId:movie, roleName: role}' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
movieId | actors | |
---|---|---|
56 | 57,22,60,59,58 | |
29 | 34,33,30,16,32,31 | |
11 | 13,1,12 | |
46 | 51,20,50,49,47,40,48 | |
52 | 22,54,53,17 | |
37 | 44,40,41,42,43,16,22,38,39 | |
10 | 4,2,3,1 | |
9 | 4,3,2,1 | |
15 | 28,26,23,22,25,24,20,21,18,19,16,17 | |
0 | 8,4,3,2,1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Movie { | |
id: ID! | |
title: String | |
year: Int | |
actors: [Actor] @relation(name: "ACTED_IN", direction: IN) | |
} | |
type Actor { | |
id: ID! | |
name: String | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id": 0, | |
"title": "The Matrix", | |
"year": 1999 | |
} | |
, | |
{ | |
"id": 9, | |
"title": "The Matrix Reloaded", | |
"year": 2003 | |
} | |
, | |
{ | |
"id": 10, | |
"title": "The Matrix Revolutions", | |
"year": 2003 | |
} | |
, | |
{ | |
"id": 11, | |
"title": "The Devil's Advocate", | |
"year": 1997 | |
} | |
, | |
{ | |
"id": 15, | |
"title": "A Few Good Men", | |
"year": 1992 | |
} | |
, | |
{ | |
"id": 29, | |
"title": "Top Gun", | |
"year": 1986 | |
} | |
, | |
{ | |
"id": 37, | |
"title": "Jerry Maguire", | |
"year": 2000 | |
} | |
, | |
{ | |
"id": 46, | |
"title": "Stand By Me", | |
"year": 1986 | |
} | |
, | |
{ | |
"id": 52, | |
"title": "As Good as It Gets", | |
"year": 1997 | |
} | |
, | |
{ | |
"id": 56, | |
"title": "What Dreams May Come", | |
"year": 1998 | |
} | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id": 4, | |
"name": "Hugo Weaving" | |
} | |
, | |
{ | |
"id": 3, | |
"name": "Laurence Fishburne" | |
} | |
, | |
{ | |
"id": 2, | |
"name": "Carrie-Anne Moss" | |
} | |
, | |
{ | |
"id": 1, | |
"name": "Keanu Reeves" | |
} | |
, | |
{ | |
"id": 13, | |
"name": "Al Pacino" | |
} | |
, | |
{ | |
"id": 12, | |
"name": "Charlize Theron" | |
} | |
, | |
{ | |
"id": 28, | |
"name": "Aaron Sorkin" | |
} | |
, | |
{ | |
"id": 26, | |
"name": "Christopher Guest" | |
} | |
, | |
{ | |
"id": 23, | |
"name": "Kevin Pollak" | |
} | |
, | |
{ | |
"id": 22, | |
"name": "Cuba Gooding Jr." | |
} | |
, | |
{ | |
"id": 25, | |
"name": "James Marshall" | |
} | |
, | |
{ | |
"id": 24, | |
"name": "J.T. Walsh" | |
} | |
, | |
{ | |
"id": 20, | |
"name": "Kiefer Sutherland" | |
} | |
, | |
{ | |
"id": 21, | |
"name": "Noah Wyle" | |
} | |
, | |
{ | |
"id": 18, | |
"name": "Demi Moore" | |
} | |
, | |
{ | |
"id": 19, | |
"name": "Kevin Bacon" | |
} | |
, | |
{ | |
"id": 16, | |
"name": "Tom Cruise" | |
} | |
, | |
{ | |
"id": 17, | |
"name": "Jack Nicholson" | |
} | |
, | |
{ | |
"id": 34, | |
"name": "Meg Ryan" | |
} | |
, | |
{ | |
"id": 33, | |
"name": "Tom Skerritt" | |
} | |
, | |
{ | |
"id": 30, | |
"name": "Kelly McGillis" | |
} | |
, | |
{ | |
"id": 32, | |
"name": "Anthony Edwards" | |
} | |
, | |
{ | |
"id": 31, | |
"name": "Val Kilmer" | |
} | |
, | |
{ | |
"id": 44, | |
"name": "Jonathan Lipnicki" | |
} | |
, | |
{ | |
"id": 40, | |
"name": "Jerry O'Connell" | |
} | |
, | |
{ | |
"id": 41, | |
"name": "Jay Mohr" | |
} | |
, | |
{ | |
"id": 42, | |
"name": "Bonnie Hunt" | |
} | |
, | |
{ | |
"id": 43, | |
"name": "Regina King" | |
} | |
, | |
{ | |
"id": 38, | |
"name": "Renee Zellweger" | |
} | |
, | |
{ | |
"id": 39, | |
"name": "Kelly Preston" | |
} | |
, | |
{ | |
"id": 51, | |
"name": "Marshall Bell" | |
} | |
, | |
{ | |
"id": 50, | |
"name": "John Cusack" | |
} | |
, | |
{ | |
"id": 49, | |
"name": "Wil Wheaton" | |
} | |
, | |
{ | |
"id": 47, | |
"name": "River Phoenix" | |
} | |
, | |
{ | |
"id": 48, | |
"name": "Corey Feldman" | |
} | |
, | |
{ | |
"id": 54, | |
"name": "Greg Kinnear" | |
} | |
, | |
{ | |
"id": 53, | |
"name": "Helen Hunt" | |
} | |
, | |
{ | |
"id": 57, | |
"name": "Annabella Sciorra" | |
} | |
, | |
{ | |
"id": 60, | |
"name": "Robin Williams" | |
} | |
, | |
{ | |
"id": 59, | |
"name": "Werner Herzog" | |
} | |
, | |
{ | |
"id": 58, | |
"name": "Max von Sydow" | |
} | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:play movies | |
match (m:Movie) return collect(m {id:id(m), .title, year:m.released})[0..10] as movies | |
-> copy as movies.json | |
match (m:Movie) WITH m limit 10 match (m)<-[:ACTED_IN]-(a) where a.name <> 'Emil Eifrem' return collect(distinct a {id:id(a), .name}) as actors | |
-> copy as actors.json | |
match (m:Movie) WITH m limit 10 match (m)<-[:ACTED_IN]-(a) return id(m) as movieId, collect(id(a)) as actors | |
// download as CSV | |
// register schema | |
call graphql.idl(' | |
type Movie { | |
id: ID! | |
title: String | |
year: Int | |
actors: [Actor] @relation(name: "ACTED_IN", direction: IN) | |
} | |
type Actor { | |
id: ID! | |
name: String | |
} | |
') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment