Skip to content

Commit 85934ff

Browse files
apply v7 migration on types folder
1 parent 22c2eaf commit 85934ff

File tree

4 files changed

+86
-75
lines changed

4 files changed

+86
-75
lines changed

modules/ROOT/pages/types/interfaces.adoc

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type Series implements Production @node {
3131
}
3232
3333
type ActedIn @relationshipProperties {
34-
role: String!
34+
role: String
3535
}
3636
3737
type Actor @node {
@@ -52,7 +52,7 @@ The following will return all productions with title starting "The " for every a
5252
query GetProductionsStartingWithThe {
5353
actors {
5454
name
55-
actedIn(where: { node: { title_STARTS_WITH: "The " } }) {
55+
actedIn(where: { node: { title: { startsWith: "The " } } }) {
5656
title
5757
... on Movie {
5858
runtime
@@ -65,14 +65,14 @@ query GetProductionsStartingWithThe {
6565
}
6666
----
6767

68-
The following query will only return the movies with title starting with "The " for each actor by filtering them by `typename_IN`:
68+
The following query will only return the movies with title starting with "The " for each actor by filtering them by `typename`:
6969

7070
[source, graphql, indent=0]
7171
----
7272
query GetMoviesStartingWithThe {
7373
actors {
7474
name
75-
actedIn(where: { node: { title_STARTS_WITH: "The ", typename_IN: [Movie] } }) {
75+
actedIn(where: { node: { title: { startsWith: "The " }, typename: [Movie] } }) {
7676
title
7777
... on Movie {
7878
runtime
@@ -151,22 +151,26 @@ Take the following example:
151151
[source, graphql, indent=0]
152152
----
153153
mutation CreateActorAndProductions {
154-
updateActors(
155-
where: { name_EQ: "Woody Harrelson" }
154+
updateActors(
155+
where: { name: { eq: "Woody Harrelson" } }
156+
update: {
157+
actedIn: {
156158
connect: {
157-
actedIn: {
158-
where: { node: { title_EQ: "Zombieland" } }
159-
connect: { actors: { where: { node: { name_EQ: "Emma Stone" } } } }
160-
}
161-
}
162-
) {
163-
actors {
164-
name
165-
actedIn {
166-
title
167-
}
159+
where: { node: { title: { eq: "Zombieland" } } }
160+
connect: {
161+
actors: { where: { node: { name: { eq: "Emma Stone" } } } }
162+
}
168163
}
164+
}
165+
}
166+
) {
167+
actors {
168+
name
169+
actedIn {
170+
title
171+
}
169172
}
173+
}
170174
}
171175
----
172176

@@ -185,17 +189,17 @@ For example, the following query returns all productions (`movies` and `series`)
185189
[source, graphql, indent=0]
186190
----
187191
query GetProductionsStartingWithThe {
188-
actors {
189-
name
190-
actedIn(where: { node: { title_STARTS_WITH: "The " } }) {
191-
title
192-
... on Movie {
193-
runtime
194-
}
195-
... on Series {
196-
episodes
197-
}
198-
}
192+
actors {
193+
name
194+
actedIn(where: { title: { startsWith: "The " } }) {
195+
title
196+
... on Movie {
197+
runtime
198+
}
199+
... on Series {
200+
episodes
201+
}
199202
}
203+
}
200204
}
201205
----

modules/ROOT/pages/types/relationships.adoc

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,23 @@ type Movie @node {
4545
title: String!
4646
released: Int!
4747
actors: [Person!]! @relationship(type: "ACTED_IN", direction: IN)
48-
director: Person! @relationship(type: "DIRECTED", direction: IN)
48+
directors: [Person!]! @relationship(type: "DIRECTED", direction: IN)
4949
}
5050
----
5151

5252
Note that, in this query:
5353

5454
* A `Person` can _act in_ or _direct_ multiple movies, and a `Movie` can have multiple actors.
55-
However, it is rare for a `Movie` to have more than one director, so you can model this cardinality in your type definitions, to ensure accuracy of your data.
56-
* A `Movie` isn't really a `Movie` without a director, and this has been signified by marking the `director` field as non-nullable.
57-
This means that a `Movie` *must* have a `DIRECTED` relationship coming into it to be valid.
55+
While it is rare for a `Movie` to have more than one director, Neo4j GraphQL Library requires all relationships to be modeled as "many" relationships (using arrays).
56+
* Even conceptually one-to-one relationships like a movie having a single director must be represented as arrays (e.g., `directors: [Person!]!`) because Neo4j cannot reliably enforce 1:1 cardinality between nodes.
5857
* To figure out whether the `direction` argument of the `@relationship` directive should be `IN` or `OUT`, visualize your relationships like in the diagram above, then model out the direction of the arrows.
5958
* The `@relationship` directive is a reference to Neo4j relationships, whereas in the schema, the phrase `edge(s)` is used to be consistent with the general API language used by Relay.
6059

60+
=== Neo4j GraphQL Cardinality Limitation
61+
62+
It's important to understand that Neo4j cannot reliably enforce 1:1 cardinality between nodes in a graph database. Therefore, all relationships in Neo4j GraphQL are modeled as "many" relationships (using arrays) even when conceptually they represent one-to-one relationships.
63+
As alternative you can define your relationship with the `@cypher` directive, however some of the functionality provided by the Neo4j GraphQL Library will not be available.
64+
6165
=== Relationship properties
6266

6367
You can add relationship properties to the example in two steps:
@@ -83,7 +87,7 @@ type Movie @node {
8387
title: String!
8488
released: Int!
8589
actors: [Person!]! @relationship(type: "ACTED_IN", properties: "ActedIn", direction: IN)
86-
director: Person! @relationship(type: "DIRECTED", direction: IN)
90+
directors: [Person!]! @relationship(type: "DIRECTED", direction: IN)
8791
}
8892
8993
type ActedIn @relationshipProperties {
@@ -142,7 +146,6 @@ type Person @node {
142146
----
143147

144148
`queryDirection` can have the following values:
145-
146149
* `DIRECTED`: only directed queries can be performed on this relationship.
147150
* `UNDIRECTED`: only undirected queries can be performed on this relationship.
148151

@@ -160,20 +163,20 @@ mutation CreateMovieAndDirector {
160163
{
161164
title: "Forrest Gump"
162165
released: 1994
163-
director: {
164-
create: {
166+
directors: {
167+
create: [{
165168
node: {
166169
name: "Robert Zemeckis"
167170
born: 1951
168171
}
169-
}
172+
}]
170173
}
171174
}
172175
]) {
173176
movies {
174177
title
175178
released
176-
director {
179+
directors {
177180
name
178181
born
179182
}
@@ -187,40 +190,40 @@ You then need to create the actor in this example, and connect them to the new `
187190
[source, graphql, indent=0]
188191
----
189192
mutation CreateActor {
190-
createPeople(input: [
191-
{
192-
name: "Tom Hanks"
193-
born: 1956
194-
actedInMovies: {
195-
connect: {
196-
where: {
197-
node: { title_EQ: "Forrest Gump" }
198-
}
199-
edge: {
200-
roles: ["Forrest"]
201-
}
202-
}
203-
}
193+
createPeople(
194+
input: [
195+
{
196+
name: "Tom Hanks"
197+
born: 1956
198+
actedInMovies: {
199+
connect: {
200+
where: { node: { title: { eq: "Forrest Gump" } } }
201+
edge: { roles: ["Forrest"] }
202+
}
204203
}
205-
]) {
206-
movies {
207-
title
208-
released
209-
director {
210-
name
211-
born
204+
}
205+
]
206+
) {
207+
people {
208+
name
209+
born
210+
actedInMovies {
211+
title
212+
released
213+
actorsConnection {
214+
edges {
215+
properties {
216+
roles
212217
}
213-
actorsConnection {
214-
edges {
215-
roles
216-
node {
217-
name
218-
born
219-
}
220-
}
218+
node {
219+
name
220+
born
221221
}
222+
}
222223
}
224+
}
223225
}
226+
}
224227
}
225228
----
226229

@@ -236,7 +239,7 @@ mutation CreateMovieDirectorAndActor {
236239
{
237240
title: "Forrest Gump"
238241
released: 1994
239-
director: {
242+
directors: {
240243
create: {
241244
node: {
242245
name: "Robert Zemeckis"
@@ -262,13 +265,15 @@ mutation CreateMovieDirectorAndActor {
262265
movies {
263266
title
264267
released
265-
director {
268+
directors {
266269
name
267270
born
268271
}
269272
actorsConnection {
270273
edges {
271-
roles
274+
properties {
275+
roles
276+
}
272277
node {
273278
name
274279
born
@@ -289,16 +294,18 @@ Now that you have the `Movie` information in your database, you can query everyt
289294
[source, graphql, indent=0]
290295
----
291296
query {
292-
movies(where: { title_EQ: "Forrest Gump" }) {
297+
movies(where: { title: { eq: "Forrest Gump" } }) {
293298
title
294299
released
295-
director {
300+
directors {
296301
name
297302
born
298303
}
299304
actorsConnection {
300305
edges {
301-
roles
306+
properties {
307+
roles
308+
}
302309
node {
303310
name
304311
born

modules/ROOT/pages/types/scalar.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ a|
3838
[source, graphql, indent=0]
3939
----
4040
query {
41-
files(where: { size_EQ: 9223372036854775807 }) {
41+
files(where: { size: { eq: 9223372036854775807 }}) {
4242
size
4343
}
4444
}

modules/ROOT/pages/types/unions.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ While this particular query only returns blogs, you could for instance use a fil
9696
query GetUsersWithAllContent {
9797
users {
9898
name
99-
content(where: { Blog: { NOT: { title_EQ: null } }}) {
99+
content(where: { Blog: { NOT: { title: { eq: null } } }}) {
100100
... on Blog {
101101
title
102102
}

0 commit comments

Comments
 (0)