Skip to content

Commit 3edead6

Browse files
committed
add offset failure states
1 parent 63d3ed5 commit 3edead6

File tree

9 files changed

+502
-0
lines changed

9 files changed

+502
-0
lines changed

src/builder.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,9 @@ where
13981398
return Err("\"first\" may only be used with \"after\"".to_string());
13991399
} else if last.is_some() && after.is_some() {
14001400
return Err("\"last\" may only be used with \"before\"".to_string());
1401+
} else if offset.is_some() && (last.is_some() || before.is_some()) {
1402+
// Only support forward pagination with offset
1403+
return Err("\"offset\" may only be used with \"first\" and \"after\"".to_string());
14011404
}
14021405

14031406
let filter: FilterBuilder =

src/transpile.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ impl MutationEntrypoint<'_> for UpdateBuilder {
463463
select
464464
case
465465
when total.total_count > {at_most} then graphql.exception($a$update impacts too many records$a$)::jsonb
466+
else req.res
466467
467468
468469
end

test/expected/function_calls.out

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,6 +2078,14 @@ begin;
20782078
"ofType": null +
20792079
} +
20802080
}, +
2081+
{ +
2082+
"name": "offset", +
2083+
"type": { +
2084+
"kind": "SCALAR", +
2085+
"name": "Int", +
2086+
"ofType": null +
2087+
} +
2088+
}, +
20812089
{ +
20822090
"name": "filter", +
20832091
"type": { +
@@ -2198,6 +2206,14 @@ begin;
21982206
"ofType": null +
21992207
} +
22002208
}, +
2209+
{ +
2210+
"name": "offset", +
2211+
"type": { +
2212+
"kind": "SCALAR", +
2213+
"name": "Int", +
2214+
"ofType": null +
2215+
} +
2216+
}, +
22012217
{ +
22022218
"name": "filter", +
22032219
"type": { +

test/expected/function_calls_unsupported.out

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,12 @@ begin;
336336
"name": "Cursor" +
337337
} +
338338
}, +
339+
{ +
340+
"name": "offset", +
341+
"type": { +
342+
"name": "Int" +
343+
} +
344+
}, +
339345
{ +
340346
"name": "filter", +
341347
"type": { +

test/expected/page_info.out

Lines changed: 267 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,4 +416,271 @@ begin;
416416
}
417417
(1 row)
418418

419+
-- OFFSET ARG
420+
-- Only supported for forward pagination
421+
-- hasPreviousPage is false, hasNextPage is true
422+
select jsonb_pretty(
423+
graphql.resolve($$
424+
{
425+
accountCollection(first: 2, offset: 0) {
426+
pageInfo {
427+
hasNextPage
428+
hasPreviousPage
429+
startCursor
430+
endCursor
431+
}
432+
edges {
433+
cursor
434+
node {
435+
id
436+
}
437+
}
438+
}
439+
}
440+
$$)
441+
);
442+
jsonb_pretty
443+
------------------------------------------
444+
{ +
445+
"data": { +
446+
"accountCollection": { +
447+
"edges": [ +
448+
{ +
449+
"node": { +
450+
"id": 1 +
451+
}, +
452+
"cursor": "WzFd" +
453+
}, +
454+
{ +
455+
"node": { +
456+
"id": 2 +
457+
}, +
458+
"cursor": "WzJd" +
459+
} +
460+
], +
461+
"pageInfo": { +
462+
"endCursor": "WzJd", +
463+
"hasNextPage": true, +
464+
"startCursor": "WzFd", +
465+
"hasPreviousPage": false+
466+
} +
467+
} +
468+
} +
469+
}
470+
(1 row)
471+
472+
-- hasPreviousPage is true, hasNextPage is true
473+
select jsonb_pretty(
474+
graphql.resolve($$
475+
{
476+
accountCollection(first: 2, offset: 1) {
477+
pageInfo {
478+
hasNextPage
479+
hasPreviousPage
480+
startCursor
481+
endCursor
482+
}
483+
edges {
484+
cursor
485+
node {
486+
id
487+
}
488+
}
489+
}
490+
}
491+
$$)
492+
);
493+
jsonb_pretty
494+
-----------------------------------------
495+
{ +
496+
"data": { +
497+
"accountCollection": { +
498+
"edges": [ +
499+
{ +
500+
"node": { +
501+
"id": 2 +
502+
}, +
503+
"cursor": "WzJd" +
504+
}, +
505+
{ +
506+
"node": { +
507+
"id": 3 +
508+
}, +
509+
"cursor": "WzNd" +
510+
} +
511+
], +
512+
"pageInfo": { +
513+
"endCursor": "WzNd", +
514+
"hasNextPage": true, +
515+
"startCursor": "WzJd", +
516+
"hasPreviousPage": true+
517+
} +
518+
} +
519+
} +
520+
}
521+
(1 row)
522+
523+
-- hasPreviousPage is true, hasNextPage is true
524+
select jsonb_pretty(
525+
graphql.resolve($$
526+
{
527+
accountCollection(
528+
first: 2,
529+
offset: 1,
530+
after: "Wzdd" # id = 7
531+
) {
532+
pageInfo {
533+
hasNextPage
534+
hasPreviousPage
535+
startCursor
536+
endCursor
537+
}
538+
edges {
539+
cursor
540+
node {
541+
id
542+
}
543+
}
544+
}
545+
}
546+
$$)
547+
);
548+
jsonb_pretty
549+
------------------------------------------
550+
{ +
551+
"data": { +
552+
"accountCollection": { +
553+
"edges": [ +
554+
{ +
555+
"node": { +
556+
"id": 9 +
557+
}, +
558+
"cursor": "Wzld" +
559+
}, +
560+
{ +
561+
"node": { +
562+
"id": 10 +
563+
}, +
564+
"cursor": "WzEwXQ=="+
565+
} +
566+
], +
567+
"pageInfo": { +
568+
"endCursor": "WzEwXQ==",+
569+
"hasNextPage": false, +
570+
"startCursor": "Wzld", +
571+
"hasPreviousPage": true +
572+
} +
573+
} +
574+
} +
575+
}
576+
(1 row)
577+
578+
-- hasPreviousPage is true, hasNextPage is false
579+
select jsonb_pretty(
580+
graphql.resolve($$
581+
{
582+
accountCollection(
583+
first: 2,
584+
offset: 2,
585+
after: "Wzdd" # id = 7
586+
) {
587+
pageInfo {
588+
hasNextPage
589+
hasPreviousPage
590+
startCursor
591+
endCursor
592+
}
593+
edges {
594+
cursor
595+
node {
596+
id
597+
}
598+
}
599+
}
600+
}
601+
$$)
602+
);
603+
jsonb_pretty
604+
--------------------------------------------
605+
{ +
606+
"data": { +
607+
"accountCollection": { +
608+
"edges": [ +
609+
{ +
610+
"node": { +
611+
"id": 10 +
612+
}, +
613+
"cursor": "WzEwXQ==" +
614+
} +
615+
], +
616+
"pageInfo": { +
617+
"endCursor": "WzEwXQ==", +
618+
"hasNextPage": false, +
619+
"startCursor": "WzEwXQ==",+
620+
"hasPreviousPage": true +
621+
} +
622+
} +
623+
} +
624+
}
625+
(1 row)
626+
627+
-- Error States
628+
-- Offset doesn't work with "last"
629+
select jsonb_pretty(
630+
graphql.resolve($$
631+
{
632+
accountCollection(
633+
last: 2,
634+
offset: 2,
635+
) {
636+
edges {
637+
node {
638+
id
639+
}
640+
}
641+
}
642+
}
643+
$$)
644+
);
645+
jsonb_pretty
646+
-----------------------------------------------------------------------------------
647+
{ +
648+
"data": null, +
649+
"errors": [ +
650+
{ +
651+
"message": "\"offset\" may only be used with \"first\" and \"after\""+
652+
} +
653+
] +
654+
}
655+
(1 row)
656+
657+
-- Offset doesn't work with "before"
658+
select jsonb_pretty(
659+
graphql.resolve($$
660+
{
661+
accountCollection(
662+
last: 2,
663+
offset: 2,
664+
) {
665+
edges {
666+
node {
667+
id
668+
}
669+
}
670+
}
671+
}
672+
$$)
673+
);
674+
jsonb_pretty
675+
-----------------------------------------------------------------------------------
676+
{ +
677+
"data": null, +
678+
"errors": [ +
679+
{ +
680+
"message": "\"offset\" may only be used with \"first\" and \"after\""+
681+
} +
682+
] +
683+
}
684+
(1 row)
685+
419686
rollback;

test/expected/resolve_connection_offset.out

Whitespace-only changes.

0 commit comments

Comments
 (0)