GraphQL GRANDstack Episode 005

Опубликовано: 19 Май 2026
на канале: The Broke Gamer
30
0

This is a tutorial series about GraphSQL programing with React, Node.js and Neo4j made for Amateurs and anyone interested in learning Full-Stack Application development.

Neo4j Download Link: https://neo4j.com/download/
Graph Data Model Diagramming Tool: https://arrows.app
Cypher Style Guide: https://neo4j.com/docs/cypher-manual/...
Neo4j Client Driver and Language Guides: https://neo4j.com/docs/create-applica...
The Neo4j GraphQL Library Documentation: https://neo4j.com/docs/graphql/current/

/////////////////////////// Commands & Cyphers Used ////////////////////////////////
Creating DB:
MERGE (b:Business {name: "Bob's Pizza"})
MERGE (r:Review {stars: 4, text: "Great pizza!"})
MERGE (u:User {name: "Willie"})
RETURN *

Empty DB:
MATCH (a) DETACH DELETE a;

Sample Dataset:
LOAD CSV WITH HEADERS FROM "https://cdn.neo4jlabs.com/data/grands..." AS row

MERGE (b:Business {businessId: row.businessId})
ON CREATE SET b.name = row.businessName,
b.city = row.businessCity,
b.state = row.businessState,
b.address = row.businessAddress,
b.location = Point({latitude: toFloat(row.latitude), longitude: toFloat(row.longitude)})

MERGE (u:User {userId: row.userId})
ON CREATE SET u.name = row.userName

MERGE (r:Review {reviewId: row.reviewId})
ON CREATE SET r.text = row.reviewText,
r.stars = toFloat(row.reviewStars),
r.date = row.reviewDate

MERGE (u)-[:WROTE]->(r)
MERGE (r)-[:REVIEWS]->(b)

WITH *

UNWIND split(row.categories, ",") AS cat
MERGE (c:Category {name: cat})
MERGE (c)<-[:IN_CATEGORY]-(b)

Visualizing the graph schema in Neo4j:
CALL db.schema.visualization();

Neo4j GraphQL library and Neo4j drivers Installation:
npm i @neo4j/graphql neo4j-driver

Neo4j GraphQL library's Debug logging Used With Git-Bash:
DEBUG=@neo4j/graphql:* nodemon index.js
/////////////////////////// Commands & Cyphers Used ////////////////////////////////

/////////////////////////// Index.js ////////////////////////////////
const { ApolloServer } = require("apollo-server");
const neo4j = require("neo4j-driver");
const { Neo4jGraphQL } = require("@neo4j/graphql");

const typeDefs = /* GraphQL */ `
type Business @node{
businessId: ID!
name: String!
city: String!
state: String!
address: String!
location: Point!
reviews: [Review!]! @relationship(type: "REVIEWS", direction: IN)
categories: [Category!]! @relationship(type: "IN_CATEGORY", direction: OUT)
}

type User @node{
userID: ID!
name: String!
reviews: [Review!]! @relationship(type: "WROTE", direction: OUT)
}

type Review @node{
reviewId: ID!
stars: Float!
date: Date!
text: String
user: User! @relationship(type: "WROTE", direction: IN)
business: Business! @relationship(type: "REVIEWS", direction: OUT)
}

type Category @node{
name: String!
businesses: [Business!]! @relationship(type: "IN_CATEGORY", direction: IN)
}
`;

const driver = neo4j.driver(
"bolt://localhost:7687",
neo4j.auth.basic("neo4j", "password")
);

const neoSchema = new Neo4jGraphQL({ typeDefs, driver});

neoSchema.getSchema().then((schema) => {
const server = new ApolloServer({
schema,
});
server.listen().then(({ url }) => {
console.log(`GraphQL server ready at ${url}`);
});
});
/////////////////////////// Index.js ////////////////////////////////