{"id":14959342,"url":"https://github.com/neo4j/graph-schema-json-js-utils","last_synced_at":"2025-10-19T07:31:48.804Z","repository":{"id":65757498,"uuid":"532650634","full_name":"neo4j/graph-schema-json-js-utils","owner":"neo4j","description":"Utility library to work with the Graph Schema JSON representation ","archived":false,"fork":false,"pushed_at":"2024-12-19T14:51:07.000Z","size":569,"stargazers_count":7,"open_issues_count":1,"forks_count":7,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-01-29T10:36:18.131Z","etag":null,"topics":["graph-database","json-schema","property-graph","schema"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/neo4j.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-04T20:28:51.000Z","updated_at":"2025-01-21T08:24:05.000Z","dependencies_parsed_at":"2023-06-28T14:32:25.151Z","dependency_job_id":"3cf4cbb5-ab8e-4f7c-8ba8-5b24de1a6d23","html_url":"https://github.com/neo4j/graph-schema-json-js-utils","commit_stats":{"total_commits":242,"total_committers":5,"mean_commits":48.4,"dds":0.5743801652892562,"last_synced_commit":"fe8a8f8d12787b44c671b65cc2708b8dbc9e5ea7"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neo4j%2Fgraph-schema-json-js-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neo4j%2Fgraph-schema-json-js-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neo4j%2Fgraph-schema-json-js-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neo4j%2Fgraph-schema-json-js-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neo4j","download_url":"https://codeload.github.com/neo4j/graph-schema-json-js-utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237088522,"owners_count":19253569,"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":["graph-database","json-schema","property-graph","schema"],"created_at":"2024-09-24T13:19:30.164Z","updated_at":"2025-10-19T07:31:48.393Z","avatar_url":"https://github.com/neo4j.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Graph Schema JSON utility library\n\n## Install\n\n```\nnpm install @neo4j/graph-schema-utils\n```\n\n## How to consume\n\nThere are two parts to this repo:\n\n1. A JSON schema that describes how a graph schema should be expressed in JSON.\n2. Utility functions that help the consumers to validate and work with a graph schema.\n\n### JSON-schema\n\nThe JSON that describes the shape of a graph schema is available in the source code (`packages/json-schema/json-schema.json`) and published on: https://dist.neo4j.org/json-graph-schema/ (to be published, not in place yet)\n\n### Validate\n\nThis function is needed to perform a validation on a graph schema. The validateSchema function compares the output against the JSON schema.\n\n```js\nimport { validateSchema } from \"@neo4j/graph-schema-utils\";\n\nvalidateSchema(jsonSchema, graphSchema);\n```\n\n### Parse\n\nSince the references in the JSON document are references by id:s, there's a parser utility that hydrates the references and makes it easy to work with the schema.\n\n```js\nimport { formatters } from \"@neo4j/graph-schema-utils\";\n\nconst parsed = formatters.json.fromJson(graphSchemaJsonString);\n```\n\n### Model\n\nYou can also create a schema model programatically.\nExample:\n\n```js\nimport { model } from \"@neo4j/graph-schema-utils\";\n\nconst labels = [\n  new model.NodeLabel(\"l1\", \"Person\"),\n  new model.NodeLabel(\"l1\", \"Movie\"),\n];\n\nconst relationshipTypes = [new model.RelationshipType(\"rt1\", \"ACTED_IN\")];\n\nconst properties = [\n  new model.Property(\"name\", new model.PropertyBaseType(\"string\"), true),\n  new model.Property(\"title\", new model.PropertyBaseType(\"string\"), true),\n  new model.Property(\n    \"roles\",\n    new model.PropertyArrayType(new model.PropertyBaseType(\"string\")),\n    false\n  ),\n];\n\nconst nodeObjectTypes = [\n  new model.NodeObjectType(\"n1\", [labels[0]], [properties[0]]), // (:Person {name}) node type\n  new model.NodeObjectType(\"n2\", [labels[1]], [properties[1]]), // (:Movie {title}) node type\n];\n\nconst relationshipObjectTypes = [\n  // (:Person {name})-[:ACTED_IN {roles}]-\u003e(:Movie {title})\n  new model.RelationshipObjectType(\n    \"r1\",\n    relationshipTypes[0],\n    nodeObjectTypes[0],\n    nodeObjectTypes[1],\n    [properties[2]]\n  ),\n];\n\nconst graphSchema = new model.GraphSchema(\n  nodeObjectTypes,\n  relationshipObjectTypes\n);\n```\n\n### Serialize\n\nIf you need to transport or persist the schema, you can serialize the model into the JSON represenation.\n\n```js\nimport { formatters } from \"@neo4j/graph-schema-utils\";\n\nconst serialized = formatters.json.toJson(graphSchema);\n```\n\n## Contribute\n\nWe welcome contributions to this repo. Fork this repo and open a PR!\n\n### Run test\n\nTo run a single test run:\n\n```bash\nnpm run test\n```\n\nTo watch for changes and run tests on change:\n\n```bash\nnpm run test:watch\n```\n\n### Build\n\nTo build the TypeScript:\n\n```bash\nnpm run build\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneo4j%2Fgraph-schema-json-js-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneo4j%2Fgraph-schema-json-js-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneo4j%2Fgraph-schema-json-js-utils/lists"}