Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🤖 Sandbox code update #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions code/graphql/example.js
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const { makeAugmentedSchema, inferSchema } = require("neo4j-graphql-js");
const { ApolloServer } = require("apollo-server");
const neo4j = require("neo4j-driver");

const main = async () => {
// Create Neo4j driver instance
const driver = neo4j.driver(
"bolt://<HOST>:<BOLTPORT>",
neo4j.auth.basic("<USERNAME>", "<PASSWORD>")
);

let typeDefs;
// GraphQL type definitions can be inferred from existing database or
// specified explicitly. Uncomment the lines below to specify typedefs explicitly
// otherwise typedefs will be inferred from existing database
//typeDefs = /* GraphQL */ `
//type Person {
// name: String
// knows: [Person] @relation(name: "KNOWS", direction: "OUT")
// friendCount: Int @cypher(statement:"RETURN SIZE( (this)-[:KNOWS]->(:Person))")
//}
//`;

const getInferredTypes = async (driver) => {
const schemaInferenceOptions = {
alwaysIncludeRelationships: false,
};

const results = await inferSchema(driver, schemaInferenceOptions);
return results.typeDefs;
};

if (!typeDefs) {
typeDefs = await getInferredTypes(driver);
}

// Create executable GraphQL schema from GraphQL type definitions,
// using neo4j-graphql.js to autogenerate resolvers
const schema = makeAugmentedSchema({
typeDefs,
});

// Create ApolloServer instance to serve GraphQL schema
// Inject Neo4j driver instance into the context object
// which is passed into each (autogenerated) resolver
const server = new ApolloServer({
context: { driver },
schema,
});

// Start ApolloServer
server.listen().then(({ url }) => {
console.log(`GraphQL server ready at ${url}`);
});
};

main();

AltStyle によって変換されたページ (->オリジナル) /