Skip to content

Commit 564c8bb

Browse files
authored
Merge branch '7.x' into restructuring-the-reference
2 parents d664fc2 + 099d76c commit 564c8bb

File tree

5 files changed

+137
-8
lines changed

5 files changed

+137
-8
lines changed

modules/ROOT/pages/directives/index.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ Particularly useful for types that are not correctly pluralized or are non-Engli
9494
| xref:/directives/schema-configuration/field-configuration.adoc#_settable[`@settable`]
9595
| Sets the availability of fields on the `create` and `update` inputs.
9696

97+
| xref:/directives/schema-configuration/field-configuration.adoc#_sortable[`@sortable`]
98+
| Sets the availability of sorting inputs for that field.
99+
97100
| xref:/directives/schema-configuration/field-configuration.adoc#_filterable[`@filterable`]
98101
| Defines the filters generated for a field.
99102

modules/ROOT/pages/directives/schema-configuration/field-configuration.adoc

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,71 @@ input ActorUpdateInput {
398398

399399
This means `actedIn` can be updated on an update, but it is no longer available on `create` operations.
400400

401+
402+
== `@sortable`
403+
404+
This directive sets the availability of the input fields for sorting.
405+
It has a single argument:
406+
407+
* **byValue**: Defaults to true. If disabled, this field is not available for sorting.
408+
409+
=== Definition
410+
411+
[source, graphql, indent=0]
412+
----
413+
"""Instructs @neo4j/graphql to generate sorting inputs for this field."""
414+
directive @sortable(byValue: Boolean! = true) on FIELD_DEFINITION
415+
----
416+
417+
=== Usage
418+
419+
With this definition:
420+
421+
[source, graphql, indent=0]
422+
----
423+
type Movie @node {
424+
title: String!
425+
description: String! @sortable(byValue: false)
426+
}
427+
----
428+
429+
The following input type is generated for Movies:
430+
431+
[source, graphql, indent=0]
432+
----
433+
"""
434+
Fields to sort Movies by. The order in which sorts are applied is not guaranteed when specifying many fields in one MovieSort object.
435+
"""
436+
input MovieSort {
437+
title: SortDirection
438+
}
439+
----
440+
441+
Movies can be sorted by the title, but not by description:
442+
443+
This is valid:
444+
[source, graphql, indent=0]
445+
----
446+
query {
447+
movies(sort: {title: DESC}) {
448+
title
449+
}
450+
}
451+
----
452+
453+
This is not valid:
454+
[source, graphql, indent=0]
455+
----
456+
query {
457+
movies(sort: {description: DESC}) {
458+
title
459+
}
460+
}
461+
----
462+
463+
464+
If no fields are sortable, the type `MovieSort` is not generated, and the `sort` input isn't available.
465+
401466
== `@filterable`
402467

403468
This directive defines the filters generated for the field to which this directive is applied.

modules/ROOT/pages/directives/schema-configuration/global-configuration.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type Actor @node {
2020
name: String
2121
movies: [Movie!]! @relationship(type: "ACTED_IN", direction: OUT)
2222
}
23-
extend schema @query(read: true, aggregate: false)
23+
extend schema @query(read: true, connection: true, aggregate: false)
2424
----
2525

2626
This configuration disables all top-level aggregation operations for the `Movie` and `Actor` types, while still allowing read operations.
@@ -59,7 +59,7 @@ type Movie @node {
5959
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN)
6060
}
6161
62-
type Actor @node @query(read: false, aggregate: true) {
62+
type Actor @node @query(read: false, connection: false, aggregate: true) {
6363
name: String
6464
movies: [Movie!]! @relationship(type: "ACTED_IN", direction: OUT)
6565
}

modules/ROOT/pages/directives/schema-configuration/type-configuration.adoc

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ This directive is used to limit the availability of query operations in the libr
5151

5252
[source, graphql, indent=0]
5353
----
54-
directive @query(read: Boolean! = true, aggregate: Boolean! = false) on OBJECT | SCHEMA | INTERFACE | UNION
54+
directive @query(read: Boolean! = true, connection: Boolean, aggregate: Boolean! = false) on OBJECT | SCHEMA | INTERFACE | UNION
5555
----
5656

57+
Where the value of the `connection` argument defaults to the value of the `read` argument.
58+
5759
=== Usage
5860

5961
.Disable query _movies_ and _moviesConnection_ edges field
@@ -68,7 +70,25 @@ type Movie @node @query(read: false, aggregate: true) {
6870
.Disable _moviesConnection_ aggregate field
6971
[source, graphql, indent=0]
7072
----
71-
type Movie @node @query(read: true, aggregate: false) {
73+
type Movie @node @query(read: true, aggregate: false) { # aggregate can be omitted as it defaults to false
74+
title: String
75+
length: Int
76+
}
77+
----
78+
79+
.Disable _moviesConnection_ completely
80+
[source, graphql, indent=0]
81+
----
82+
type Movie @node @query(read: true, connection: false, aggregate: false) { # aggregate can be omitted as it defaults to false
83+
title: String
84+
length: Int
85+
}
86+
----
87+
88+
.Disable all reads
89+
[source, graphql, indent=0]
90+
----
91+
type Movie @node @query(read: false, aggregate: false) { # aggregate can be omitted as it defaults to false
7292
title: String
7393
length: Int
7494
}

modules/ROOT/pages/queries-aggregations/aggregations.adoc

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ Aggregations on a type are provided in the field `aggregate` inside Connection:
4949
query {
5050
usersConnection {
5151
aggregate {
52-
name {
53-
longest
52+
node {
53+
name {
54+
longest
55+
}
5456
}
5557
}
5658
}
@@ -94,8 +96,10 @@ a|
9496
query {
9597
postsConnection {
9698
aggregate {
97-
createdAt {
98-
min
99+
node {
100+
createdAt {
101+
min
102+
}
99103
}
100104
}
101105
}
@@ -220,3 +224,40 @@ query {
220224
}
221225
----
222226

227+
228+
== Aggregations and pagination
229+
230+
Since aggregations are done within the `Connection` type, the optional arguments `first` and `after` are available for pagination.
231+
However, pagination **does not** apply to aggregations.
232+
233+
For example:
234+
235+
[source, graphql, indent=0]
236+
----
237+
query {
238+
usersConnection(first: 10) {
239+
aggregate {
240+
count {
241+
nodes
242+
}
243+
}
244+
}
245+
}
246+
----
247+
248+
The result returns the count of all the nodes:
249+
250+
[source, json, indent=0]
251+
----
252+
{
253+
"usersConnection": {
254+
"aggregate": {
255+
"count": {
256+
"nodes": 38
257+
}
258+
}
259+
}
260+
}
261+
----
262+
263+

0 commit comments

Comments
 (0)