Skip to content

Commit 9602b83

Browse files
authored
Merge pull request #2944 from Liam-Doodson/make-relationship-properties-directive-mandatory
Make the `@relationshipProperties` directive mandatory
2 parents 9eb4ffc + d6acab2 commit 9602b83

File tree

137 files changed

+497
-356
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+497
-356
lines changed

.changeset/quick-insects-turn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@neo4j/graphql": major
3+
---
4+
5+
Made `@relationshipProperties` mandatory for relationship property interfaces

docs/modules/ROOT/pages/directives.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ Reference: xref::type-definitions/relationships.adoc[Relationships]
113113

114114
== `@relationshipProperties`
115115

116-
Optional syntactic sugar to help you distinguish between interfaces which are used for relationship properties, and otherwise.
116+
Required to help you distinguish between interfaces which are used for relationship properties, and otherwise.
117117

118118
Can only be used on interfaces, as per its definition:
119119

120120
[source, graphql, indent=0]
121121
----
122-
"""Syntactic sugar to help differentiate between interfaces for relationship properties, and otherwise."""
122+
"""Required to differentiate between interfaces for relationship properties, and otherwise."""
123123
directive @relationshipProperties on INTERFACE
124124
----
125125

docs/modules/ROOT/pages/filtering.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ type Person {
341341
name: String
342342
}
343343
344-
interface ActedIn {
344+
interface ActedIn @relationshipProperties {
345345
screenTime: Int
346346
}
347347
----

docs/modules/ROOT/pages/guides/v2-migration/mutations.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[[v2-migration-mutations]]
22
= Mutations
33

4-
The most broadly affected area of functionality by the 2.0.0 upgrade are the nested operations of Mutations, to faciliate the mutation of and filtering on relationship properties.
4+
The most broadly affected area of functionality by the 2.0.0 upgrade are the nested operations of Mutations, to facilitate the mutation of and filtering on relationship properties.
55

66
The examples in this section will be based off the following type definitions:
77

docs/modules/ROOT/pages/guides/v4-migration/index.adoc

Lines changed: 91 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,75 @@ const neoSchema = new Neo4jGraphQL({
130130
})
131131
----
132132

133+
==== `requires` changes
134+
135+
In version 4.0.0, it is now possible to require non-scalar fields. This means it is also possible to require fields on related type.
136+
To make this possible, the `requires` argument now accept a graphql selection set instead of a list of strings.
137+
138+
Therefore, the following type definitions:
139+
140+
[source, graphql, indent=0]
141+
----
142+
type User {
143+
firstName: String!
144+
lastName: String!
145+
fullName: String! @customResolver(requires: ["firstName", "lastName"])
146+
}
147+
----
148+
149+
Would need to be modified to use a selection set as below:
150+
151+
[source, graphql, indent=0]
152+
----
153+
type User {
154+
firstName: String!
155+
lastName: String!
156+
fullName: String! @customResolver(requires: "firstName lastName")
157+
}
158+
----
159+
160+
Below is a more advanced example showing what the selection set is capable of:
161+
162+
[source, graphql, indent=0]
163+
----
164+
interface Publication {
165+
publicationYear: Int!
166+
}
167+
168+
type Author {
169+
name: String!
170+
publications: [Publication!]! @relationship(type: "WROTE", direction: OUT)
171+
publicationsWithAuthor: [String!]!
172+
@customResolver(
173+
requires: "name publications { publicationYear ...on Book { title } ... on Journal { subject } }"
174+
)
175+
}
176+
177+
type Book implements Publication {
178+
title: String!
179+
publicationYear: Int!
180+
author: [Author!]! @relationship(type: "WROTE", direction: IN)
181+
}
182+
183+
type Journal implements Publication {
184+
subject: String!
185+
publicationYear: Int!
186+
author: [Author!]! @relationship(type: "WROTE", direction: IN)
187+
}
188+
----
189+
190+
Additionally, the requires argument also validates the required selection set against your type definitions.
191+
Therefore, as there is no field called `someFieldThatDoesNotExist`, an error would be thrown on startup if you tried to use the following type definitions:
192+
193+
[source, graphql, indent=0]
194+
----
195+
type User {
196+
firstName: String!
197+
lastName: String!
198+
fullName: String! @customResolver(requires: "firstName someFieldThatDoesNotExist")
199+
}
200+
----
201+
133202
[plural-migration]
134203
=== `plural` argument removed from `@node` and replaced with `@plural`
135204

@@ -406,76 +475,49 @@ type query {
406475

407476
Additionally, escaping strings is no longer needed.
408477

409-
=== `@customResolver` changes
478+
=== Mandatory `@relationshipProperties`
410479

411-
In version 4.0.0, it is now possible to require non-scalar fields. This means it is also possible to require fields on related type.
412-
To make this possible, the `requires` argument now accept a graphql selection set instead of a list of strings.
480+
Upcoming changes to interfaces require us to distinguish between interfaces that are used to specify relationship properties, and others. Therefore, the `@relationshipProperties` directive is now required on all relationship property interfaces.
481+
If it is not included, an error will be thrown.
413482

414-
Therefore, the following type definitions:
483+
As a result, in version 4.0.0, the following type definitions are invalid:
415484

416485
[source, graphql, indent=0]
417486
----
418-
type User {
419-
firstName: String!
420-
lastName: String!
421-
fullName: String! @customResolver(requires: ["firstName", "lastName"])
487+
type Person {
488+
name: String!
489+
movies: [Movie!]! @relationship(type: "ACTED_IN", direction: OUT, properties: "ActedIn")
422490
}
423-
----
424491
425-
Would need to be modified to use a selection set as below:
492+
type Movie {
493+
title: String!
494+
actors: [Person!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
495+
}
426496
427-
[source, graphql, indent=0]
428-
----
429-
type User {
430-
firstName: String!
431-
lastName: String!
432-
fullName: String! @customResolver(requires: "firstName lastName")
497+
interface ActedIn {
498+
screenTime: Int!
433499
}
434500
----
435501

436-
Below is a more advanced example showing what the selection set is capable of:
502+
Instead, they would need to be updated as below:
437503

438504
[source, graphql, indent=0]
439505
----
440-
interface Publication {
441-
publicationYear: Int!
506+
type Person {
507+
name: String!
508+
movies: [Movie!]! @relationship(type: "ACTED_IN", direction: OUT, properties: "ActedIn")
442509
}
443510
444-
type Author {
445-
name: String!
446-
publications: [Publication!]! @relationship(type: "WROTE", direction: OUT)
447-
publicationsWithAuthor: [String!]!
448-
@customResolver(
449-
requires: "name publications { publicationYear ...on Book { title } ... on Journal { subject } }"
450-
)
451-
}
452-
453-
type Book implements Publication {
454-
title: String!
455-
publicationYear: Int!
456-
author: [Author!]! @relationship(type: "WROTE", direction: IN)
457-
}
458-
459-
type Journal implements Publication {
460-
subject: String!
461-
publicationYear: Int!
462-
author: [Author!]! @relationship(type: "WROTE", direction: IN)
511+
type Movie {
512+
title: String!
513+
actors: [Person!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
463514
}
464-
----
465-
466-
Additionally, the requires argument also validates the required selection set against your type definitions.
467-
Therefore, as there is no field called `someFieldThatDoesNotExist`, an error would be thrown on startup if you tried to use the following type definitions:
468515
469-
[source, graphql, indent=0]
470-
----
471-
type User {
472-
firstName: String!
473-
lastName: String!
474-
fullName: String! @customResolver(requires: "firstName someFieldThatDoesNotExist")
516+
interface ActedIn @relationshipProperties {
517+
screenTime: Int!
475518
}
476519
----
477520

478-
479521
== Miscellaneous changes
480522

481523
[[startup-validation]]

docs/modules/ROOT/pages/queries.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type User {
2424
friends: [User!]! @relationship(type: "FRIENDS_WITH", direction: OUT)
2525
}
2626
27-
interface PostedAt {
27+
interface PostedAt @relationshipProperties {
2828
date: DateTime
2929
}
3030
----

docs/modules/ROOT/pages/subscriptions/events/create_relationship.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ type Influencer implements Reviewer {
226226
reputation: Int!
227227
}
228228

229-
interface Review {
229+
interface Review @relationshipProperties {
230230
score: Int!
231231
}
232232
```

docs/modules/ROOT/pages/subscriptions/events/delete_relationship.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ type Influencer implements Reviewer {
226226
reputation: Int!
227227
}
228228

229-
interface Review {
229+
interface Review @relationshipProperties {
230230
score: Int!
231231
}
232232
```

docs/modules/ROOT/pages/subscriptions/filtering.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ type Magazine implements Reviewer {
335335
reputation: Int!
336336
}
337337
338-
interface Review {
338+
interface Review @relationshipProperties {
339339
score: Int!
340340
}
341341
----

docs/modules/ROOT/pages/type-definitions/basics.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ Note there is a directive on each "end" of the relationship in this case, but it
3939

4040
=== Relationship properties
4141

42-
In order to add relationship properties to a relationship, you need to add a new type to your type definitions, but this time it will be of type `interface`. For example, for your "ACTED_IN" relationship, add a property "roles":
42+
In order to add relationship properties to a relationship, you need to add a new type to your type definitions, but this time it will be of type `interface`. This interface must be decorated with the `@relationshipProperties` directive.
43+
For example, for your "ACTED_IN" relationship, add a property "roles":
4344

4445
[source, graphql, indent=0]
4546
----

0 commit comments

Comments
 (0)