Setup
Quick Start
You can skip steps 2, 3, 4 by running npm build command.
Prerequisites
A running
neo4jdatabase instance.Set the following environment variables:
NEO4J_URI=bolt://35.156.6.182:7687NEO4J_USER=neo4jNEO4J_PASSWORD="xyzw"GRAPHQL_LISTEN_PORT=4001GRAPHQL_URI=http://localhost:4001/graphql
1. Mapping a data row to an edge
Goto setup/fieldsMapping.js and edit the file accordingly to your data.
Meaning, you should provide the mapping between each data row in the csv to an edge connecting to nodes (startNode, stopNode, edgeInfo).
fieldNamestands for the name of the field as it will be represented in the GraphQL schema.fieldDataNamestands for the name of the field as it shown in the csv header.fieldTypea GraphQL type of the field. If you would like to provide sort and filter options, useGRAPHQL.GraphQLString.
Mapping Example
In the Hubway dataset, each data row contains the following fields:
"tripduration","starttime","stoptime","start station id","start station name","start station latitude","start station longitude","end station id","end station name","end station latitude","end station longitude","bikeid","usertype","birth year","gender"
Therefore, a mapping will be:
exports.fieldsMapping = {startNode: [// required:{ fieldName: 'id', fieldDataName: 'start station id', fieldType: GRAPHQL.GraphQLID },{fieldName: 'latitude',fieldDataName: 'start station latitude',fieldType: GRAPHQL.GraphQLString,},{fieldName: 'longitude',fieldDataName: 'start station longitude',fieldType: GRAPHQL.GraphQLString,},// optional:{ fieldName: 'name', fieldDataName: 'start station name', fieldType: GRAPHQL.GraphQLString },],endNode: [// required:{ fieldName: 'id', fieldDataName: 'end station id', fieldType: GRAPHQL.GraphQLID },{fieldName: 'latitude',fieldDataName: 'end station latitude',fieldType: GRAPHQL.GraphQLString,},{fieldName: 'longitude',fieldDataName: 'end station longitude',fieldType: GRAPHQL.GraphQLString,},// optional:{ fieldName: 'name', fieldDataName: 'end station name', fieldType: GRAPHQL.GraphQLString },],edgeInfo: [// required:{ fieldName: 'startTime', fieldDataName: 'starttime', fieldType: GRAPHQL.GraphQLString },{ fieldName: 'stopTime', fieldDataName: 'stoptime', fieldType: GRAPHQL.GraphQLString },// optional:{ fieldName: 'bikeID', fieldDataName: 'bikeid', fieldType: GRAPHQL.GraphQLString },{ fieldName: 'userType', fieldDataName: 'usertype', fieldType: GRAPHQL.GraphQLString },{ fieldName: 'birthYear', fieldDataName: 'birth year', fieldType: GRAPHQL.GraphQLString },{ fieldName: 'gender', fieldDataName: 'gender', fieldType: GRAPHQL.GraphQLString },],};
2. Create GraphQL Schema
Run the node setup/createSchema.js command to create GraphQL schema according to the mapping you provided in the previous stage.
The GraphQL schema provides the type definitions, functions, queries and mutations.
Schema Example
Generating schema from Hubway dataset will result build/schema.graphql file:
type Edge {startNode: NodestopNode: NodestartTime: StringstopTime: StringbikeID: StringuserType: StringbirthYear: Stringgender: Stringid: ID}input EdgeFilterParameter {startNode: NodeFilterParameterstopNode: NodeFilterParameterstartTime: StringOperatorsstopTime: StringOperatorsbikeID: StringOperatorsuserType: StringOperatorsbirthYear: StringOperatorsgender: StringOperators}input EdgeSortParameter {startNode: NodeSortParameterstopNode: NodeSortParameterstartTime: SortOrderstopTime: SortOrderbikeID: SortOrderuserType: SortOrderbirthYear: SortOrdergender: SortOrder}type EdgeUpdateResponse {success: Booleanmessage: Stringedge: Edge}type Mutation {CreateEdge(startNode: NodeInputstopNode: NodeInputstartTime: StringstopTime: StringbikeID: StringuserType: StringbirthYear: Stringgender: String): EdgeUpdateResponseUpdateEdge(startNode: NodeInputstopNode: NodeInputstartTime: StringstopTime: StringbikeID: StringuserType: StringbirthYear: Stringgender: String): EdgeUpdateResponseDeleteEdge(id: ID!): EdgeUpdateResponseCreateNode(id: ID, latitude: String, longitude: String, name: String): NodeUpdateResponseUpdateNode(id: ID!, latitude: String, longitude: String, name: String): NodeUpdateResponseDeleteNode(id: ID!): NodeUpdateResponse}type Node {id: IDlatitude: Stringlongitude: Stringname: String}input NodeFilterParameter {id: StringOperatorslatitude: StringOperatorslongitude: StringOperatorsname: StringOperators}input NodeInput {id: IDlatitude: Stringlongitude: Stringname: String}input NodeSortParameter {id: SortOrderlatitude: SortOrderlongitude: SortOrdername: SortOrder}type NodeUpdateResponse {success: Booleanmessage: Stringnode: Node}type Query {Node(id: String!): NodeEdge(id: String!): EdgeNodes(sort: NodeSortParameter, filter: NodeFilterParameter, limit: Int): [Node]Edges(sort: EdgeSortParameter, filter: EdgeFilterParameter, limit: Int): [Edge]Paths(startNodeIDs: [String]stopNodeIDs: [String]length: Int!limit: Int!filter: EdgeFilterParameter): [[Edge]]MostConnected(nodesLimit: Int!pathsLimit: Int!pathLength: Int!filter: EdgeFilterParameter): [[Edge]]}enum SortOrder {ASCDESC}input StringOperators {eq: Stringcontains: Stringgt: Stringlt: String}
3. Create TypeScript Types
Run the node setup/createTypes.js command to create GraphQL schema according to the mapping you provided in the previous stage.
Types Example
Generating types for Hubway dataset will result build/types.ts file:
export interface Node {id: string;latitude: string;longitude: string;name: string;}export interface Edge {startNode: Node;stopNode: Node;startTime: string;stopTime: string;bikeID: string;userType: string;birthYear: string;gender: string;}
4. Build
Run the tsc command to compile the src folder to JavaScript. The compiled .js files will be in the build folder.