From cc20165a7aff5272b3690198917ffeb797c32c9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandbox=20=F0=9F=A4=96?= Date: 2020年12月22日 10:31:59 +0000 Subject: [PATCH] Updating sandbox graph-data-science --- code/graphql/example.js | 57 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 code/graphql/example.js diff --git a/code/graphql/example.js b/code/graphql/example.js new file mode 100644 index 0000000..6ca867b --- /dev/null +++ b/code/graphql/example.js @@ -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://:", + neo4j.auth.basic("", "") + ); + + 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(); \ No newline at end of file

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