Skip to content

Commit 310c937

Browse files
migrate queries-aggretation folder
1 parent 05a4803 commit 310c937

File tree

4 files changed

+67
-73
lines changed

4 files changed

+67
-73
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Queries on this page assume the following type definitions:
1111
type Post @node {
1212
id: ID! @id
1313
content: String!
14-
creator: User! @relationship(type: "HAS_POST", direction: IN, properties: "PostedAt")
14+
creators: [User!]! @relationship(type: "HAS_POST", direction: IN, properties: "PostedAt")
1515
createdAt: DateTime!
1616
}
1717
@@ -35,7 +35,6 @@ For which the following query fields are generated:
3535
type Query {
3636
posts(where: PostWhere, sort: [PostSort!]!, limit: Int, offset: Int,): [Post!]!
3737
postsConnection(after: String, first: Int, sort: [PostSort], where: PostWhere): PostsConnection!
38-
3938
users(where: UserWhere, sort: [UserSort!]!, limit: Int, offset: Int,): [User!]!
4039
usersConnection(after: String, first: Int, sort: [UserSort], where: UserWhere): UsersConnection!
4140
}
@@ -123,7 +122,7 @@ query {
123122
[source, graphql, indent=0]
124123
----
125124
query {
126-
usersConnection(where: { name_STARTS_WITH: "J" }) {
125+
usersConnection(where: { name: { startsWith: "J" } }) {
127126
aggregate {
128127
count {
129128
nodes
@@ -172,7 +171,7 @@ query {
172171
aggregate {
173172
node {
174173
content {
175-
longest
174+
longest
176175
}
177176
}
178177
}

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

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,12 @@ You can also fetch a `User` and then paginate through their posts:
7777
[source, graphql, indent=0]
7878
----
7979
query {
80-
users(where: {
81-
name_EQ: "Billy"
82-
}) {
83-
name
84-
posts(offset: 20, limit: 10) {
85-
content
86-
}
80+
users(where: { name: { eq: "Billy" } }) {
81+
name
82+
posts(offset: 20, limit: 10) {
83+
content
8784
}
85+
}
8886
}
8987
----
9088

@@ -113,21 +111,22 @@ If you wanted to fetch the posts of user "John Smith" 10 at a time, you would fi
113111
[source, graphql, indent=0]
114112
----
115113
query {
116-
users(where: { name_EQ: "John Smith" }) {
117-
name
118-
postsConnection(first: 10) {
119-
edges {
120-
node {
121-
content
122-
}
123-
}
124-
pageInfo {
125-
endCursor
126-
hasNextPage
127-
}
114+
users(where: { name: { eq: "John Smith" } }) {
115+
name
116+
postsConnection(first: 10) {
117+
edges {
118+
node {
119+
content
128120
}
121+
}
122+
pageInfo {
123+
endCursor
124+
hasNextPage
125+
}
129126
}
127+
}
130128
}
129+
131130
----
132131

133132
In the return value, if `hasNextPage` is `true`, you would pass `endCursor` into the next query of 10.
@@ -136,7 +135,7 @@ You can do this with a variable, for example, `$after` in the following query:
136135
[source, graphql, indent=0]
137136
----
138137
query Users($after: String) {
139-
users(where: { name_EQ: "John Smith" }) {
138+
users(where: { name: { eq: "John Smith"} }) {
140139
name
141140
postsConnection(first: 10, after: $after) {
142141
edges {
@@ -165,21 +164,21 @@ Add the `totalCount` field which returns the total number of results matching th
165164

166165
[source, graphql, indent=0]
167166
----
168-
query Users($after: String) {
169-
users(where: { name_EQ: "John Smith" }) {
170-
name
171-
postsConnection(first: 10) {
172-
edges {
173-
node {
174-
content
175-
}
176-
}
177-
pageInfo {
178-
endCursor
179-
hasNextPage
180-
}
181-
totalCount
167+
query Users {
168+
users(where: { name: { eq: "John Smith" } }) {
169+
name
170+
postsConnection(first: 10) {
171+
edges {
172+
node {
173+
content
182174
}
175+
}
176+
pageInfo {
177+
endCursor
178+
hasNextPage
179+
}
180+
totalCount
183181
}
182+
}
184183
}
185184
----

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
== Type definitions
66

7-
Quries on this page assume the following type definitions:
7+
Queries on this page assume the following type definitions:
88

99
[source, graphql, indent=0]
1010
----
1111
type Post @node {
1212
id: ID! @id
1313
content: String!
14-
creator: User! @relationship(type: "HAS_POST", direction: IN, properties: "PostedAt")
14+
creators: [User!]! @relationship(type: "HAS_POST", direction: IN, properties: "PostedAt")
1515
createdAt: DateTime!
1616
}
1717
@@ -33,11 +33,10 @@ For which the following query fields are generated:
3333
[source, graphql, indent=0]
3434
----
3535
type Query {
36-
posts(where: PostWhere, sort: [PostSort!]!, limit: Int, offset: Int,): [Post!]!
37-
postsAggregate(where: PostWhere): PostAggregationSelection!
38-
39-
users(where: UserWhere, sort: [UserSort!]!, limit: Int, offset: Int,): [User!]!
40-
usersAggregate(where: UserWhere): UserAggregationSelection!
36+
postsConnection(first: Int, after: String, where: PostWhere, sort: [PostSort!]): PostsConnection!
37+
posts(where: PostWhere, limit: Int, offset: Int, sort: [PostSort!]): [Post!]!
38+
usersConnection(first: Int, after: String, where: UserWhere, sort: [UserSort!]): UsersConnection!
39+
users(where: UserWhere, limit: Int, offset: Int, sort: [UserSort!]): [User!]!
4140
}
4241
----
4342

@@ -60,12 +59,12 @@ query {
6059
[source, graphql, indent=0]
6160
----
6261
query {
63-
users(where: { name_EQ: "Jane Smith" }) {
64-
id
65-
name
66-
posts {
67-
content
68-
}
62+
users(where: { name: { eq: "Jane Smith" } }) {
63+
id
64+
name
65+
posts {
66+
content
6967
}
68+
}
7069
}
7170
----

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

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@ Using this example type definition:
1313
type Movie @node {
1414
title: String!
1515
runtime: Int!
16+
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN)
17+
}
18+
19+
type Actor @node {
20+
surname: String!
21+
movies: [Movie!]! @relationship(type: "ACTED_IN", direction: OUT)
1622
}
1723
----
1824

19-
The following sorting input type and query are generated:
25+
The following sorting input type and query are generated for the type `Movie`:
2026

2127
[source, graphql, indent=0]
2228
----
@@ -36,7 +42,7 @@ input MovieSort {
3642
}
3743
3844
type Query {
39-
movies(where: MovieWhere, sort: [MovieSort!], limit: Int, offset: Int): [Movie!]!
45+
movies(where: MovieWhere, limit: Int, offset: Int, sort: [MovieSort!]): [Movie!]!
4046
}
4147
----
4248

@@ -45,15 +51,10 @@ The following query fetches all movies sorted by runtime in ascending order:
4551
[source, graphql, indent=0]
4652
----
4753
query {
48-
movies(sort: [
49-
{
50-
runtime: ASC
51-
}
52-
]
53-
) {
54-
title
55-
runtime
56-
}
54+
movies(sort: [{ runtime: ASC }]) {
55+
title
56+
runtime
57+
}
5758
}
5859
----
5960

@@ -62,19 +63,15 @@ If there is a relationship between the `Movie` and an `Actor` type, you can also
6263
[source, graphql, indent=0]
6364
----
6465
query {
65-
movies {
66-
title
67-
runtime
68-
actors(sort: [
69-
{
70-
surname: ASC
71-
}
72-
]
73-
) {
74-
surname
75-
}
66+
movies {
67+
title
68+
runtime
69+
actors(sort: [{ surname: ASC }]) {
70+
surname
7671
}
72+
}
7773
}
74+
7875
----
7976

8077
[CAUTION]

0 commit comments

Comments
 (0)