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/type-definitions/directives/custom-logic.adoc
+17-16Lines changed: 17 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,14 +9,14 @@ This directive can be used both for properties in a type or as top level queries
9
9
10
10
=== Global variables
11
11
12
-
Global variables are available for use within the Cypher statement and can be applied to the `@cypher` directive.
12
+
Global variables are available for use within the Cypher statement, and can be applied to the `@cypher` directive.
13
13
14
14
[cols="1,2,2"]
15
15
|===
16
16
| Variable | Description | Example
17
17
18
18
| `this`
19
-
| This value is a reference to the currently resolved node, and it can be used to traverse the graph.
19
+
| Refers to the currently resolved node, and can be used to traverse the graph.
20
20
a|
21
21
[source, graphql, indent=0]
22
22
----
@@ -99,7 +99,7 @@ type Query {
99
99
The return value of Cypher statements must always be of the same type to which the directive is applied.
100
100
101
101
The variable must also be aliased with a name that is the same as the one passed to `columnName`.
102
-
This can be the name of a node, relationship query or an alias in the `RETURN` statement of the Cypher statement.
102
+
This can be the name of a node, relationship query, or an alias in the `RETURN` statement of the Cypher statement.
103
103
104
104
==== Scalar values
105
105
@@ -158,7 +158,8 @@ The downside of the latter approach is that you need to adjust the return object
158
158
159
159
=== Input arguments
160
160
161
-
The `@cypher` statement can access the query parameters by prepending `$` to the parameter name. For example:
161
+
The `@cypher` statement can access the query parameters by prepending `$` to the parameter name.
162
+
For example:
162
163
163
164
[source, graphql, indent=0]
164
165
----
@@ -184,7 +185,7 @@ The `@cypher` directive can be used in different contexts, such as the ones desc
184
185
[[type-definitions-cypher-object-usage]]
185
186
==== On an object type field
186
187
187
-
In the example below, a field `similarMovies` is bound to the `Movie` type, to find other movies with an overlap of actors:
188
+
In the following example, the field `similarMovies` is bound to the `Movie` type for finding other movies with an overlap of actors:
188
189
189
190
[source, graphql, indent=0]
190
191
----
@@ -265,7 +266,8 @@ type Mutation {
265
266
When translating from GraphQL to Cypher, any instances of fields to which this directive is applied will be wrapped in a `coalesce()` function in the WHERE clause (see https://neo4j.com/developer/kb/understanding-non-existent-properties-and-null-values/#_use_coalesce_to_use_a_default_for_a_null_value).
266
267
267
268
This directive helps querying against non-existent properties in a database.
268
-
However, it is encouraged to populate these properties with meaningful values if this is becoming the norm. The `@coalesce`directive is a primitive implementation of the function which only takes a static default value as opposed to using another property in a node or a Cypher expression.
269
+
However, it is encouraged to populate these properties with meaningful values if it becomes the norm.
270
+
The `@coalesce`directive is a primitive implementation of the function which only takes a static default value as opposed to using another property in a node or a Cypher expression.
269
271
270
272
=== Definition
271
273
@@ -337,9 +339,8 @@ If no `default` value is set, `max` is used for queries without limit.
337
339
338
340
The Neo4j GraphQL Library generates query and mutation resolvers, so you don't need to implement them yourself.
339
341
However, if you need additional behaviors besides the autogenerated CRUD operations, you can specify custom resolvers for these scenarios.
340
-
This page describes how to set them up.
341
342
342
-
To add a field to an object type which is resolved from existing values in the type, rather than storing new values, you should mark it with the `@customResolver` directive and define a custom resolver for it.
343
+
To add a field to an object type which is resolved from existing values in the type, rather than storing new values, you should mark it with the `@customResolver` directive, and define a custom resolver for it.
343
344
344
345
Take, for instance, this schema:
345
346
@@ -386,11 +387,11 @@ directive @customResolver(
386
387
387
388
=== The `requires` argument
388
389
389
-
This is how the `requires` argument can be used on your schema:
390
+
The `requires` argument can be used:
390
391
391
-
* Accepts a selection set string.
392
-
* Can be used in any field, as long as it is not another `@customResolver` field.
393
-
* Should be used in case the custom resolver depends on any fields.
392
+
* For a selection set string.
393
+
* In any field, as long as it is not another `@customResolver` field.
394
+
* In case the custom resolver depends on any fields.
394
395
This ensures that, during the Cypher generation process, these properties are selected from the database.
395
396
396
397
Using a selection set string makes it possible to select fields from related types, as shown in the following example:
@@ -428,7 +429,7 @@ const neoSchema = new Neo4jGraphQL({
428
429
});
429
430
----
430
431
431
-
Here the `firstName`, `lastName`, `address.street`, and `address.city` fields are always selected from the database if the `fullName` field is selected and is available to the custom resolver.
432
+
Here the `firstName`, `lastName`, `address.street`, and `address.city` fields are always selected from the database if the `fullName` field is selected, and is available to the custom resolver.
432
433
433
434
It is also possible to inline fragments to conditionally select fields from interface/union types:
434
435
@@ -461,7 +462,7 @@ type Journal implements Publication {
461
462
----
462
463
463
464
However, it is **not** possible to require extra fields generated by the library such as aggregations and connections.
464
-
For example, the type definitions below would throw an error as they attempt to require the `publicationsAggregate`:
465
+
For example, the following type definitions would throw an error since they attempt to require the `publicationsAggregate`:
465
466
466
467
[source, graphql, indent=0]
467
468
----
@@ -495,7 +496,7 @@ type Journal implements Publication {
495
496
496
497
== `@populatedBy`
497
498
498
-
This directive is used to specify a callback function that gets executed during GraphQL query parsing,
499
+
This directive is used to specify a callback function, which is executed during GraphQL query parsing,
499
500
to populate fields which have not been provided within the input.
500
501
501
502
For non-required values, callbacks may return `undefined` (meaning that nothing is changed or added to the property) or `null` (meaning that the property will be removed).
@@ -566,7 +567,7 @@ type Record {
566
567
}
567
568
----
568
569
569
-
If the username is located in `context.username`, you could define a callback such as:
570
+
And if the username is located in `context.username`, you could define a callback such as:
0 commit comments