You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: modules/ROOT/pages/directives/autogeneration.adoc
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ This enables autogeneration of IDs for the field.
15
15
The format of each generated ID is a UUID generated by the link:https://neo4j.com/docs/cypher-manual/current/functions/scalar/#functions-randomuuid[`randomUUID()` function].
16
16
The field will not be present in input types for mutations.
17
17
18
-
It is recommended to use xref::/directives/indexes-and-constraints.adoc#_unique_node_property_constraints[`@unique`] in conjunction with this to add a unique node property constraint.
18
+
It is recommended to use xref::/directives/indexes-and-constraints.adoc#_unique[`@unique`] in conjunction with this to add a unique node property constraint.
Copy file name to clipboardExpand all lines: modules/ROOT/pages/directives/custom-logic.adoc
+10-8Lines changed: 10 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,9 @@
7
7
The `@cypher` directive binds a GraphQL field to the results of a Cypher query.
8
8
This directive can be used both for properties in a type or as top level queries.
9
9
10
-
=== Global variables
10
+
=== Definition
11
+
12
+
==== Global variables
11
13
12
14
Global variables are available for use within the Cypher statement, and can be applied to the `@cypher` directive.
13
15
@@ -90,14 +92,14 @@ type Query {
90
92
|===
91
93
92
94
93
-
=== Return values
95
+
==== Return values
94
96
95
97
The return value of Cypher statements must always be of the same type to which the directive is applied.
96
98
97
99
The variable must also be aliased with a name that is the same as the one passed to `columnName`.
98
100
This can be the name of a node, relationship query, or an alias in the `RETURN` statement of the Cypher statement.
99
101
100
-
==== Scalar values
102
+
===== Scalar values
101
103
102
104
Cypher statements must return a value which matches the scalar type to which the directive was applied.
103
105
For example:
@@ -109,7 +111,7 @@ type Query {
109
111
}
110
112
----
111
113
112
-
==== Object types
114
+
===== Object types
113
115
114
116
When returning an object type, all fields of the type must be available in the Cypher return value.
115
117
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 {
152
154
The downside of the latter approach is that you need to adjust the return object as you change your object type definition.
153
155
154
156
155
-
=== Input arguments
157
+
==== Input arguments
156
158
157
159
The `@cypher` statement can access the query parameters by prepending `$` to the parameter name.
158
160
For example:
@@ -174,7 +176,7 @@ query {
174
176
----
175
177
176
178
177
-
=== Usage examples
179
+
=== Usage
178
180
179
181
The `@cypher` directive can be used in different contexts, such as the ones described in this section.
180
182
@@ -383,7 +385,7 @@ directive @customResolver(
383
385
) on FIELD_DEFINITION
384
386
----
385
387
386
-
=== The `requires` argument
388
+
=== Usage
387
389
388
390
The `requires` argument can be used:
389
391
@@ -552,7 +554,7 @@ new Neo4jGraphQL({
552
554
})
553
555
----
554
556
555
-
=== Context values
557
+
==== Context values
556
558
557
559
The GraphQL context for the request is available as the third argument in a callback.
558
560
This maps to the argument pattern for GraphQL resolvers.
Relationships are represented by marking particular fields with a directive -- in this case, `@relationship`.
14
41
It defines the relationship type in the database, as well as which direction that relationship goes in.
15
42
16
-
To add a second node type, "Actor", and connect the two together, you should do the following:
43
+
To add two node types, "Movie" and "Actor", and connect the two:
17
44
18
45
[source, graphql, indent=0]
19
46
----
@@ -28,8 +55,14 @@ type Actor {
28
55
}
29
56
----
30
57
31
-
Note that, in this case, there is a directive on each "end" of the relationship, but it is not essential.
58
+
[NOTE]
59
+
====
60
+
The `@relationship` directive is used twice, once on each end of the relationship.
61
+
This is the standard way of modeling a relationship with the GraphQL Library.
62
+
However, it is not a requirement of the type definitions themselves as relationships can deliberately be underspecified, for example to limit access through the API layer.
63
+
====
32
64
65
+
See also: xref::/directives/schema-configuration/field-configuration#_relationship[`@relationship` field configuration].
33
66
34
67
== `@relationshipProperties`
35
68
@@ -70,9 +103,21 @@ Note that in addition to this type, there is an added key `properties` in the ex
70
103
For more information, see xref::/types/relationships.adoc[Type definitions -> Relationships].
71
104
72
105
73
-
[[type-definitions-node]]
74
106
== `@node`
75
107
108
+
=== Definition
109
+
110
+
[source, graphql, indent=0]
111
+
----
112
+
"""Informs @neo4j/graphql of node metadata"""
113
+
directive @node(
114
+
"""The labels to map this GraphQL type to in the Neo4j database"""
115
+
labels: [String!]
116
+
) on OBJECT
117
+
----
118
+
119
+
=== Usage
120
+
76
121
The most basic mapping uses GraphQL type names to map to a Neo4j node label.
77
122
For example, to represent a node with the label "Movie" and a single property "title" of type string:
78
123
@@ -84,13 +129,15 @@ type Movie {
84
129
----
85
130
86
131
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:
88
132
133
+
==== The `labels` parameter
89
134
90
-
[discrete]
91
-
=== `labels`
135
+
You can append the optional parameters `labels` to a GraphQL object with the `@node` directive.
136
+
This parameter lists the labels to be used in Neo4j instead of the GraphQL type name.
92
137
93
-
This parameter defines the list of label to be used in Neo4j instead of the GraphQL type name:
138
+
.Querying a field with the `labels` parameter
139
+
====
140
+
Consider the following type definition:
94
141
95
142
[source, graphql, indent=0]
96
143
----
@@ -99,7 +146,7 @@ type Dog @node(labels: ["K9"]) {
99
146
}
100
147
----
101
148
102
-
This way, the following query:
149
+
Here is a query against the `Dog` node:
103
150
104
151
[source, graphql, indent=0]
105
152
----
@@ -110,15 +157,20 @@ This way, the following query:
110
157
}
111
158
----
112
159
113
-
Generates the Cypher query:
160
+
The following Cypher is generated:
114
161
115
162
[source, cypher, indent=0]
116
163
----
117
164
MATCH (this: K9)
118
165
RETURN this { .name } as name
119
166
----
167
+
====
120
168
121
-
If the GraphQL type name should still be used as a label, it needs to be specified as well:
169
+
If you want to use the GraphQL type name as a label, specifiy both.
170
+
171
+
.Querying a field with two entries for the `labels` parameter
172
+
====
173
+
Consider the following type definition:
122
174
123
175
[source, graphql, indent=0]
124
176
----
@@ -127,7 +179,8 @@ type Dog @node(labels: ["Dog", "K9"]) {
127
179
}
128
180
----
129
181
130
-
This way, the following query:
182
+
Here is an example for a query against the `Dog` node
183
+
131
184
132
185
[source, graphql, indent=0]
133
186
----
@@ -138,13 +191,14 @@ This way, the following query:
138
191
}
139
192
----
140
193
141
-
Generates the Cypher query:
194
+
The following Cypher is generated:
142
195
143
196
[source, cypher, indent=0]
144
197
----
145
198
MATCH (this:Dog:K9)
146
199
RETURN this { .name } as this
147
200
----
201
+
====
148
202
149
203
[NOTE]
150
204
====
@@ -161,12 +215,18 @@ type Dog @node(labels: ["K9", "Dog"]) {
161
215
}
162
216
----
163
217
218
+
See xref::/directives/indexes-and-constraints.adoc#_unique[`@unique`] to learn more about the `@unique` directive.
219
+
164
220
165
-
[discrete]
166
-
=== Using `$jwt` and `$context`
221
+
==== Using `$jwt` and `$context`
167
222
168
223
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:
224
+
You can use the variable `$jwt` to define a custom label in the JWT.
225
+
226
+
227
+
.Querying a field with a `$jwt` variable in the `labels` parameter
228
+
====
229
+
Consider the following type definition:
170
230
171
231
[source, graphql, indent=0]
172
232
----
@@ -186,13 +246,14 @@ The following query yields a different Cypher query depending on the user JWT:
186
246
}
187
247
----
188
248
189
-
Assuming there is a user with the value `"username": "arthur"` in JWT, the Cypher query looks like:
249
+
Assuming there is a user with the value `"username": "arthur"` in JWT, the Cypher query looks like this:
190
250
191
251
[source, cypher, indent=0]
192
252
----
193
253
MATCH (this:arthur)
194
254
RETURN this { .name } as this
195
255
----
256
+
====
196
257
197
258
Similarly, context values can be passed directly:
198
259
@@ -203,7 +264,7 @@ type User @node(label: ["$context.appId"]) {
203
264
}
204
265
----
205
266
206
-
When running the server with Apollo:
267
+
For example, if you are running the server with Apollo:
0 commit comments