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.
@@ -8,9 +8,21 @@ This page describes how to use directives for database mapping.
8
8
Each type in your GraphQL type definitions can be mapped to an entity in your Neo4j database, such as nodes, relationships, and relationship properties.
9
9
10
10
11
-
[[type-definitions-node]]
12
11
== `@node`
13
12
13
+
=== Definition
14
+
15
+
[source, graphql, indent=0]
16
+
----
17
+
"""Informs @neo4j/graphql of node metadata"""
18
+
directive @node(
19
+
"""The labels to map this GraphQL type to in the Neo4j database"""
20
+
labels: [String!]
21
+
) on OBJECT
22
+
----
23
+
24
+
=== Usage
25
+
14
26
Adding the `@node` directive to your GraphQL type specifies that it represents a Neo4j node.
15
27
For example, to represent a Neo4j node with the label "Movie" and a single property "title" of type string:
16
28
@@ -27,12 +39,16 @@ In version 6.x, it's not required to specify every GraphQL type representing a N
27
39
In the future, types without the `@node` directive will no longer be treated as Neo4j nodes.
28
40
====
29
41
30
-
When not differently specified, the GraphQL type name is used as a label for the represented Neo4j node. It's possible to explicitly define the Neo4j node labels by using the argument `labels`:
42
+
When not differently specified, the GraphQL type name is used as a label for the represented Neo4j node. It's possible to explicitly define the Neo4j node labels by using the parameter `labels`.
31
43
32
-
[discrete]
33
-
=== `labels`
44
+
==== The `labels` parameter
34
45
35
-
This parameter defines the list of label to be used in Neo4j instead of the GraphQL type name:
46
+
You can append the optional parameters `labels` to a GraphQL object with the `@node` directive.
47
+
This parameter lists the labels to be used in Neo4j instead of the GraphQL type name.
48
+
49
+
.Querying a field with the `labels` parameter
50
+
====
51
+
Consider the following type definition:
36
52
37
53
[source, graphql, indent=0]
38
54
----
@@ -41,7 +57,7 @@ type Dog @node(labels: ["K9"]) {
41
57
}
42
58
----
43
59
44
-
This way, the following query:
60
+
Here is a query against the `Dog` node:
45
61
46
62
[source, graphql, indent=0]
47
63
----
@@ -52,15 +68,20 @@ This way, the following query:
52
68
}
53
69
----
54
70
55
-
Generates the Cypher query:
71
+
The following Cypher is generated:
56
72
57
73
[source, cypher, indent=0]
58
74
----
59
75
MATCH (this: K9)
60
76
RETURN this { .name } as name
61
77
----
78
+
====
62
79
63
-
If the GraphQL type name should still be used as a label, it needs to be specified as well:
80
+
If you want to use the GraphQL type name as a label, specifiy both.
81
+
82
+
.Querying a field with two entries for the `labels` parameter
83
+
====
84
+
Consider the following type definition:
64
85
65
86
[source, graphql, indent=0]
66
87
----
@@ -69,7 +90,8 @@ type Dog @node(labels: ["Dog", "K9"]) {
69
90
}
70
91
----
71
92
72
-
This way, the following query:
93
+
Here is an example for a query against the `Dog` node
94
+
73
95
74
96
[source, graphql, indent=0]
75
97
----
@@ -80,13 +102,14 @@ This way, the following query:
80
102
}
81
103
----
82
104
83
-
Generates the Cypher query:
105
+
The following Cypher is generated:
84
106
85
107
[source, cypher, indent=0]
86
108
----
87
109
MATCH (this:Dog:K9)
88
110
RETURN this { .name } as this
89
111
----
112
+
====
90
113
91
114
[NOTE]
92
115
====
@@ -103,12 +126,18 @@ type Dog @node(labels: ["K9", "Dog"]) {
103
126
}
104
127
----
105
128
129
+
See xref::/directives/indexes-and-constraints.adoc#_unique[`@unique`] to learn more about the `@unique` directive.
130
+
106
131
107
-
[discrete]
108
-
=== Using `$jwt` and `$context`
132
+
==== Using `$jwt` and `$context`
109
133
110
134
In some cases, you may want to generate dynamic labels depending on the user requesting.
111
-
For that, you can use the variable `$jwt` to define a custom label in the JWT:
135
+
You can use the variable `$jwt` to define a custom label in the JWT.
136
+
137
+
138
+
.Querying a field with a `$jwt` variable in the `labels` parameter
139
+
====
140
+
Consider the following type definition:
112
141
113
142
[source, graphql, indent=0]
114
143
----
@@ -128,13 +157,14 @@ The following query yields a different Cypher query depending on the user JWT:
128
157
}
129
158
----
130
159
131
-
Assuming there is a user with the value `"username": "arthur"` in JWT, the Cypher query looks like:
160
+
Assuming there is a user with the value `"username": "arthur"` in JWT, the Cypher query looks like this:
132
161
133
162
[source, cypher, indent=0]
134
163
----
135
164
MATCH (this:arthur)
136
165
RETURN this { .name } as this
137
166
----
167
+
====
138
168
139
169
Similarly, context values can be passed directly:
140
170
@@ -145,7 +175,7 @@ type User @node(label: ["$context.appId"]) {
145
175
}
146
176
----
147
177
148
-
When running the server with Apollo:
178
+
For example, if you are running the server with Apollo:
Note that, in this case, there is a directive on each "end" of the relationship, but it is not essential.
238
+
[NOTE]
239
+
====
240
+
The `@relationship` directive is used twice, once on each end of the relationship.
241
+
This is the standard way of modeling a relationship with the GraphQL Library.
242
+
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.
243
+
====
182
244
245
+
See also: xref::/directives/schema-configuration/field-configuration#_relationship[`@relationship` field configuration].
183
246
184
247
== `@relationshipProperties`
185
248
@@ -201,12 +264,12 @@ For example, for the "ACTED_IN" relationship, add a property "roles":
201
264
202
265
[source, graphql, indent=0]
203
266
----
204
-
type Movie @node {
267
+
type Movie {
205
268
title: String
206
269
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
0 commit comments