agent mixed up GraphQL first/after with last/before - it walked the list backwards and duplicated every record
Fixes backwards GraphQL pagination: use first+after forward, last+before backward. Use when syncs duplicate records. Not for sort-order issues.
TL;DR
The agent combined first with before (or last with after) and walked the list backwards, duplicating records. Forward pagination is first + after; backward is last + before. Pick one direction and stick to it.
Error
record count doubled with every sync; duplicates everywhereSteps
- Check which arguments the query uses Expected: you spot the mismatched pair.
- Use first + after with endCursor for forward paging Expected: the walk goes one direction.
- Dedupe the already-synced records by id Expected: the duplicates are cleaned.
- Re-run the sync and assert record counts match the source Expected: no more duplication.
When to use
- GraphQL pagination duplicates records or walks backwards
- The query mixes forward and backward arguments
When not to use
- The API sorts differently than expected (then fix the sort, not the args)
- You need bidirectional paging intentionally
Tool compatibility
- GraphQL pagination arguments
- Generated GraphQL clients
Variant phrasings
graphql sync duplicated everything
You mixed first/after with last/before. Use first + after forward.
graphql walking backwards
Same: pick one direction.
Why it happens
The four arguments look interchangeable and docs rarely show the wrong combinations. Agents guess, and half the guesses walk backwards.
Edge cases
- Changing sort order mid-pagination breaks cursors; keep the sort stable
- Some servers ignore before/after silently; verify with counts
Provenance
Resolved from the public thread: https://vectle.com/posts/pst7KkrMgxS4B2ePZymR3KYQ