Skip to content

Commit de396f2

Browse files
authored
Merge pull request #596 from supabase/max_rows_improvements
Max rows improvements
2 parents a899acd + 53b9ac9 commit de396f2

File tree

4 files changed

+230
-35
lines changed

4 files changed

+230
-35
lines changed

docs/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,4 @@
9696

9797
## master
9898
- feature: Add support for aggregate functions (count, sum, avg, min, max) on collection types
99+
- feature: Add support for per table and view `max_row` directives

docs/configuration.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,21 @@ For more fine grained adjustments to reflected names, see [renaming](#renaming).
6060

6161
### Max Rows
6262

63-
The default page size for collections is 30 entries. To adjust the number of entries on each page, set a `max_rows` directive on the relevant schema entity.
63+
The default page size for collections is 30 entries. To adjust the number of entries on each page, set a `max_rows` directive on the relevant schema entity, table or view.
6464

6565
For example, to increase the max rows per page for each table in the `public` schema:
6666
```sql
6767
comment on schema public is e'@graphql({"max_rows": 100})';
6868
```
6969

70+
To limit the max rows per page for the `blog_post` table and `Person` view:
71+
```sql
72+
comment on table blog_post is e'@graphql({"max_rows": 20})';
73+
comment on view "Person" is e'@graphql({"primary_key_columns": ["id"], "max_rows": 10})';
74+
```
75+
76+
The `max_rows` value falls back to the parent object if it is missing on the current object. For example, if a table doesn't have `max_rows` set, the value set on the table's schema will be used. If the schema also doesn't have `max_rows` set, then it falls back to default value 30. The parent object of a view is the schema, not the table on which the view is created.
77+
7078
### totalCount
7179

7280
`totalCount` is an opt-in field that extends a table's Connection type. It provides a count of the rows that match the query's filters, and ignores pagination arguments.

test/expected/max_rows_directive.out

Lines changed: 124 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@ begin;
22
create table account(
33
id int primary key
44
);
5+
create view "accountView" as
6+
select * from account;
7+
comment on view "accountView" is e'@graphql({"primary_key_columns": ["id"]})';
8+
create view "accountViewWrapper" as
9+
select * from "accountView";
10+
comment on view "accountViewWrapper" is e'@graphql({"primary_key_columns": ["id"]})';
511
insert into public.account(id)
612
select * from generate_series(1, 100);
7-
-- expect default 30 rows on first page
13+
-- expect 30 rows on first page because of fallback to default
814
select graphql.resolve($$
915
{
1016
accountCollection
@@ -22,8 +28,42 @@ begin;
2228
{"data": {"accountCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 2}}, {"node": {"id": 3}}, {"node": {"id": 4}}, {"node": {"id": 5}}, {"node": {"id": 6}}, {"node": {"id": 7}}, {"node": {"id": 8}}, {"node": {"id": 9}}, {"node": {"id": 10}}, {"node": {"id": 11}}, {"node": {"id": 12}}, {"node": {"id": 13}}, {"node": {"id": 14}}, {"node": {"id": 15}}, {"node": {"id": 16}}, {"node": {"id": 17}}, {"node": {"id": 18}}, {"node": {"id": 19}}, {"node": {"id": 20}}, {"node": {"id": 21}}, {"node": {"id": 22}}, {"node": {"id": 23}}, {"node": {"id": 24}}, {"node": {"id": 25}}, {"node": {"id": 26}}, {"node": {"id": 27}}, {"node": {"id": 28}}, {"node": {"id": 29}}, {"node": {"id": 30}}]}}}
2329
(1 row)
2430

31+
-- expect 30 rows on first page because of fallback to default
32+
select graphql.resolve($$
33+
{
34+
accountViewCollection {
35+
edges {
36+
node {
37+
id
38+
}
39+
}
40+
}
41+
}
42+
$$);
43+
resolve
44+
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
45+
{"data": {"accountViewCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 2}}, {"node": {"id": 3}}, {"node": {"id": 4}}, {"node": {"id": 5}}, {"node": {"id": 6}}, {"node": {"id": 7}}, {"node": {"id": 8}}, {"node": {"id": 9}}, {"node": {"id": 10}}, {"node": {"id": 11}}, {"node": {"id": 12}}, {"node": {"id": 13}}, {"node": {"id": 14}}, {"node": {"id": 15}}, {"node": {"id": 16}}, {"node": {"id": 17}}, {"node": {"id": 18}}, {"node": {"id": 19}}, {"node": {"id": 20}}, {"node": {"id": 21}}, {"node": {"id": 22}}, {"node": {"id": 23}}, {"node": {"id": 24}}, {"node": {"id": 25}}, {"node": {"id": 26}}, {"node": {"id": 27}}, {"node": {"id": 28}}, {"node": {"id": 29}}, {"node": {"id": 30}}]}}}
46+
(1 row)
47+
48+
-- expect 30 rows on first page because of fallback to default
49+
select graphql.resolve($$
50+
{
51+
accountViewWrapperCollection {
52+
edges {
53+
node {
54+
id
55+
}
56+
}
57+
}
58+
}
59+
$$);
60+
resolve
61+
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
62+
{"data": {"accountViewWrapperCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 2}}, {"node": {"id": 3}}, {"node": {"id": 4}}, {"node": {"id": 5}}, {"node": {"id": 6}}, {"node": {"id": 7}}, {"node": {"id": 8}}, {"node": {"id": 9}}, {"node": {"id": 10}}, {"node": {"id": 11}}, {"node": {"id": 12}}, {"node": {"id": 13}}, {"node": {"id": 14}}, {"node": {"id": 15}}, {"node": {"id": 16}}, {"node": {"id": 17}}, {"node": {"id": 18}}, {"node": {"id": 19}}, {"node": {"id": 20}}, {"node": {"id": 21}}, {"node": {"id": 22}}, {"node": {"id": 23}}, {"node": {"id": 24}}, {"node": {"id": 25}}, {"node": {"id": 26}}, {"node": {"id": 27}}, {"node": {"id": 28}}, {"node": {"id": 29}}, {"node": {"id": 30}}]}}}
63+
(1 row)
64+
2565
comment on schema public is e'@graphql({"max_rows": 5})';
26-
-- expect 5 rows on first page
66+
-- expect 5 rows on first page because of fallback to schema max_rows
2767
select graphql.resolve($$
2868
{
2969
accountCollection
@@ -41,8 +81,42 @@ begin;
4181
{"data": {"accountCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 2}}, {"node": {"id": 3}}, {"node": {"id": 4}}, {"node": {"id": 5}}]}}}
4282
(1 row)
4383

84+
-- expect 5 rows on first page because of fallback to schema max_rows
85+
select graphql.resolve($$
86+
{
87+
accountViewCollection {
88+
edges {
89+
node {
90+
id
91+
}
92+
}
93+
}
94+
}
95+
$$);
96+
resolve
97+
-----------------------------------------------------------------------------------------------------------------------------------------------------------
98+
{"data": {"accountViewCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 2}}, {"node": {"id": 3}}, {"node": {"id": 4}}, {"node": {"id": 5}}]}}}
99+
(1 row)
100+
101+
-- expect 5 rows on first page because of fallback to schema max_rows
102+
select graphql.resolve($$
103+
{
104+
accountViewWrapperCollection {
105+
edges {
106+
node {
107+
id
108+
}
109+
}
110+
}
111+
}
112+
$$);
113+
resolve
114+
------------------------------------------------------------------------------------------------------------------------------------------------------------------
115+
{"data": {"accountViewWrapperCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 2}}, {"node": {"id": 3}}, {"node": {"id": 4}}, {"node": {"id": 5}}]}}}
116+
(1 row)
117+
44118
comment on schema public is e'@graphql({"max_rows": 40})';
45-
-- expect 40 rows on first page
119+
-- expect 40 rows on first page because of fallback to schema max_rows
46120
select graphql.resolve($$
47121
{
48122
accountCollection
@@ -60,9 +134,43 @@ begin;
60134
{"data": {"accountCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 2}}, {"node": {"id": 3}}, {"node": {"id": 4}}, {"node": {"id": 5}}, {"node": {"id": 6}}, {"node": {"id": 7}}, {"node": {"id": 8}}, {"node": {"id": 9}}, {"node": {"id": 10}}, {"node": {"id": 11}}, {"node": {"id": 12}}, {"node": {"id": 13}}, {"node": {"id": 14}}, {"node": {"id": 15}}, {"node": {"id": 16}}, {"node": {"id": 17}}, {"node": {"id": 18}}, {"node": {"id": 19}}, {"node": {"id": 20}}, {"node": {"id": 21}}, {"node": {"id": 22}}, {"node": {"id": 23}}, {"node": {"id": 24}}, {"node": {"id": 25}}, {"node": {"id": 26}}, {"node": {"id": 27}}, {"node": {"id": 28}}, {"node": {"id": 29}}, {"node": {"id": 30}}, {"node": {"id": 31}}, {"node": {"id": 32}}, {"node": {"id": 33}}, {"node": {"id": 34}}, {"node": {"id": 35}}, {"node": {"id": 36}}, {"node": {"id": 37}}, {"node": {"id": 38}}, {"node": {"id": 39}}, {"node": {"id": 40}}]}}}
61135
(1 row)
62136

137+
-- expect 40 rows on first page because of fallback to schema max_rows
138+
select graphql.resolve($$
139+
{
140+
accountViewCollection {
141+
edges {
142+
node {
143+
id
144+
}
145+
}
146+
}
147+
}
148+
$$);
149+
resolve
150+
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
151+
{"data": {"accountViewCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 2}}, {"node": {"id": 3}}, {"node": {"id": 4}}, {"node": {"id": 5}}, {"node": {"id": 6}}, {"node": {"id": 7}}, {"node": {"id": 8}}, {"node": {"id": 9}}, {"node": {"id": 10}}, {"node": {"id": 11}}, {"node": {"id": 12}}, {"node": {"id": 13}}, {"node": {"id": 14}}, {"node": {"id": 15}}, {"node": {"id": 16}}, {"node": {"id": 17}}, {"node": {"id": 18}}, {"node": {"id": 19}}, {"node": {"id": 20}}, {"node": {"id": 21}}, {"node": {"id": 22}}, {"node": {"id": 23}}, {"node": {"id": 24}}, {"node": {"id": 25}}, {"node": {"id": 26}}, {"node": {"id": 27}}, {"node": {"id": 28}}, {"node": {"id": 29}}, {"node": {"id": 30}}, {"node": {"id": 31}}, {"node": {"id": 32}}, {"node": {"id": 33}}, {"node": {"id": 34}}, {"node": {"id": 35}}, {"node": {"id": 36}}, {"node": {"id": 37}}, {"node": {"id": 38}}, {"node": {"id": 39}}, {"node": {"id": 40}}]}}}
152+
(1 row)
153+
154+
-- expect 40 rows on first page because of fallback to schema max_rows
155+
select graphql.resolve($$
156+
{
157+
accountViewWrapperCollection {
158+
edges {
159+
node {
160+
id
161+
}
162+
}
163+
}
164+
}
165+
$$);
166+
resolve
167+
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
168+
{"data": {"accountViewWrapperCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 2}}, {"node": {"id": 3}}, {"node": {"id": 4}}, {"node": {"id": 5}}, {"node": {"id": 6}}, {"node": {"id": 7}}, {"node": {"id": 8}}, {"node": {"id": 9}}, {"node": {"id": 10}}, {"node": {"id": 11}}, {"node": {"id": 12}}, {"node": {"id": 13}}, {"node": {"id": 14}}, {"node": {"id": 15}}, {"node": {"id": 16}}, {"node": {"id": 17}}, {"node": {"id": 18}}, {"node": {"id": 19}}, {"node": {"id": 20}}, {"node": {"id": 21}}, {"node": {"id": 22}}, {"node": {"id": 23}}, {"node": {"id": 24}}, {"node": {"id": 25}}, {"node": {"id": 26}}, {"node": {"id": 27}}, {"node": {"id": 28}}, {"node": {"id": 29}}, {"node": {"id": 30}}, {"node": {"id": 31}}, {"node": {"id": 32}}, {"node": {"id": 33}}, {"node": {"id": 34}}, {"node": {"id": 35}}, {"node": {"id": 36}}, {"node": {"id": 37}}, {"node": {"id": 38}}, {"node": {"id": 39}}, {"node": {"id": 40}}]}}}
169+
(1 row)
170+
63171
-- table-specific max_rows
64172
comment on table account is e'@graphql({"max_rows": 5})';
65-
-- expect 5 rows on first page
173+
-- expect 5 rows on first page because of table max_rows
66174
select graphql.resolve($$
67175
{
68176
accountCollection {
@@ -80,13 +188,11 @@ begin;
80188
(1 row)
81189

82190
-- view-specific max_rows
83-
create view person as
84-
select * from account;
85-
comment on view person is e'@graphql({"primary_key_columns": ["id"], "max_rows": 3})';
86-
-- expect 3 rows on first page
191+
comment on view "accountView" is e'@graphql({"primary_key_columns": ["id"], "max_rows": 3})';
192+
-- expect 3 rows on first page because of view max_rows
87193
select graphql.resolve($$
88194
{
89-
personCollection {
195+
accountViewCollection {
90196
edges {
91197
node {
92198
id
@@ -95,19 +201,17 @@ begin;
95201
}
96202
}
97203
$$);
98-
resolve
99-
------------------------------------------------------------------------------------------------------------
100-
{"data": {"personCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 2}}, {"node": {"id": 3}}]}}}
204+
resolve
205+
-----------------------------------------------------------------------------------------------------------------
206+
{"data": {"accountViewCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 2}}, {"node": {"id": 3}}]}}}
101207
(1 row)
102208

103209
-- nested view with max_rows
104-
create view parent as
105-
select * from person;
106-
comment on view parent is e'@graphql({"primary_key_columns": ["id"], "max_rows": 2})';
107-
-- expect 2 rows on first page
210+
comment on view "accountViewWrapper" is e'@graphql({"primary_key_columns": ["id"], "max_rows": 2})';
211+
-- expect 2 rows on first page because of view max_rows
108212
select graphql.resolve($$
109213
{
110-
parentCollection {
214+
accountViewWrapperCollection {
111215
edges {
112216
node {
113217
id
@@ -116,9 +220,9 @@ begin;
116220
}
117221
}
118222
$$);
119-
resolve
120-
---------------------------------------------------------------------------------------
121-
{"data": {"parentCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 2}}]}}}
223+
resolve
224+
---------------------------------------------------------------------------------------------------
225+
{"data": {"accountViewWrapperCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 2}}]}}}
122226
(1 row)
123227

124228
rollback;

0 commit comments

Comments
 (0)