npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mathix420/introspector

v1.0.1

Published

Introspect a Neo4j database model/schema

Downloads

4

Readme

Introspect schema from an existing Neo4j database

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.

GraphQL Type Definitions format

Features

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 set
    • additionalLabels for nodes that has multiple labels
  • Generating a read-only version of the GraphQL type definitions, i.e. generate a @exclude(operations: [CREATE, DELETE, UPDATE]) directive on all node types.

Limitations

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.

Usage examples

Currently there's a programmatic API for introspecting the Neo4j schema and generating GraphQL type definitions.

Introspect and persist to file

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();

Introspect and spin up a read-only schema

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();

Generic format

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();