Skip to content

Commit 15ef1ae

Browse files
committed
attempt at unifying directive presentation
1 parent c5b7617 commit 15ef1ae

File tree

11 files changed

+225
-130
lines changed

11 files changed

+225
-130
lines changed

modules/ROOT/pages/directives/custom-logic.adoc

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
The `@cypher` directive binds a GraphQL field to the results of a Cypher query.
88
This directive can be used both for properties in a type or as top level queries.
99

10-
=== Global variables
10+
=== Definition
11+
12+
==== Global variables
1113

1214
Global variables are available for use within the Cypher statement, and can be applied to the `@cypher` directive.
1315

@@ -90,14 +92,14 @@ type Query {
9092
|===
9193

9294

93-
=== Return values
95+
==== Return values
9496

9597
The return value of Cypher statements must always be of the same type to which the directive is applied.
9698

9799
The variable must also be aliased with a name that is the same as the one passed to `columnName`.
98100
This can be the name of a node, relationship query, or an alias in the `RETURN` statement of the Cypher statement.
99101

100-
==== Scalar values
102+
===== Scalar values
101103

102104
Cypher statements must return a value which matches the scalar type to which the directive was applied.
103105
For example:
@@ -109,7 +111,7 @@ type Query {
109111
}
110112
----
111113

112-
==== Object types
114+
===== Object types
113115

114116
When returning an object type, all fields of the type must be available in the Cypher return value.
115117
This can be achieved by either returning the entire object from the Cypher query, or returning a map of the fields which are required for the object type.
@@ -152,7 +154,7 @@ type Query {
152154
The downside of the latter approach is that you need to adjust the return object as you change your object type definition.
153155

154156

155-
=== Input arguments
157+
==== Input arguments
156158

157159
The `@cypher` statement can access the query parameters by prepending `$` to the parameter name.
158160
For example:
@@ -174,7 +176,7 @@ query {
174176
----
175177

176178

177-
=== Usage examples
179+
=== Usage
178180

179181
The `@cypher` directive can be used in different contexts, such as the ones described in this section.
180182

@@ -383,7 +385,11 @@ directive @customResolver(
383385
) on FIELD_DEFINITION
384386
----
385387

386-
=== The `requires` argument
388+
=== Usage
389+
390+
// tba - an example without requires argument (?)
391+
392+
==== The `requires` argument
387393

388394
The `requires` argument can be used:
389395

modules/ROOT/pages/directives/database-mapping.adoc

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ Each type in your GraphQL type definitions can be mapped to an entity in your Ne
1010

1111
== `@relationship`
1212

13+
=== Definition
14+
15+
// tba
16+
17+
=== Usage
18+
1319
Relationships are represented by marking particular fields with a directive -- in this case, `@relationship`.
1420
It defines the relationship type in the database, as well as which direction that relationship goes in.
1521

16-
To add a second node type, "Actor", and connect the two together, you should do the following:
22+
To add two node types, "Movie" and "Actor", and connect the two:
1723

1824
[source, graphql, indent=0]
1925
----
@@ -28,8 +34,14 @@ type Actor {
2834
}
2935
----
3036

31-
Note that, in this case, there is a directive on each "end" of the relationship, but it is not essential.
37+
[NOTE]
38+
====
39+
The `@relationship` directive is used twice, once on each end of the relationship.
40+
This is the standard way of modeling a relationship with the GraphQL library.
41+
However, it is not a requirement of the type definitions themselves and relationships can deliberately be underspecified, for example to limit access through the API layer.
42+
====
3243

44+
Also see xref::/directives/schema-configuration/field-configuration/#_relationship[`@relationship` field configuration].
3345

3446
== `@relationshipProperties`
3547

@@ -70,9 +82,14 @@ Note that in addition to this type, there is an added key `properties` in the ex
7082
For more information, see xref::/types/relationships.adoc[Type definitions -> Relationships].
7183

7284

73-
[[type-definitions-node]]
7485
== `@node`
7586

87+
=== Definition
88+
89+
// tba
90+
91+
=== Usage
92+
7693
The most basic mapping uses GraphQL type names to map to a Neo4j node label.
7794
For example, to represent a node with the label "Movie" and a single property "title" of type string:
7895

@@ -84,13 +101,15 @@ type Movie {
84101
----
85102

86103
With the `@node` directive, you have more control over this mapping, and you can specify the configuration of a GraphQL object type which represents a Neo4j node.
87-
It can be appended with the following optional parameters:
88104

105+
==== The `labels` parameter
89106

90-
[discrete]
91-
=== `labels`
107+
You can append the optional parameters `labels` to a GraphQL object with the `@node` directive.
108+
This parameter lists the labels to be used in Neo4j instead of the GraphQL type name.
92109

93-
This parameter defines the list of label to be used in Neo4j instead of the GraphQL type name:
110+
.Querying a field with the `labels` parameter
111+
====
112+
Consider the following type definition:
94113
95114
[source, graphql, indent=0]
96115
----
@@ -99,7 +118,7 @@ type Dog @node(labels: ["K9"]) {
99118
}
100119
----
101120
102-
This way, the following query:
121+
Here is a query against the `Dog` node:
103122
104123
[source, graphql, indent=0]
105124
----
@@ -110,15 +129,20 @@ This way, the following query:
110129
}
111130
----
112131
113-
Generates the Cypher query:
132+
The following Cypher is generated:
114133
115134
[source, cypher, indent=0]
116135
----
117136
MATCH (this: K9)
118137
RETURN this { .name } as name
119138
----
139+
====
120140

121-
If the GraphQL type name should still be used as a label, it needs to be specified as well:
141+
If you want to use the GraphQL type name as a label, specifiy both.
142+
143+
.Querying a field with two entries for the `labels` parameter
144+
====
145+
Consider the following type definition:
122146
123147
[source, graphql, indent=0]
124148
----
@@ -127,7 +151,8 @@ type Dog @node(labels: ["Dog", "K9"]) {
127151
}
128152
----
129153
130-
This way, the following query:
154+
Here is an example for a query against the `Dog` node
155+
131156
132157
[source, graphql, indent=0]
133158
----
@@ -138,13 +163,14 @@ This way, the following query:
138163
}
139164
----
140165
141-
Generates the Cypher query:
166+
The following Cypher is generated:
142167
143168
[source, cypher, indent=0]
144169
----
145170
MATCH (this:Dog:K9)
146171
RETURN this { .name } as this
147172
----
173+
====
148174

149175
[NOTE]
150176
====
@@ -161,12 +187,18 @@ type Dog @node(labels: ["K9", "Dog"]) {
161187
}
162188
----
163189

190+
See xref::/directives/indexes-and-constraints.adoc#_unique_node_property_constraints[`@unique`] to learn more about the `@unique` directive.
164191

165-
[discrete]
166-
=== Using `$jwt` and `$context`
192+
193+
==== Using `$jwt` and `$context`
167194

168195
In some cases, you may want to generate dynamic labels depending on the user requesting.
169-
For that, you can use the variable `$jwt` to define a custom label in the JWT:
196+
You can use the variable `$jwt` to define a custom label in the JWT.
197+
198+
199+
.Querying a field with a `$jwt` variable in the `labels` parameter
200+
====
201+
Consider the following type definition:
170202
171203
[source, graphql, indent=0]
172204
----
@@ -186,13 +218,14 @@ The following query yields a different Cypher query depending on the user JWT:
186218
}
187219
----
188220
189-
Assuming there is a user with the value `"username": "arthur"` in JWT, the Cypher query looks like:
221+
Assuming there is a user with the value `"username": "arthur"` in JWT, the Cypher query looks like this:
190222
191223
[source, cypher, indent=0]
192224
----
193225
MATCH (this:arthur)
194226
RETURN this { .name } as this
195227
----
228+
====
196229

197230
Similarly, context values can be passed directly:
198231

@@ -203,7 +236,7 @@ type User @node(label: ["$context.appId"]) {
203236
}
204237
----
205238

206-
When running the server with Apollo:
239+
For example, if you are running the server with Apollo:
207240

208241
[source, js, indent=0]
209242
----
@@ -217,9 +250,14 @@ await startStandaloneServer(server, {
217250
----
218251

219252

220-
[[type-definitions-alias]]
221253
== `@alias`
222254

255+
=== Definition
256+
257+
// tba
258+
259+
=== Usage
260+
223261
This directive maps a GraphQL field to a Neo4j property on a node or relationship.
224262
It can be used on any fields that are not `@cypher` or `@relationship` fields.
225263

modules/ROOT/pages/directives/index.adoc

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,50 @@
55

66
The Neo4j GraphQL Library provides the following directives to be used whilst defining types:
77

8-
== Database mapping
8+
== Security
99

1010
[cols="2,5"]
1111
|===
1212
| Directive | Description
1313

14-
| xref::/directives/database-mapping.adoc#_relationship[`@relationship`]
15-
| Configures xref::/types/relationships.adoc[relationships] between object types.
14+
| xref::/security/authentication.adoc#_authentication[`@authentication`]
15+
| Requires authentication checks when accessing the type.
1616

17-
| xref::/directives/database-mapping.adoc#_relationshipproperties[`@relationshipProperties`]
18-
a| Required to differentiate interfaces that are used for relationship properties, and otherwise.
17+
| xref::/security/authorization.adoc[`@authorization`]
18+
| Specifies authorization rules for queries and mutations on the type.
1919

20-
| xref::/directives/database-mapping.adoc#type-definitions-node[`@node`]
21-
| Specifies the configuration of a GraphQL object type which represents a Neo4j node.
20+
| xref::/security/configuration.adoc#_jwt[`@jwt`]
21+
| Configures the JWT authentication and authorization filters to include additional JWT claims.
2222

23-
| xref::/directives/database-mapping.adoc#type-definitions-alias[`@alias`]
24-
| Maps a GraphQL schema field to a Neo4j property on a node or relationship.
23+
| xref::/security/configuration.adoc#_jwtclaim[`@jwtClaim`]
24+
| Used in combination with `@jwt`.
25+
Configures the JWT authentication and authorization filters to include an additional JWT claim which is either nested or using special characters not supported by GraphQL.
2526

26-
| xref::/types/relationships.adoc#_declarerelationship[`@declareRelationship`]
27-
| Configure relationships to be implemented on object types.
27+
| xref::/security/subscriptions-authorization.adoc[`@subscriptionsAuthorization`]
28+
| Specifies authorization rules for subscriptions on the type.
2829

2930
|===
3031

31-
== Security
32+
== Database mapping
3233

3334
[cols="2,5"]
3435
|===
3536
| Directive | Description
3637

37-
| xref::/security/authentication.adoc[`@authentication`]
38-
| Requires authentication checks when accessing the type.
38+
| xref::/directives/database-mapping.adoc#_relationship[`@relationship`]
39+
| Configures xref::/types/relationships.adoc[relationships] between object types. Also see xref::/directives/schema-configuration/field-configuration.adoc#_relationship[`@relationship` field configuration].
3940

40-
| xref::/security/authorization.adoc[`@authorization`]
41-
| Specifies authorization rules for queries and mutations on the type.
41+
| xref::/directives/database-mapping.adoc#_relationshipproperties[`@relationshipProperties`]
42+
a| Required to differentiate interfaces that are used for relationship properties, and otherwise.
4243

43-
| xref::/security/configuration.adoc#_the_jwt_directive[`@jwt`]
44-
| Configures the JWT authentication and authorization filters to include additional JWT claims.
44+
| xref::/directives/database-mapping.adoc#_node[`@node`]
45+
| Specifies the configuration of a GraphQL object type which represents a Neo4j node.
4546

46-
| xref::/security/configuration.adoc#_the_jwtclaim_directive[`@jwtClaim`]
47-
| Used in combination with `@jwt`.
48-
Configures the JWT authentication and authorization filters to include an additional JWT claim which is either nested or using special characters not supported by GraphQL.
47+
| xref::/directives/database-mapping.adoc#_alias[`@alias`]
48+
| Maps a GraphQL schema field to a Neo4j property on a node or relationship.
4949

50-
| xref::/security/subscriptions-authorization.adoc[`@subscriptionsAuthorization`]
51-
| Specifies authorization rules for subscriptions on the type.
50+
| xref::/types/relationships.adoc#_declarerelationship[`@declareRelationship`]
51+
| Configure relationships to be implemented on object types.
5252

5353
|===
5454

@@ -84,7 +84,7 @@ Configures the JWT authentication and authorization filters to include an additi
8484
| xref::/directives/schema-configuration/type-configuration.adoc#type-definitions-default-values-default[`@default`]
8585
| Allows the setting of a default value for a field during object creation.
8686

87-
| xref::/directives/schema-configuration/type-configuration.adoc#type-definitions-plural[`@plural`]
87+
| xref::/directives/schema-configuration/type-configuration.adoc#_plural[`@plural`]
8888
| Redefines how to compose the plural of the type for the generated operations.
8989
Particularly useful for types that are not correctly pluralized or are non-English words.
9090

@@ -157,7 +157,7 @@ of any required fields that is passed as arguments to the custom resolver.
157157
|===
158158
| Directive | Description
159159

160-
| xref:/integrations/relay-compatibility.adoc[`@relayId`]
160+
| xref:/integrations/relay-compatibility.adoc#_relayid[`@relayId`]
161161
| Specifies that the field should be used as the global node identifier for Relay.
162162

163163
|===

0 commit comments

Comments
 (0)