-
Notifications
You must be signed in to change notification settings - Fork 15
add documentation for group by directive #296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 7.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||||||||||||||||||||||||||||
| ---- | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| === 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. | ||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||
| In this case `year` is the only option. | ||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| [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. | ||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||
| For example: | ||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| [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. | ||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Nodes can be grouped by multiple fields: | ||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| [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. | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
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?