Cypher/GQL
Cypher is Neo4j's graph query language; GQL is the emerging ISO standard for graph queries, based on Cypher. Both use ASCII-art syntax for pattern matching.
Infrastructure
Cypher is an expressive graph query language using ASCII-art patterns to match graph structures. GQL is the ISO standard based on Cypher.
Basic Queries
// Create nodes
CREATE (jane:Person {name: "Jane Smith", age: 30})
CREATE (techcorp:Company {name: "TechCorp"})
// Create relationship
MATCH (p:Person {name: "Jane Smith"})
MATCH (c:Company {name: "TechCorp"})
CREATE (p)-[:WORKS_AT {since: 2020}]->(c)
// Query
MATCH (p:Person)-[r:WORKS_AT]->(c:Company)
WHERE r.since >= 2020
RETURN p.name, c.name, r.since
Path Matching
// Find paths
MATCH path = (start:Person {name: "Jane"})-[*1..4]-(end:Person {name: "John"})
RETURN path, length(path) as hops
ORDER BY hops
// Shortest path
MATCH path = shortestPath((a:Person)-[*]-(b:Person))
WHERE a.name = "Jane" AND b.name = "John"
RETURN path
TrustGraph Usage
await trustgraph.query({
cypher: `
MATCH (p:Person)-[:WORKS_ON]->(proj:Project)
WHERE proj.status = "active"
RETURN p.name, collect(proj.name) as projects
`
});
See Also
Examples
- •MATCH (p:Person)-[:WORKS_AT]->(c:Company) RETURN p.name, c.name
- •MATCH path = shortestPath((a)-[*]-(b)) RETURN path