Skip to content

Commit 1d77f3c

Browse files
mjfwebbrsill-neo4j
andauthored
Update docs to use features instead of Neo4jGraphQLSubscriptionsSingleInstancePlugin (#167)
* Update docs to use features instead of Neo4jGraphQLSubscriptionsSingleInstancePlugin * small adjustments, mostly a heading alias that was never working + an xref to that heading --------- Co-authored-by: Richard Sill <richard.sill@neo4j.com>
1 parent 4858092 commit 1d77f3c

File tree

2 files changed

+50
-40
lines changed

2 files changed

+50
-40
lines changed

modules/ROOT/pages/ogm/subscriptions.adoc

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This section shows how to use subscriptions with the OGM inside custom resolvers
1010

1111
=== Prerequisites
1212

13-
. Use the following type definitions:
13+
Use the following type definitions:
1414
[source, javascript, indent=0]
1515
----
1616
const typeDefs = `#graphql
@@ -21,28 +21,32 @@ const typeDefs = `#graphql
2121
`;
2222
----
2323

24-
. Set up a subscriptions plugin instance to be shared between the Library and the OGM constructors:
25-
[source, javascript, indent=0]
26-
----
27-
const subscriptionsPlugin = new Neo4jGraphQLSubscriptionsSingleInstancePlugin();
28-
----
24+
Set up a server that supports subscriptions. See more instructions in the xref:subscriptions/getting-started.adoc#_setting_up_an_apolloserver_server[Getting started] page.
2925

30-
. Set up a server that supports subscriptions.
31-
See more instructions in the xref:subscriptions/getting-started.adoc#setting-up-server[Getting started page].
26+
=== Adding the OGM
3227

28+
Enable the subscriptions feature in the OGM constructor:
3329

34-
=== Adding the OGM
30+
[source, javascript, indent=0]
31+
----
32+
const ogm = new OGM({
33+
typeDefs,
34+
driver,
35+
features: {
36+
subscriptions: true
37+
},
38+
});
39+
----
3540

36-
In order to utilize the `@private` marked field on the `User` type, you need to create the `User` model.
37-
Also, to use the subscriptions, you need to pass in the subscriptions plugin instance to the OGM constructor:
41+
Create the `User` model, which utilizes the `@private` marked field on the `User` type in the type definitions.
3842

3943
[source, javascript, indent=0]
4044
----
41-
const ogm = new OGM({ typeDefs, driver, plugins: { subscriptions: subscriptionsPlugin } });
42-
const Profile = ogm.model("Profile");
45+
const User = ogm.model("User");
4346
----
4447

45-
Make sure you initialize the OGM instance before using it by adding the following line to the `main()` function:
48+
Initialize the OGM instance before using it by adding the following line to the `main()` function:
49+
4650
[source, javascript, indent=0]
4751
----
4852
await ogm.init();
@@ -52,39 +56,39 @@ await ogm.init();
5256

5357
xref:custom-resolvers/[Custom resolvers] can be used for multiple reasons such as performing data manipulation and checks, or interact with third party systems.
5458
In this case, you only need to create a `User` node with the `password` field set.
55-
You can do that by adding a sign-up mutation.
56-
For example:
59+
You can do that by adding a sign-up mutation:
5760

5861
[source, javascript, indent=0]
5962
----
6063
const resolvers = {
6164
Mutation: {
6265
signUp: async (_source, { username, password }) => {
6366
const [existing] = await User.find({
64-
where: {
65-
username,
66-
},
67+
where: {
68+
username,
69+
},
6770
});
6871
if (existing) {
69-
throw new Error(`User with username ${username} already exists!`);
72+
throw new Error(`User with username ${username} already exists!`);
7073
}
7174
const { users } = await User.create({
72-
input: [
73-
{
74-
username,
75-
password,
76-
}
77-
]
75+
input: [
76+
{
77+
username,
78+
password,
79+
},
80+
],
7881
});
7982
return createJWT({ sub: users[0].id });
8083
},
8184
},
8285
};
8386
const typeDefs = `
84-
type Mutation {
87+
type Mutation {
8588
signUp(username: String!, password: String!): String!
8689
}
87-
`
90+
`;
91+
8892
----
8993

9094
[discrete]
@@ -94,7 +98,6 @@ Altogether, it should look like this:
9498

9599
[source, javascript, indent=0]
96100
----
97-
const subscriptionsPlugin = new Neo4jGraphQLSubscriptionsSingleInstancePlugin();
98101
const driver = neo4j.driver(
99102
"bolt://localhost:7687",
100103
neo4j.auth.basic("neo4j", "password")
@@ -131,17 +134,22 @@ const resolvers = {
131134
},
132135
},
133136
};
134-
// Share the subscriptions plugin instance across the Library and the OGM
135137
const neoSchema = new Neo4jGraphQL({
136-
typeDefs,
137-
driver,
138-
resolvers,
139-
plugins: {
140-
subscriptions: subscriptionsPlugin,
141-
},
138+
typeDefs,
139+
driver,
140+
resolvers,
141+
feature: {
142+
subscriptions: true,
143+
},
144+
});
145+
const ogm = new OGM({
146+
typeDefs,
147+
driver,
148+
features: {
149+
subscriptions: true
150+
},
142151
});
143-
const ogm = new OGM({ typeDefs, driver, plugins: { subscriptions: subscriptionsPlugin } });
144-
const Profile = ogm.model("Profile");
152+
const User = ogm.model("User");
145153
146154
async function main() {
147155
// initialize the OGM instance

modules/ROOT/pages/subscriptions/getting-started.adoc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This guide shows how to start using subscription capabilities on a GraphQL serve
99
If you use link:https://studio.apollographql.com/[Apollo Studio], make sure to select the link:https://www.npmjs.com/package/graphql-ws[graphql-ws] implementation in the connection settings.
1010
====
1111

12+
1213
== Enable subscription capabilities
1314

1415
Before using subscriptions on a GraphQL server, you must enable them by passing the `subscriptions` feature to `Neo4jGraphQL`:
@@ -24,6 +25,7 @@ new Neo4jGraphQL({
2425
});
2526
----
2627

28+
2729
== Install dependencies
2830

2931
Then, the next step is to install the following dependencies:
@@ -33,8 +35,8 @@ Then, the next step is to install the following dependencies:
3335
npm i --save ws graphql-ws neo4j-driver @neo4j/graphql express @apollo/server body-parser cors
3436
----
3537

36-
[setting-up-server]
37-
== Set up an `@apollo/server` server
38+
39+
== Setting up an `@apollo/server` server
3840

3941
Add the following code to your `index.js` file to implement a simple `@apollo/server` server with subscriptions (for more options, see link:https://www.apollographql.com/docs/apollo-server/data/subscriptions/[Apollo's documentation]):
4042

0 commit comments

Comments
 (0)