Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Rewrite infinite queries to be consist using undefined over null #3637

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ const RequestSchema = z.object({
})

const query = `query InfiniteAccountOrganizations(
$owner: String!,
$after: String,
$first: Int!,
$owner: String!,
$after: String,
$first: Int!,
$direction: OrderingDirection!
) {
owner(username: $owner) {
Expand Down Expand Up @@ -85,15 +85,17 @@ export function InfiniteAccountOrganizationsQueryOpts({

return infiniteQueryOptionsV5({
queryKey: ['InfiniteAccountOrganizations', provider, owner, variables],
queryFn: ({ pageParam, signal }) =>
Api.graphql({
queryFn: ({ pageParam, signal }) => {
const after = pageParam ? pageParam : undefined

return Api.graphql({
provider,
signal,
query,
variables: {
...variables,
owner,
after: pageParam,
after,
},
}).then((res) => {
const parsedRes = RequestSchema.safeParse(res.data)
Expand Down Expand Up @@ -121,10 +123,11 @@ export function InfiniteAccountOrganizationsQueryOpts({
organizations: mapEdges(account.organizations),
pageInfo: account.organizations.pageInfo,
}
}),
})
},
initialPageParam: '',
getNextPageParam: (data) => {
return data?.pageInfo?.hasNextPage ? data?.pageInfo?.endCursor : null
return data?.pageInfo?.hasNextPage ? data?.pageInfo?.endCursor : undefined
},
})
}
6 changes: 4 additions & 2 deletions src/services/bundleAnalysis/BundleAssetsQueryOpts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ export const BundleAssetsQueryOpts = ({
orderingDirection,
],
queryFn: ({ signal, pageParam }) => {
const assetsAfter = pageParam ? pageParam : undefined

return Api.graphql({
query,
provider,
Expand All @@ -271,7 +273,7 @@ export const BundleAssetsQueryOpts = ({
dateBefore,
dateAfter,
filters,
assetsAfter: pageParam,
assetsAfter,
ordering,
orderingDirection,
},
Expand Down Expand Up @@ -353,6 +355,6 @@ export const BundleAssetsQueryOpts = ({
// matches the type for initialPageParam.
initialPageParam: '',
getNextPageParam: (data) => {
return data?.pageInfo?.hasNextPage ? data?.pageInfo?.endCursor : null
return data?.pageInfo?.hasNextPage ? data?.pageInfo?.endCursor : undefined
},
})
6 changes: 4 additions & 2 deletions src/services/repos/ReposQueryOpts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,16 @@ function ReposQueryOpts({
return infiniteQueryOptionsV5({
queryKey: ['repos', provider, owner, variables],
queryFn: ({ pageParam, signal }) => {
const after = pageParam === '' ? undefined : pageParam

return Api.graphql({
provider,
query,
signal,
variables: {
...variables,
owner,
after: pageParam === '' ? undefined : pageParam,
after,
},
}).then((res) => {
const parsedRes = RequestSchema.safeParse(res?.data)
Expand All @@ -169,7 +171,7 @@ function ReposQueryOpts({
},
initialPageParam: '',
getNextPageParam: (data) => {
return data?.pageInfo?.hasNextPage ? data.pageInfo.endCursor : null
return data?.pageInfo?.hasNextPage ? data.pageInfo.endCursor : undefined
},
})
}
Expand Down
9 changes: 4 additions & 5 deletions src/services/repos/ReposTeamQueryOpts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,16 @@ function ReposTeamQueryOpts({
return infiniteQueryOptionsV5({
queryKey: ['GetReposTeam', provider, variables, owner],
queryFn: ({ pageParam, signal }) => {
const after = pageParam === '' ? undefined : pageParam

return Api.graphql({
provider,
query,
signal,
variables: {
...variables,
owner,
after: pageParam === '' ? undefined : pageParam,
after,
},
}).then((res) => {
const parsedRes = RequestSchema.safeParse(res?.data)
Expand All @@ -161,10 +163,7 @@ function ReposTeamQueryOpts({
},
initialPageParam: '',
getNextPageParam: (data) => {
if (data?.pageInfo?.hasNextPage) {
return data.pageInfo.endCursor
}
return null
return data?.pageInfo?.hasNextPage ? data.pageInfo.endCursor : undefined
},
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/selfHosted/SelfHostedUserListQueryOpts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const SelfHostedUserListQueryOpts = ({
const { searchParams } = new URL(data.next)
return searchParams.get('page')
}
return null
return undefined
},
})
}
Loading