-
Notifications
You must be signed in to change notification settings - Fork 6
🤖 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
fbiville
merged 1 commit into
main
from
graph-data-science-381a4be4dba5009b61c9322c9724f418397b75f90b113d0bff31f44820ba2340
Dec 22, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
code/graphql/example.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.