Skip to content

added graphql connect #57

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

Closed
wants to merge 7 commits into from
Closed
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
72 changes: 72 additions & 0 deletions documentation/connect-graphql.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
== Install

Install the Neo4j GraphQL library and its peer dependencies with `npm`.

[source, bash]
----
npm install @neo4j/graphql graphql neo4j-driver @apollo/server
----

link:https://neo4j.com/docs/graphql/current/getting-started/[More info on installing the Neo4j GraphQL Library]


== Connect to the database

Connect to the Neo4j server via `neo4j.driver()` and your server credentials.

[source, javascript]
----
import neo4j from "neo4j-driver";

const driver = neo4j.driver(
"<neo4j-database-uri>",
neo4j.auth.basic("<username>", "<password>")
);
----


== Set GraphQL type definitions

Provide the GraphQL type definitions mapping to the nodes and relationships in your Neo4j database through `Neo4jGraphQL`.

.Type definitions for node labels `Actor` and `Movie` and relationship `ACTED_IN`
[source, javascript]
----
import { Neo4jGraphQL } from "@neo4j/graphql";

const typeDefs = `#graphql
type Movie @node {
title: String
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN)
}

type Actor @node {
name: String
movies: [Movie!]! @relationship(type: "ACTED_IN", direction: OUT)
}
`;

const neoSchema = new Neo4jGraphQL({ typeDefs, driver });
----


== Create an instance of Apollo Server

Start an `ApolloServer` instance drawing its schema from the Neo4j type definitions.
Execute mutations and link:https://neo4j.com/docs/graphql/current/getting-started/#_create_nodes_in_the_database[create nodes in the database] through the Apollo server.

[source, javascript]
----
import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone';

const server = new ApolloServer({
schema: await neoSchema.getSchema(),
});

const { url } = await startStandaloneServer(server, {
listen: { port: 4000 },
});

console.log(`🚀 Server ready at ${url}`);
----