Skip to content

Commit

Permalink
prevent pagination of arrays in subgraph queries
Browse files Browse the repository at this point in the history
  • Loading branch information
jfschwarz committed Sep 26, 2024
1 parent 3690fa9 commit aab96b4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
18 changes: 14 additions & 4 deletions packages/deployments/src/fetchRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ const QUERY = `
query Role($id: String) {
role(id: $id) {
key
members {
members(first: 1000) {
member {
address
}
}
targets {
targets(first: 1000) {
address
clearance
executionOptions
functions {
functions(first: 1000) {
selector
executionOptions
wildcarded
Expand All @@ -37,7 +37,7 @@ query Role($id: String) {
}
}
}
annotations {
annotations(first: 1000) {
uri
schema
}
Expand Down Expand Up @@ -77,6 +77,10 @@ export const fetchRole = async (
return null
}

assertNoPagination(data.role.members)
assertNoPagination(data.role.targets)
assertNoPagination(data.role.annotations)

return mapGraphQl(data.role)
}

Expand Down Expand Up @@ -105,3 +109,9 @@ const mapGraphQl = (role: any): Role => ({
})
),
})

const assertNoPagination = (data: any[]) => {
if (data.length === 1000) {
throw new Error("Pagination not supported")
}
}
20 changes: 16 additions & 4 deletions packages/deployments/src/fetchRolesMod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ const QUERY = `
owner
avatar
target
roles {
roles(first: 1000) {
key
members {
members(first: 1000) {
member {
address
}
}
targets {
targets(first: 1000) {
address
clearance
executionOptions
functions {
functions(first: 1000) {
selector
wildcarded
executionOptions
Expand Down Expand Up @@ -67,6 +67,12 @@ export const fetchRolesMod = async (
return null
}

assertNoPagination(data.rolesModifier.roles)
for (const role of data.rolesModifier.roles) {
assertNoPagination(role.members)
assertNoPagination(role.targets)
}

return mapGraphQl(data.rolesModifier)
}

Expand Down Expand Up @@ -134,3 +140,9 @@ const mapGraphQlRole = (role: any): RoleSummary => ({
})
),
})

const assertNoPagination = (data: any[]) => {
if (data.length === 1000) {
throw new Error("Pagination not supported")
}
}

0 comments on commit aab96b4

Please sign in to comment.