Skip to content

Commit 4ff550b

Browse files
authored
Mutations review (#14)
* Mutations review * final additions * removing pages from content nav * changing formatting * update * note on optimization * fixing conflicts * fixing conflicts * update after review * update after review
1 parent b6654fd commit 4ff550b

File tree

5 files changed

+224
-191
lines changed

5 files changed

+224
-191
lines changed

modules/ROOT/pages/mutations/create.adoc

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[[mutations-create]]
2-
= Create
2+
:description: This page describes how to create nodes through mutations.
3+
= `create`
34

4-
Using the following type definitions for these examples:
5+
Using the following type definitions:
56

67
[source, graphql, indent=0]
78
----
@@ -18,7 +19,7 @@ type User {
1819
}
1920
----
2021

21-
The following create mutations and response types will be generated for the above type definitions:
22+
These `create` mutations and response types should be generated:
2223

2324
[source, graphql, indent=0]
2425
----
@@ -36,13 +37,17 @@ type Mutation {
3637
}
3738
----
3839

39-
The `CreateInput` types closely mirror the object type definitions, allowing you to create not only the type in question, but to recurse down and perform further operations on related types in the same Mutation.
40+
Note that the `CreateInput` types closely mirror the object type definitions.
41+
This allows you to create not only the type in question, but to recurse down and perform further operations on related types in the same mutation.
4042

41-
> The `id` field will be absent from both create input types as the xref::reference/directives/autogeneration.adoc#type-definitions-autogeneration-id[`@id`] directive has been used.
43+
[NOTE]
44+
====
45+
The `id` field is absent from both `create` input types as the xref::reference/directives/autogeneration.adoc#type-definitions-autogeneration-id[`@id`] directive has been used.
46+
====
4247

43-
== Single create
48+
== Single `create`
4449

45-
A single user can be created by executing the following GraphQL statement:
50+
A single `User` can be created by executing the following GraphQL statement:
4651

4752
[source, graphql, indent=0]
4853
----
@@ -60,11 +65,11 @@ mutation {
6065
}
6166
----
6267

63-
This will create a User with name "John Doe", and that name plus the autogenerated ID will be returned.
68+
This should create a `User` with name "John Doe", and that name plus the autogenerated ID should be returned.
6469

65-
== Nested create
70+
== Nested `create`
6671

67-
A User and an initial Post can be created by executing the following:
72+
A `User` and an initial `Post` can be created by executing the following:
6873

6974
[source, graphql, indent=0]
7075
----
@@ -95,10 +100,19 @@ mutation {
95100
}
96101
----
97102

98-
This will create a User with name "John Doe", an introductory Post, both of which will be returned with their autogenerated IDs.
103+
This creates a `User` with name "John Doe" and an introductory post.
104+
Both should be returned with their autogenerated IDs.
105+
106+
[NOTE]
107+
====
108+
You can perform similar and complementary actions by using the `update` mutation combined with `create`.
109+
Read about xref:mutations/update.adoc#_connectorcreate_relationships[`update`] for more information.
110+
====
99111

100112
== `connectOrCreate` relationships
101-
If a related node has a `@unique` or `@id` directive defined, `connectOrCreate` can be used in a nested create to perform a `MERGE` operation on the related node, creating a new relationship and the related node if it doesn't exist.
113+
114+
If a related node has a `@unique` or `@id` directive defined, `connectOrCreate` can be used in a nested `create` to perform a `MERGE` operation on the related node.
115+
This should create a new relationship and the related node if it doesn't exist yet.
102116

103117
Consider the following type definitions:
104118

@@ -116,7 +130,8 @@ type Movie {
116130
}
117131
----
118132

119-
Because a movie ID is unique, `connectOrCreate` can be used in an Actor mutation to ensure a movie exists before connecting. Note that only `@unique` or `@id` fields can be used in `where`:
133+
Because a movie ID is unique, `connectOrCreate` can be used in an `Actor` mutation to ensure the movie exists in the database before connecting.
134+
Note that only `@unique` or `@id` fields can be used in `where`:
120135

121136
[source, graphql, indent=0]
122137
----
@@ -139,22 +154,13 @@ mutation {
139154

140155
This will ensure that a movie with ID 1234 exists and it is connected to `"Tom Hanks"`. If the movie does not exist, it will be created with the title `"Forrest Gump"`. Note that if the movie with the given ID already exists, it will be connected to it, regardless of the title.
141156

142-
[[optimizing-create-operations]]
143-
== Optimizing create operations
144-
145-
It's possible to use the Neo4jGraphQL library to create several nodes and relationships in a single mutation, however,
146-
it's well known that performance issues are present in performing this task.
147-
A solution has been implemented that doesn't require any changes from the user.
148-
However, there are still several situations where this kind of optimization is not achievable.
149-
150-
=== Subscriptions enabled
151-
152-
No optimizations are available if a Subscription plugin it's being used.
153-
154-
=== `@populated_by`
157+
== `CREATE` optimization
155158

156-
No optimizations are available if a Node affected by the mutation has a field with the directive `@populated_by`.
159+
With the `create` operations, there is no limit on how many nodes can be created at once.
160+
However, there is a known performance issue for large batch sizes.
157161

158-
=== `connect` and `connectOrCreate` operations
162+
The Neo4j GraphQL Library contains an optimization feature designed to mitigate it, but it does not work in the following scenarios:
159163

160-
No optimizations are available if the GraphQL input contains the `connect` or `connectOrCreate` operation.
164+
* A field is populated using the directive `@populated_by`.
165+
* The `connect` or `connectOrCreate` operation is used.
166+
* Interface and union types are present in the mutation.

modules/ROOT/pages/mutations/delete.adoc

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[[mutations-delete]]
2-
= Delete
2+
:description: This page describes how to delete nodes using mutations.
3+
= `delete`
34

4-
Using the following type definitions for these examples:
5+
Using these type definitions:
56

67
[source, graphql, indent=0]
78
----
@@ -18,7 +19,7 @@ type User {
1819
}
1920
----
2021

21-
The following delete mutations and response type will be generated for the above type definitions:
22+
These `delete` mutations and response types should be generated:
2223

2324
[source, graphql, indent=0]
2425
----
@@ -33,9 +34,12 @@ type Mutation {
3334
}
3435
----
3536

36-
Note that the `DeleteInfo` type is the common return type for all delete mutations.
37+
[NOTE]
38+
====
39+
The `DeleteInfo` type is the common return type for all delete mutations.
40+
====
3741

38-
== Single Delete
42+
== Single `delete`
3943

4044
A single post can be deleted by executing the following GraphQL statement:
4145

@@ -51,34 +55,25 @@ mutation {
5155
}
5256
----
5357

54-
This will delete the post using the autogenerated ID that would have been returned after that post's creation.
58+
This should delete the post using the autogenerated ID that was returned after that post's creation.
59+
Consequently, `nodesDeleted` should be equal `1` (the post) and `relationshipsDeleted` should also equal `1` as the `HAS_POST` relationship between the `Post` and its author was deleted.
5560

56-
`nodesDeleted` would equal 1 (the post) and `relationshipsDeleted` would also equal equal 1 (the `HAS_POST` relationship between the Post and its author).
61+
== Nested `delete`
5762

58-
== Nested Delete
59-
60-
Say that if when you delete a User, you want to delete _all_ of their Posts as well. This can be achieved using a single nested delete operations:
63+
In case you want to delete a `User` *and* all of their posts, you can use a single nested `delete` mutation:
6164

6265
[source, graphql, indent=0]
6366
----
6467
mutation {
65-
deleteUsers(
66-
where: {
67-
name: "Jane Doe"
68-
},
69-
delete: {
70-
posts: [
71-
where: { }
72-
]
73-
}
74-
) {
75-
nodesDeleted
76-
relationshipsDeleted
77-
}
68+
deleteUsers(where: { name: "Jane Doe" }, delete: { posts: {} }) {
69+
nodesDeleted
70+
relationshipsDeleted
71+
}
7872
}
7973
----
8074

81-
You may look at that empty `where` argument and wonder what that's doing. By the time the traversal has reached that argument, it has the context of only posts that were created by Jane Doe, as the traversals to those Post nodes were from her User node. Essentially, the above query is equivalent to:
75+
By the time the traversal has reached it, that empty `where` argument has the context of only refer to posts that were created by Jane Doe, as the traversals to those `Post` nodes were from her `User` node.
76+
Essentially, the above query is equivalent to:
8277

8378
[source, graphql, indent=0]
8479
----
@@ -105,4 +100,12 @@ mutation {
105100
}
106101
----
107102

108-
Slightly easier to reason with, but the output Cypher statement will have a redundant `WHERE` clause!
103+
Note that the output Cypher statement should also have a redundant `WHERE` clause:
104+
105+
//Please add the cypher statement:
106+
107+
//[source, cypher, indent=0]
108+
//----
109+
//DELETE User (name:"Jane Doe")
110+
//WHERE Posts -
111+
//----
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
[[mutations]]
2+
:description: This section describes how to use mutations with the Neo4j GraphQL Library.
23
= Mutations
34

4-
Several mutations are automatically generated for each type defined in type definitions, which are covered in the following chapters:
5+
This section addresses basic examples of the following mutations:
56

6-
- xref::mutations/create.adoc[Create] - create nodes, and recursively create or connect further nodes in the graph
7-
- xref::mutations/update.adoc[Update] - update nodes, and recursively perform any operations from there
8-
- xref::mutations/delete.adoc[Delete] - delete nodes, and recursively delete or disconnect further nodes in the graph
7+
- xref::mutations/create.adoc[`create`] - create nodes, and recursively create or connect further nodes in the graph.
8+
- xref::mutations/update.adoc[`update`] - update nodes, and recursively perform any operations from there.
9+
- xref::mutations/delete.adoc[`delete`] - delete nodes, and recursively delete or disconnect further nodes in the graph.
910
10-
== A note on nested mutations
11-
12-
You will see some basic examples of nested mutations in this chapter, which barely scratch the surface of what can be achieved with them. It's encouraged to explore the power of what you can do with them!
13-
14-
However, it has to be noted that in order to provide the abstractions available in these mutations, the output Cypher can end up being extremely complex, which can result in your database throwing out-of-memory errors depending on its configuration.
15-
16-
If out-of-memory errors are a regular occurrence, you can adjust the `dbms.memory.heap.max_size` parameter in the DBMS settings.
11+
[NOTE]
12+
====
13+
In order to provide the abstractions available in these mutations, the output Cypher can end up being complex.
14+
This can result in your database throwing out-of-memory errors depending on its configuration.
1715
16+
If this becomes a regular occurrence, you can adjust the link:https://neo4j.com/docs/operations-manual/current/configuration/configuration-settings/#config_server.memory.heap.max_size[`server.memory.heap.max_size`] parameter in the DBMS settings.
1817
If you need to perform major data migrations, it may be best to manually write the necessary Cypher and execute this directly in the database.
18+
====

0 commit comments

Comments
 (0)