Skip to content

Commit 298613a

Browse files
Subscriptions section review (#16)
* first draft * update * update * update * fix conflict * final additions * fixes * first draft * update * update * final additions * fixing conflicts * fixing conflicts * Apply suggestions from code review Co-authored-by: angrykoala <[email protected]> --------- Co-authored-by: angrykoala <[email protected]>
1 parent 5e9ea87 commit 298613a

File tree

13 files changed

+650
-341
lines changed

13 files changed

+650
-341
lines changed

modules/ROOT/content-nav.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
*** xref:mutations/delete.adoc[]
4141
4242
** xref:subscriptions/index.adoc[]
43-
*** xref:subscriptions/getting-started.adoc[Getting Started]
43+
*** xref:subscriptions/getting-started.adoc[Getting started]
4444
*** xref:subscriptions/events.adoc[Events]
4545
*** xref:subscriptions/filtering.adoc[]
4646
*** xref:subscriptions/scaling.adoc[]
47-
*** xref:subscriptions/engines.adoc[Subscriptions Engines]
47+
*** xref:subscriptions/engines.adoc[Engines]
4848

4949
** xref:custom-resolvers.adoc[]
5050

-139 KB
Binary file not shown.

modules/ROOT/images/subscriptions/diagram1.svg

Lines changed: 50 additions & 0 deletions
Loading
-152 KB
Binary file not shown.

modules/ROOT/images/subscriptions/diagram2.svg

Lines changed: 50 additions & 0 deletions
Loading
-239 KB
Binary file not shown.

modules/ROOT/images/subscriptions/diagram3.svg

Lines changed: 79 additions & 0 deletions
Loading

modules/ROOT/pages/subscriptions/engines.adoc

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
[[subscription-engines]]
2-
= Engines
3-
4-
There are different ways to how a GraphQL subscription may be set along with `@neo4j/graphql` server.
2+
:description: This page describes how a GraphQL subscription may be set along with a @neo4j/graphql server.
3+
= Subscription engines
54

5+
This page describes different ways to set up a GraphQL subscription along with a `@neo4j/graphql` server.
66

77
== Default
8+
89
The default behavior is automatically set if the `subscriptions` feature is set to `true`, as described in xref::subscriptions/getting-started.adoc[Getting Started]:
910

10-
[source, javascript]
11+
[source, javascript, indent=0]
1112
----
1213
new Neo4jGraphQL({
1314
typeDefs,
@@ -18,11 +19,13 @@ new Neo4jGraphQL({
1819
});
1920
----
2021

21-
This behavior enables a simple subscription system that will work on a single instance, which is ideal for development, testing, and servers that do not require horizontal scaling.
22+
This behavior enables a simple subscription system that works on a single instance.
23+
It is ideal for development, testing, and servers that do not require horizontal scaling.
2224

2325
[[amqp]]
2426
== AMQP
25-
Using subscriptions on a server with multiple instances can be tricky, as described in xref::subscriptions/scaling.adoc[Horizontal Scaling].
27+
28+
Using subscriptions on a server with multiple instances can be complex, as described in xref::subscriptions/scaling.adoc[Horizontal scaling].
2629
Therefore, the recommended approach is to use a PubSub system, which can be achieved with an AMQP broker such as link:https://www.rabbitmq.com/[RabbitMQ].
2730
This is supported by the link:https://www.npmjs.com/package/@neo4j/graphql-amqp-subscriptions-engine[@neo4j/graphql-amqp-subscriptions-engine] package.
2831

@@ -36,19 +39,22 @@ Some brokers supporting this protocol are:
3639

3740
The plugin can be installed with `npm`:
3841

39-
[source, bash]
42+
[source, sh, indent=0]
4043
----
4144
npm install @neo4j/graphql-amqp-subscriptions-engine
4245
----
4346

44-
NOTE: AMQP 1.0 is **not** supported by this plugin.
47+
[NOTE]
48+
====
49+
AMQP 1.0 is **not** supported by this plugin.
50+
====
4551

4652
=== Usage
4753

4854
The AMQP plugin should be instanced and passed to the `subscription` field in features.
49-
This will automatically enable the subscriptions with the AMQP broker as a message queue:
55+
This automatically enables the subscriptions with the AMQP broker as a message queue:
5056

51-
[source, javascript]
57+
[souce, javascript, indent=0]
5258
----
5359
const { Neo4jGraphQLAMQPSubscriptionsEngine } = require("@neo4j/graphql-amqp-subscriptions-engine");
5460
@@ -72,33 +78,37 @@ const neoSchema = new Neo4jGraphQL({
7278
=== API
7379
The following options can be passed to the constructor:
7480

75-
* **connection**: An AMQP uri as a string or a configuration object.
76-
** **hostname**: Hostname to be used, defaults to `localhost`.
81+
* **connection**: an AMQP uri as a string or a configuration object.
82+
** **hostname**: hostname to be used.
83+
Defaults to `localhost`.
7784
** **username**: defaults to `guest`.
7885
** **password**: defaults to `guest`.
79-
** **port**: Port of the AMQP broker, defaults to `5672`.
80-
* **exchange**: The exchange to be used in the broker. Defaults to `neo4j.graphql.subscriptions.fx`.
81-
* **version**: The AMQP version to be used. Currently only `0-9-1` is supported.
86+
** **port**: port of the AMQP broker.
87+
Defaults to `5672`.
88+
* **exchange**: the exchange to be used in the broker.
89+
Defaults to `neo4j.graphql.subscriptions.fx`.
90+
* **version**: the AMQP version to be used.
91+
Currently only `0-9-1` is supported.
8292

8393
Additionally, any option supported by link:https://www.npmjs.com/package/amqplib[amqplib] can be passed to `connection`.
84-
85-
==== Methods
94+
To set these configurations up, use the following method:
8695

8796
* **close(): Promise<void>**: Closes the connection and channel created, and unbinds the event emitter.
8897

8998
[[custom-subscription]]
90-
== Custom Subscription Engine
99+
== Custom subscription engine
100+
91101
If none of the existing engines is valid for your use case, you can create a new engine to connect to any broker you may need.
92102
For that, you need to create a new class defining your messaging behavior and it must contain:
93103

94104
* An `EventEmitter` property called `events` that should emit an event every time the broker sends a message.
95-
* A `publish` method that will publish a new event to the broker.
96-
* Optionally, an `init` method returning a promise that will be called on `getSchema`.
105+
* A `publish` method that should publish a new event to the broker.
106+
* Optionally, an `init` method returning a promise that should be called on `getSchema`.
97107
This is useful for setting up the connection to a broker.
98108

99109
In case you want to handle subscriptions using link:https://redis.io/[redis]:
100110

101-
[source, javascript]
111+
[souce, javascript, indent=0]
102112
----
103113
// Note: This is an example of a custom subscription behavior and not a production ready redis implementation.
104114
class CustomRedisSubscriptionEngine {
@@ -139,9 +149,10 @@ const neoSchema = new Neo4jGraphQL({
139149
----
140150

141151
Note that extra properties and methods are often needed to handle the connection to the broker.
142-
As long as the messages are sent to the broker in the `publish` method and that these messages are received and then emitted through the `events` property, the subscriptions will be properly handled.
152+
However, as long as the messages are sent to the broker in the `publish` method and that these messages are received and then emitted through the `events` property, the subscriptions are properly handled.
143153

144154
=== Using Typescript
155+
145156
If using Typescript, you may import the interface `Neo4jGraphQLSubscriptionsEngine` to implement your own class.
146157
Ensure the API is correctly defined:
147158

@@ -152,6 +163,7 @@ class CustomRedisEngine implements Neo4jGraphQLSubscriptionsEngine {}
152163

153164
[NOTE]
154165
====
155-
Events are sent to the class in order, however, order is not guaranteed once these events have been broadcasted through a broker.
166+
Events are sent in order to the class.
167+
However, order is not guaranteed once these events have been broadcasted through a broker.
156168
For cases when ordering is important, you must set up the field `timestamp` in the subscriptions payload.
157169
====

0 commit comments

Comments
 (0)