Skip to content

Commit

Permalink
Adding final version of the index.js file (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
lidiazuin authored Jan 8, 2024
1 parent 1f88d16 commit 6eab853
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion modules/ROOT/pages/getting-started/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ cd neo4j-graphql-example
npm init es6 --yes
----
+
. Create an empty `index.js` file which with all of the code for this example:
. Create an empty `index.js` file which will contain all of the code for this example:
+
[source, bash, indent=0]
----
Expand Down Expand Up @@ -168,6 +168,46 @@ If successful, you should see the following output:

The address http://localhost:4000/ is the default URL in which Apollo Server starts at.

This is how your `index.js` file should look after following the previous steps:

[source, javascript]
----
import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone';
import { Neo4jGraphQL } from "@neo4j/graphql";
import neo4j from "neo4j-driver";
const typeDefs = `#graphql
type Movie {
title: String
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN)
}
type Actor {
name: String
movies: [Movie!]! @relationship(type: "ACTED_IN", direction: OUT)
}
`;
const driver = neo4j.driver(
"bolt://localhost:7687",
neo4j.auth.basic("neo4j", "password")
);
const neoSchema = new Neo4jGraphQL({ typeDefs, driver });
const server = new ApolloServer({
schema: await neoSchema.getSchema(),
});
const { url } = await startStandaloneServer(server, {
context: async ({ req }) => ({ req }),
listen: { port: 4000 },
});
console.log(`🚀 Server ready at ${url}`);
----

== Create nodes in the database

. Visit http://localhost:4000/ in your web browser.
Expand Down

0 comments on commit 6eab853

Please sign in to comment.