Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-11-2022 10:08 PM
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!
01-05-2023 03:54 PM
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();
All the sessions of the conference are now available online