Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions modules/ROOT/pages/directives/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ Particularly useful for types that are not correctly pluralized or are non-Engli
| xref:/directives/schema-configuration/field-configuration.adoc#_filterable[`@filterable`]
| Defines the filters generated for a field.

| xref:/directives/schema-configuration/field-configuration.adoc#_groupBy[`@groupBy`]
| Defines a field that can be used to group by in queries.

|===

== Indexes and constraints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,3 +565,110 @@ input ActorActedInNodeAggregationWhereInput {
----

As shown by the previous inputs fields, the `actors` field is not available for filtering on both value and aggregation filters.


== `@groupBy`

This directive defines fields that can be used to group query results.

=== Definition

[source, graphql, indent=0]
----
"""Enables groupBy operations for this field."""
directive @groupBy() on FIELD_DEFINITION
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this have the empty paranthesis?

----

=== Usage

Consider the following definition:

[source, graphql, indent=0]
----
type Movie @node {
title: String!
year: Int! @groupBy
}
----

It adds the field `groupBy` to the `movieConnection` operation.
The field allows you to query movies grouped by the `year` field.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The field allows you to query movies grouped by the `year` field.



The `groupBy` field has one argument `fields`, that defines the field to group by.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The `groupBy` field has one argument `fields`, that defines the field to group by.
The `groupBy` field has a single, mandatory argument `fields` which defines the field to group the results by.
The type of the `groupBy` field is a list of results compliant to the Connection Spec.

In this case `year` is the only option.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In this case `year` is the only option.
The following example shows how to query movies grouped by the `year` field.
In this case, `year` is the only field the results can be group by.


[source, graphql, indent=0]
----
query {
moviesConnection {
groupBy(fields: { year: true }) {
edges {
node {
title
year
}
}
}
}
}
----

The `groupBy` field returns a list of results and each result contains a list of `edges`, with all results grouped by the `year` field.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The `groupBy` field returns a list of results and each result contains a list of `edges`, with all results grouped by the `year` field.
The result of this query is a list of `edges` wherein all results share the same value of the `year` field.

For example:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
For example:


[source, json, indent=0]
----
{
"moviesConnection": {
"groupBy": [
{
"edges": [
{
"node": {
"title": "The Matrix",
"year": 1999
}
},
{
"title": "Fight Club",
"year": 1999
}
]
},
{
"edges": [
{
"node": {
"title": "Gladiator",
"year": 2000
}
}
]
}
]
}
}
----

Note that the `year` field is repeated on every node of the `edges` from each `groupBy` result.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Note that the `year` field is repeated on every node of the `edges` from each `groupBy` result.


Nodes can be grouped by multiple fields:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Nodes can be grouped by multiple fields:
Nodes can be grouped by multiple fields.
Consider the following type definition:
[source, graphql, indent=0]
----
type Movie @node {
title: String!
year: Int! @groupBy
rating: Int! @groupBy
}
----
You can now use both `year` and `rating` fields in the argument of the `groupBy` field.


[source, graphql, indent=0]
----
query {
moviesConnection {
groupBy(fields: { year: true, rating: true }) {
edges {
node {
title
year
}
}
}
}
}
----

In this case, all movies with the same `year` and `rating` are grouped together in the same result.