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/custom-logic.adoc
+13-7Lines changed: 13 additions & 7 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.
Copy file name to clipboardExpand all lines: modules/ROOT/pages/directives/database-mapping.adoc
+56-18Lines changed: 56 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -10,10 +10,16 @@ Each type in your GraphQL type definitions can be mapped to an entity in your Ne
10
10
11
11
== `@relationship`
12
12
13
+
=== Definition
14
+
15
+
// tba
16
+
17
+
=== Usage
18
+
13
19
Relationships are represented by marking particular fields with a directive -- in this case, `@relationship`.
14
20
It defines the relationship type in the database, as well as which direction that relationship goes in.
15
21
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:
17
23
18
24
[source, graphql, indent=0]
19
25
----
@@ -28,8 +34,14 @@ type Actor {
28
34
}
29
35
----
30
36
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
+
====
32
43
44
+
Also see xref::/directives/schema-configuration/field-configuration/#_relationship[`@relationship` field configuration].
33
45
34
46
== `@relationshipProperties`
35
47
@@ -70,9 +82,14 @@ Note that in addition to this type, there is an added key `properties` in the ex
70
82
For more information, see xref::/types/relationships.adoc[Type definitions -> Relationships].
71
83
72
84
73
-
[[type-definitions-node]]
74
85
== `@node`
75
86
87
+
=== Definition
88
+
89
+
// tba
90
+
91
+
=== Usage
92
+
76
93
The most basic mapping uses GraphQL type names to map to a Neo4j node label.
77
94
For example, to represent a node with the label "Movie" and a single property "title" of type string:
78
95
@@ -84,13 +101,15 @@ type Movie {
84
101
----
85
102
86
103
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
104
105
+
==== The `labels` parameter
89
106
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.
92
109
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:
94
113
95
114
[source, graphql, indent=0]
96
115
----
@@ -99,7 +118,7 @@ type Dog @node(labels: ["K9"]) {
99
118
}
100
119
----
101
120
102
-
This way, the following query:
121
+
Here is a query against the `Dog` node:
103
122
104
123
[source, graphql, indent=0]
105
124
----
@@ -110,15 +129,20 @@ This way, the following query:
110
129
}
111
130
----
112
131
113
-
Generates the Cypher query:
132
+
The following Cypher is generated:
114
133
115
134
[source, cypher, indent=0]
116
135
----
117
136
MATCH (this: K9)
118
137
RETURN this { .name } as name
119
138
----
139
+
====
120
140
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:
122
146
123
147
[source, graphql, indent=0]
124
148
----
@@ -127,7 +151,8 @@ type Dog @node(labels: ["Dog", "K9"]) {
127
151
}
128
152
----
129
153
130
-
This way, the following query:
154
+
Here is an example for a query against the `Dog` node
155
+
131
156
132
157
[source, graphql, indent=0]
133
158
----
@@ -138,13 +163,14 @@ This way, the following query:
138
163
}
139
164
----
140
165
141
-
Generates the Cypher query:
166
+
The following Cypher is generated:
142
167
143
168
[source, cypher, indent=0]
144
169
----
145
170
MATCH (this:Dog:K9)
146
171
RETURN this { .name } as this
147
172
----
173
+
====
148
174
149
175
[NOTE]
150
176
====
@@ -161,12 +187,18 @@ type Dog @node(labels: ["K9", "Dog"]) {
161
187
}
162
188
----
163
189
190
+
See xref::/directives/indexes-and-constraints.adoc#_unique_node_property_constraints[`@unique`] to learn more about the `@unique` directive.
164
191
165
-
[discrete]
166
-
=== Using `$jwt` and `$context`
192
+
193
+
==== Using `$jwt` and `$context`
167
194
168
195
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:
170
202
171
203
[source, graphql, indent=0]
172
204
----
@@ -186,13 +218,14 @@ The following query yields a different Cypher query depending on the user JWT:
186
218
}
187
219
----
188
220
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:
190
222
191
223
[source, cypher, indent=0]
192
224
----
193
225
MATCH (this:arthur)
194
226
RETURN this { .name } as this
195
227
----
228
+
====
196
229
197
230
Similarly, context values can be passed directly:
198
231
@@ -203,7 +236,7 @@ type User @node(label: ["$context.appId"]) {
203
236
}
204
237
----
205
238
206
-
When running the server with Apollo:
239
+
For example, if you are running the server with Apollo:
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.
| Configures xref::/types/relationships.adoc[relationships] between object types. Also see xref::/directives/schema-configuration/field-configuration.adoc#_relationship[`@relationship` field configuration].
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.
0 commit comments