cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Graphql) Where I have to specify database name when make the schema from introspecting graph?

Hi! Glad to meet you everyone

I want to specify the database name in schema.js ,
But I'm still struggling with positioning the DB name in code

const neo4j = require("neo4j-driver");
const { inferSchema } = require("neo4j-graphql-js");
const fs = require("fs");

const dotenv = require("dotenv");
dotenv.config();
const { NEO4J_URI, NEO4J_USER, NEO4J_PASSWORD } = process.env
const driver = neo4j.driver(NEO4J_URI, neo4j.auth.basic(NEO4J_USER, NEO4J_PASSWORD));

const schemaInferenceOptions = {
  alwaysIncludeRelationships: false
};

inferSchema(driver, schemaInferenceOptions, {database : "dbname"}).then(result => {
  fs.writeFile("schema-111.graphql", result.typeDefs, err => {
    if (err) throw err;
    console.log("Updated schema.graphql");
    process.exit(0);
  });
});

I add "{database : "dbname"}' this code in the inferSchema paramter, But it doesn't work
Any Comments would be appreciated.
Thanks!

1 REPLY 1

William_Lyon
Graph Fellow

See the neo4j/introspector  package, which will allow you to control the session where you can specify the database name:

 

const { toGraphQLTypeDefs } = require("@neo4j/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({database: "dbname", 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();