2023-07-31 20:48:12 +08:00
|
|
|
const { Neo4jGraphQL } = require("@neo4j/graphql");
|
|
|
|
const { ApolloServer, gql } = require("apollo-server");
|
|
|
|
const neo4j = require("neo4j-driver");
|
|
|
|
|
|
|
|
const typeDefs = gql`
|
|
|
|
type Post {
|
|
|
|
id: ID! @id
|
|
|
|
content: String!
|
|
|
|
creator: User! @relationship(type: "HAS_POST", direction: IN)
|
|
|
|
}
|
|
|
|
|
|
|
|
type User {
|
|
|
|
id: ID! @id
|
|
|
|
name: String
|
|
|
|
posts: [Post!]! @relationship(type: "HAS_POST", direction: OUT)
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const driver = neo4j.driver(
|
|
|
|
"bolt://localhost:7687",
|
|
|
|
neo4j.auth.basic("", "")
|
|
|
|
);
|
|
|
|
|
2023-08-02 00:49:11 +08:00
|
|
|
const neoSchema = new Neo4jGraphQL({
|
|
|
|
typeDefs, driver,
|
|
|
|
config: {
|
|
|
|
driverConfig: {
|
|
|
|
database: "memgraph",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
});
|
2023-07-31 20:48:12 +08:00
|
|
|
|
|
|
|
neoSchema.getSchema().then((schema) => {
|
|
|
|
const server = new ApolloServer({
|
|
|
|
schema,
|
|
|
|
});
|
|
|
|
|
|
|
|
server.listen().then(({ url }) => {
|
|
|
|
console.log(`🚀 Server ready at ${url}`);
|
|
|
|
});
|
|
|
|
})
|