Skip to content

Commit a90e0a1

Browse files
lidiazuinrecrwplaymjfwebbdarrellwarde
authored
Adds how to add session and transaction to the execution context #59 (#60)
* Add page-aliases for version 4 (#31) (#32) Co-authored-by: Neil Dewhurst <[email protected]> * Editorial review of the latest additions (#34) * Update publish.yml * Editorial review of the most recent changes * reverting changes to partials * fixing note formatting * Add page-aliases for version 4 (#31) (#32) Co-authored-by: Neil Dewhurst <[email protected]> * Editorial review of the most recent changes * fixing note formatting * Add page-aliases for version 4 (#31) (#32) Co-authored-by: Neil Dewhurst <[email protected]> * Editorial review of the most recent changes * fixing note formatting * Add page-aliases for version 4 (#31) (#32) Co-authored-by: Neil Dewhurst <[email protected]> * Editorial review of the most recent changes * Add page-aliases for version 4 (#31) * revert * Apply suggestions from code review Co-authored-by: Michael Webb <[email protected]> --------- Co-authored-by: Neil Dewhurst <[email protected]> Co-authored-by: Michael Webb <[email protected]> * Fix scalar description placeholders #38 (#39) * Editorial review of the most recent changes * reverting changes to partials * fixing note formatting * Add page-aliases for version 4 (#31) (#32) Co-authored-by: Neil Dewhurst <[email protected]> * Editorial review of the most recent changes * fixing note formatting * Editorial review of the most recent changes * fixing note formatting * Add page-aliases for version 4 (#31) (#32) Co-authored-by: Neil Dewhurst <[email protected]> * Editorial review of the most recent changes * Fix scalar description placeholders (#38) --------- Co-authored-by: Neil Dewhurst <[email protected]> Co-authored-by: Darrell Warde <[email protected]> * Editorial review of the most recent changes * reverting changes to partials * Add page-aliases for version 4 (#31) (#32) Co-authored-by: Neil Dewhurst <[email protected]> * Editorial review of the most recent changes * fixing note formatting * Editorial review of the most recent changes * fixing note formatting * Add page-aliases for version 4 (#31) (#32) Co-authored-by: Neil Dewhurst <[email protected]> * Editorial review of the most recent changes * Add how to add session and transaction to the execution context (#59) --------- Co-authored-by: Neil Dewhurst <[email protected]> Co-authored-by: Michael Webb <[email protected]> Co-authored-by: Darrell Warde <[email protected]>
1 parent 9933dd4 commit a90e0a1

File tree

1 file changed

+68
-1
lines changed

1 file changed

+68
-1
lines changed

modules/ROOT/pages/driver-configuration.adoc

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,73 @@ await startStandaloneServer(server, {
7676
7777
----
7878

79+
==== Session in context
80+
81+
[source, javascript, indent=0]
82+
----
83+
import { ApolloServer } from "@apollo/server";
84+
import { startStandaloneServer } from "@apollo/server/standalone";
85+
import { Neo4jGraphQL } from "@neo4j/graphql";
86+
import neo4j from "neo4j-driver";
87+
88+
const typeDefs = `#graphql
89+
type User {
90+
name: String
91+
}
92+
`;
93+
94+
const driver = neo4j.driver(
95+
"bolt://localhost:7687",
96+
neo4j.auth.basic("neo4j", "password")
97+
);
98+
const session = driver.session();
99+
100+
const neoSchema = new Neo4jGraphQL({ typeDefs, driver });
101+
102+
const server = new ApolloServer({
103+
schema: await neoSchema.getSchema(),
104+
});
105+
106+
await startStandaloneServer(server, {
107+
context: async ({ req }) => ({ req, executionContext: session }),
108+
});
109+
110+
----
111+
112+
==== Transaction in context
113+
114+
[source, javascript, indent=0]
115+
----
116+
import { ApolloServer } from "@apollo/server";
117+
import { startStandaloneServer } from "@apollo/server/standalone";
118+
import { Neo4jGraphQL } from "@neo4j/graphql";
119+
import neo4j from "neo4j-driver";
120+
121+
const typeDefs = `#graphql
122+
type User {
123+
name: String
124+
}
125+
`;
126+
127+
const driver = neo4j.driver(
128+
"bolt://localhost:7687",
129+
neo4j.auth.basic("neo4j", "password")
130+
);
131+
const session = driver.transaction();
132+
const transaction = session.beginTransaction();
133+
134+
const neoSchema = new Neo4jGraphQL({ typeDefs, driver });
135+
136+
const server = new ApolloServer({
137+
schema: await neoSchema.getSchema(),
138+
});
139+
140+
await startStandaloneServer(server, {
141+
context: async ({ req }) => ({ req, executionContext: transaction }),
142+
});
143+
144+
----
145+
79146
=== OGM
80147

81148
[source, javascript, indent=0]
@@ -180,4 +247,4 @@ const server = new ApolloServer({
180247
await startStandaloneServer(server, {
181248
context: async ({ req }) => ({ req, sessionConfig: { database: "my-database" }}),
182249
});
183-
----
250+
----

0 commit comments

Comments
 (0)