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
| import { typeDefs } from "./graphql-schema"; | |
| import { ApolloServer } from "apollo-server"; | |
| import { v1 as neo4j } from "neo4j-driver"; | |
| import { makeAugmentedSchema } from "neo4j-graphql-js"; | |
| import dotenv from "dotenv"; | |
| // set environment variables from ../.env | |
| dotenv.config(); | |
| /* |
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 Repository { | |
| url: ID! | |
| created_at: DateTime | |
| description: String | |
| name: String | |
| website: String | |
| webhooks: [Webhook] @relation(name: "HAS_WEBHOOK", direction: "OUT") | |
| pull_requests: [PullRequest] @relation(name: "BASE", direction: "IN") | |
| pr_count: Int @cypher(statement: "RETURN SIZE((this)<-[:BASE]-())") | |
| } |
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
| CALL apoc.load.json("file:///Users/lyonwj/Desktop/pull_requests_000001.json") YIELD value | |
| MERGE (pr:PullRequest {url: value.url}) | |
| SET pr += value{created_at: DateTime(value.created_at), closed_at: DateTime(value.closed_at), merged_at: DateTime(value.merged_at), .title, .body } | |
| MERGE (head:Repository {url: coalesce(value.head.repo,"")}) | |
| MERGE (head)<-[h:HEAD]-(pr) | |
| SET h = {sha: value.head.sha, ref: value.head.ref} | |
| MERGE (base:Repository {url: value.base.repo}) | |
| MERGE (base)<-[b:BASE]-(pr) | |
| SET b = {sha: value.base.sha, ref: value.base.ref} | |
| MERGE (u:User {url: value.user}) |
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
| CALL apoc.load.json("file:///Users/lyonwj/Desktop/users_000001.json") YIELD value | |
| MERGE (u:User {url: value.url}) | |
| SET u += value {created_at: DateTime(value.created_at), .avatar_url, .website, .name, .bio, .company, .location, .login} |
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
| // load repositories | |
| UNWIND ["repositories_000001.json", "repositories_000002.json"] AS file | |
| CALL apoc.load.json($baseURL + file) YIELD value | |
| // only import public repos | |
| WITH value AS repo WHERE repo.private = false | |
| MERGE (r:Repository {url: repo.url}) | |
| SET r += repo {.name, .description, .website, created_at: DateTime(repo.created_at)} | |
| MERGE (u:User {url: repo.owner}) | |
| MERGE (r)<-[:OWNS]-(u) |
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
| CREATE CONSTRAINT ON (r:Repository) ASSERT r.url IS UNIQUE; | |
| CREATE CONSTRAINT ON (u:User) ASSERT u.url IS UNIQUE; | |
| CREATE CONSTRAINT ON (h:Webhook) ASSERT h.url IS UNIQUE; | |
| CREATE CONSTRAINT ON (p:PullRequest) ASSERT p.url IS UNIQUE; | |
| CREATE CONSTRAINT ON (i:Issue) ASSERT i.url IS UNIQUE; | |
| CREATE CONSTRAINT ON (c:IssueComment) ASSERT c.url IS UNIQUE; |
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
| // defined in App.js, this function is passed to the | |
| // Map component as a prop | |
| mapSearchPointChange = viewport => { | |
| this.setState({ | |
| mapCenter: { | |
| ...this.state.mapCenter, | |
| latitude: viewport.latitude, | |
| longitude: viewport.longitude, | |
| zoom: viewport.zoom |
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
| // event handler for draggable marker in Map component | |
| const onDragEnd = e => { | |
| var lngLat = e.target.getLngLat(); | |
| const viewport = { | |
| latitude: lngLat.lat, | |
| longitude: lngLat.lng, | |
| zoom: this.map.getZoom() | |
| }; | |
| this.props.mapSearchPointChange(viewport); |
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
| import { Date } from "neo4j-driver/lib/v1/temporal-types"; | |
| fetchBusinesses = () => { | |
| const { mapCenter, startDate, endDate } = this.state; | |
| const session = this.driver.session(); | |
| session.run(` | |
| MATCH (b:Business)<-[:REVIEWS]-(r:Review) | |
| WHERE $start <= r.date <= $end | |
| AND distance(b.location, | |
| point({latitude: $lat, longitude: $lon})) < ( $radius * 1000) |
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
| // import the web brower version of neo4j-javascript-driver | |
| import neo4j from "neo4j-driver/lib/browser/neo4j-web"; | |
| class App extends Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = ... // set default state | |
| // instantiate Neo4j driver instance | |
| this.driver = neo4j.driver( | |
| process.env.REACT_APP_NEO4J_URI, | |
| neo4j.auth.basic( |