Menu

1 / 3

Filtering GraphQL results after LIMIT showed a user 0 of their 50 projects

DEV Community: postgres·Muhammad Adnan·10 days ago
#7G1pB6nn
#devtopostgresql#devto#dev#projects#rows
Reading 0:00
15s threshold

Here is a permission check that looks responsible and quietly breaks pagination:

projects : async ( _ , { first , after }, ctx ) => { const { rows } = await ctx . db . query ( ' SELECT * FROM projects WHERE id > $1 ORDER BY id LIMIT $2 ' , [ after ?? 0 , first + 1 ], ); const visible = rows . filter (( p ) => canSee ( ctx . userId , p )); // permission check return toConnection ( visible , first ); }

Enter fullscreen mode

Exit fullscreen mode

The query fetches a page, then the resolver removes what the viewer may not see. Nothing leaks in the response. Each row is checked. Code review usually lets it through.

I measured what it does to a real user.

The setup

PostgreSQL 16, 10,000 projects. The viewer is a member of 50 of them, picked at random. The client asks for first: 20 and keeps paging while hasNextPage is true, like any Relay or Apollo client.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.