
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
@mathix420/introspector
Advanced tools
This is a tool that enables you, with very little effort, to introspect the schema / data model in an existing Neo4j database and builds up a set of data structures that can be transformed into any output format.
This is provided by a separate npm package, @mathix420/introspector.
The currently officially supported output format is GraphQL type definitions. This is usually a one-time-thing and should be considered a starting point for a GraphQL schema.
This tool has full support for generating type definitions, including:
@relationship directive, including relationship properties@node
label for mapping where a node label might use a character that's not in the GraphQL supported character setadditionalLabels for nodes that has multiple labels@exclude(operations: [CREATE, DELETE, UPDATE]) directive on all node types.If an element property has mixed types through out your graph, that property will be excluded from the generated type definitions. The reason for this is that your GraphQL server will throw an error if it finds data that doesn't match the specified type.
Currently there's a programmatic API for introspecting the Neo4j schema and generating GraphQL type definitions.
This example introspects the schema, generates GraphQL type definitions and persists them to a file schema.graphql.
You can then serve this file with your GraphQL server.
const { toGraphQLTypeDefs } = require("@mathix420/introspector");
const neo4j = require("neo4j-driver");
const fs = require("fs");
const driver = neo4j.driver("neo4j://localhost:7687", neo4j.auth.basic("neo4j", "password"));
const sessionFactory = () => driver.session({ defaultAccessMode: neo4j.session.READ });
// We create a async function here until "top level await" has landed
// so we can use async/await
async function main() {
const typeDefs = await toGraphQLTypeDefs(sessionFactory);
fs.writeFileSync("schema.graphql", typeDefs);
await driver.close();
}
main();
This example generates a read-only version of the schema from the database and immediately spins up an Apollo server.
Here the type definitions are never persisted to disk.
const { Neo4jGraphQL } = require("@mathix420/graphql");
const { toGraphQLTypeDefs } = require("@mathix420/introspector");
const neo4j = require("neo4j-driver");
const driver = neo4j.driver("neo4j://localhost:7687", neo4j.auth.basic("neo4j", "password"));
const sessionFactory = () => driver.session({ defaultAccessMode: neo4j.session.READ });
// We create a async function here until "top level await" has landed
// so we can use async/await
async function main() {
const readonly = true; // We don't want to expose mutations in this case
const typeDefs = await toGraphQLTypeDefs(sessionFactory, readonly);
const neoSchema = new Neo4jGraphQL({ typeDefs, driver });
const server = new ApolloServer({
schema: neoSchema.schema,
context: ({ req }) => ({ req }),
});
}
main();
You can introspect the schema and then transform it to any desired format.
Example:
const { toGenericStruct } = require("@mathix420/introspector");
const neo4j = require("neo4j-driver");
const driver = neo4j.driver("neo4j://localhost:7687", neo4j.auth.basic("neo4j", "password"));
const sessionFactory = () => driver.session({ defaultAccessMode: neo4j.session.READ });
async function main() {
const genericStruct = await toGenericStruct(sessionFactory, readonly);
// Programatically transform to what you need.
}
main();
FAQs
Introspect a Neo4j database model/schema
We found that @mathix420/introspector demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.