-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backport 5.2] alter function using apollo client to achieve paginati…
…on (#59837) Search contexts: paginate repo names (#58685) A customer reported that search contexts with over a thousand repos were failing when trying to create them. The root cause is that the webapp was fetching repositories to validate them, but was not using pagination, and instead tried to get them all in one go. The backend limits the number of results in a page to 1000, even if the client requests more. Now, the web app pages through results. (cherry picked from commit 4397287) Co-authored-by: Jason Hawk Harris <[email protected]>
- Loading branch information
1 parent
3c0a8b4
commit e70cef8
Showing
3 changed files
with
66 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,48 @@ | ||
import type { Observable } from 'rxjs' | ||
import { map } from 'rxjs/operators' | ||
|
||
import { dataOrThrowErrors, gql } from '@sourcegraph/http-client' | ||
import type { GraphQLResult } from '@sourcegraph/http-client' | ||
|
||
import { requestGraphQL } from '../../backend/graphql' | ||
import type { RepositoriesByNamesResult, RepositoriesByNamesVariables } from '../../graphql-operations' | ||
import type { InputMaybe, RepositoriesByNamesResult, RepositoriesByNamesVariables } from '../../graphql-operations' | ||
|
||
const query = gql` | ||
query RepositoriesByNames($names: [String!]!, $first: Int!, $after: String) { | ||
repositories(names: $names, first: $first, after: $after) { | ||
nodes { | ||
id | ||
name | ||
} | ||
pageInfo { | ||
endCursor | ||
hasNextPage | ||
} | ||
} | ||
} | ||
` | ||
|
||
export function fetchRepositoriesByNames( | ||
export async function fetchRepositoriesByNames( | ||
names: string[] | ||
): Observable<RepositoriesByNamesResult['repositories']['nodes']> { | ||
): Promise<RepositoriesByNamesResult['repositories']['nodes']> { | ||
let repos: RepositoriesByNamesResult['repositories']['nodes'] = [] | ||
const first = names.length | ||
return requestGraphQL<RepositoriesByNamesResult, RepositoriesByNamesVariables>( | ||
gql` | ||
query RepositoriesByNames($names: [String!]!, $first: Int!) { | ||
repositories(names: $names, first: $first) { | ||
nodes { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
`, | ||
{ | ||
let after: InputMaybe<string> = null | ||
|
||
while (true) { | ||
const result: GraphQLResult<RepositoriesByNamesResult> = await requestGraphQL< | ||
RepositoriesByNamesResult, | ||
RepositoriesByNamesVariables | ||
>(query, { | ||
names, | ||
first, | ||
after, | ||
}).toPromise() | ||
|
||
const data: RepositoriesByNamesResult = dataOrThrowErrors(result) | ||
|
||
repos = repos.concat(data.repositories.nodes) | ||
if (!data.repositories.pageInfo.hasNextPage) { | ||
break | ||
} | ||
).pipe( | ||
map(dataOrThrowErrors), | ||
map(data => data.repositories.nodes) | ||
) | ||
after = data.repositories.pageInfo.endCursor | ||
} | ||
return repos | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters