{"id":16853557,"url":"https://github.com/sim51/graphology-neo4j","last_synced_at":"2025-04-11T07:14:07.707Z","repository":{"id":57253317,"uuid":"371647419","full_name":"sim51/graphology-neo4j","owner":"sim51","description":"Create a graphology Graph from cypher queries","archived":false,"fork":false,"pushed_at":"2021-11-01T13:21:42.000Z","size":733,"stargazers_count":11,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T04:52:18.346Z","etag":null,"topics":["database","graph","graph-database","graphology","neo4j","typescript"],"latest_commit_sha":null,"homepage":"https://sim51.github.io/graphology-neo4j","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sim51.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-28T09:22:06.000Z","updated_at":"2024-02-02T20:39:44.000Z","dependencies_parsed_at":"2022-08-31T22:20:13.953Z","dependency_job_id":null,"html_url":"https://github.com/sim51/graphology-neo4j","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sim51%2Fgraphology-neo4j","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sim51%2Fgraphology-neo4j/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sim51%2Fgraphology-neo4j/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sim51%2Fgraphology-neo4j/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sim51","download_url":"https://codeload.github.com/sim51/graphology-neo4j/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248358603,"owners_count":21090405,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","graph","graph-database","graphology","neo4j","typescript"],"created_at":"2024-10-13T13:52:04.981Z","updated_at":"2025-04-11T07:14:07.658Z","avatar_url":"https://github.com/sim51.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Graphology Neo4j [![CI](https://github.com/sim51/graphology-neo4j/actions/workflows/test.yml/badge.svg)](https://github.com/sim51/graphology-neo4j/actions/workflows/test.yml)\n\nSome graphology helpers for Neo4j\n\n## Usage\n\nThis library doesn’t include the Neo4j driver library as well as the Graphology one.\nThey are peer dependencies, so you need to install them by yourself.\n\n    npm install neo4j-driver graphology graphology-neo4j\n\n### Translate a cypher query to a graph\n\nYou can create a graph directly from a cypher query.\nThe method `cypherToGraph` will parse the whole result to find Neo4j nodes and relationships for building the graph.\n\nThis is the definition of this method :\n\n    /**\n     * Create a graphology graph based on the result of a cypher query.\n     *\n     * @param neo4j Object with the neo4j's driver and optionally the database name\n     * @param cypher Query to executed for the graph creation\n     * @param params Query's parameters\n     * @param opts Allow you to defined the graphology attribut mapping for neo4j's ids (default @id), node's labels (default @labels) \u0026 relationship's type (default @type).\n     * @returns A graphology instance\n     */\n    export function cypherToGraph(\n      neo4j: { driver: Driver; database?: string },\n      cypher: string,\n      params: { [param: string]: unknown } = {},\n      opts: CypherToGraphOpts = { id: \"@id\", labels: \"@labels\", type: \"@type\" },\n    ): Promise\u003cGraph\u003e;\n\nExample:\n\n```typescript\nimport * as neo4j from \"neo4j-driver\";\nimport Graph from \"graphology\";\nimport { cypherToGraph } from \"graphology-neo4j\";\n\nconst driver: neo4j.Driver = neo4j.driver(\"bolt://localhost\", neo4j.auth.basic(\"neo4j\", \"admin\"));\nconst graph: Graph = await cypherToGraph({ driver }, \"MATCH (n)-[r]-\u003e(m) RETURN n,r,m\");\n```\n\n\u003cdiv class=\"note\"\u003e\nYour cypher query must returned `Node`, `Relationship`, `Path`, and Arrays of those.\n\u003c/div\u003e\n\n### Create a graph from a Cypher projection\n\nYou can create a graph from a cypher projection as defined\n[here](https://neo4j.com/docs/graph-algorithms/current/projected-graph-model/cypher-projection/),\nwith the help of the method `cypherProjectionToGraph` .\n\nThis is the definition of this method :\n\n    /**\n     * Create a graphology graph based on the cypher projection queries.\n     *\n     * @param neo4j Object with the neo4j's driver and optionally the database name\n     * @param cypherNodes The query to executed to get nodes. The query must return an `id` field and other fiels with be added as node's property\n     * @param cypherRelationships The query to executed to get edges. The query must returns a field `source` and `target`,\n     * @param params Query parameters that will be passed to both queries\n     * @param opts Allow you to defined the graphology attribut mapping for neo4j's ids (default @id), node's labels (default @labels) \u0026 relationship's type (default @type).\n     * @returns A graphology instance\n     */\n    export async function cypherProjectionToGraph(\n      neo4j: { driver: Driver; database?: string },\n      cypherNodes: string,\n      cypherRelationships: string,\n      params: { [param: string]: unknown } = {},\n      opts: CypherToGraphOpts = { id: \"@id\", labels: \"@labels\", type: \"@type\" },\n    ): Promise\u003cGraph\u003e\n\nExample:\n\n```typescript\nimport * as neo4j from \"neo4j-driver\";\nimport Graph from \"graphology\";\nimport { cypherProjectionToGraph } from \"graphology-neo4j\";\n\nconst driver: neo4j.Driver = neo4j.driver(\"bolt://localhost\", neo4j.auth.basic(\"neo4j\", \"admin\"));\nconst graph = await cypherProjectionToGraph(\n  { driver },\n  \"MATCH (p:Person) RETURN id(p) AS id, labels(p) AS labels, p.name AS name\",\n  \"MATCH (p1:Person)-[:ACTED_IN]-\u003e(:Movie)\u003c-[:ACTED_IN]-(p2:Person) WHERE id(p1) \u003c id(p2) RETURN id(p1) AS source, id(p2) AS target, count(*) AS weight, 'COLLEAGUE' AS type\",\n  {},\n  { id: \"_id\", labels: \"_labels\", type: \"_type\" },\n);\n```\n\n### Export a graphology graph as a Cypher script\n\nYou can export a graph as cypher script, with the help of the method `exportToCypher`.\n\nExample : `const cypherScript = exportToCypher(graph)`\n\nIt generates a cypher script with `CREATE` instructions.\n\n## The graphology Graph\n\nThe graphology created graph is a multi directed graph, where self-loop are allowed (it’s like in Neo4j).\nBut in Graphology the notion of `label` for nodes and `type` for relationships don’t exist.\nThat’s why there is the `CypherToGraphOpts` object where you can define on which property those notions will be saved.\n\n- Graphology and Neo4j id are the same, but they are also stored on nodes and edges in the property `@id`.\n\n- Neo4j node’s labels are stored in the property `@labels`\n\n- Neo4j edge’s type is stored in the property `@type`\n\n## Development\n\nTo run the tests you need to have a local Neo4j server with Movie database and the password set to `admin`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsim51%2Fgraphology-neo4j","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsim51%2Fgraphology-neo4j","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsim51%2Fgraphology-neo4j/lists"}