catalog-client: move cursors to pageinfo

Signed-off-by: Vincenzo Scamporlino <vincenzos@spotify.com>
This commit is contained in:
Vincenzo Scamporlino
2023-02-03 10:55:36 +01:00
parent 9ccbf8a08d
commit 0df4da9e71
3 changed files with 18 additions and 17 deletions
@@ -310,8 +310,8 @@ describe('CatalogClient', () => {
const response = await client.queryEntities({}, { token });
expect(response?.entities).toEqual(defaultClientResponse.entities);
expect(response?.totalItems).toEqual(defaultClientResponse.totalItems);
expect(response?.nextCursor).toBeDefined();
expect(response?.prevCursor).toBeDefined();
expect(response?.pageInfo.nextCursor).toBeDefined();
expect(response?.pageInfo.prevCursor).toBeDefined();
});
it('builds multiple entity search filters properly', async () => {
@@ -429,15 +429,15 @@ describe('CatalogClient', () => {
});
expect(mockedEndpoint.mock.calls[0][0].url.search).toBe('?limit=2');
expect(response?.nextCursor).toBeDefined();
expect(response?.prevCursor).toBeDefined();
expect(response?.pageInfo.nextCursor).toBeDefined();
expect(response?.pageInfo.prevCursor).toBeDefined();
await client.queryEntities({ cursor: response!.nextCursor! });
await client.queryEntities({ cursor: response!.pageInfo.nextCursor! });
expect(mockedEndpoint.mock.calls[1][0].url.search).toBe(
'?cursor=nextcursor',
);
await client.queryEntities({ cursor: response!.prevCursor! });
await client.queryEntities({ cursor: response!.pageInfo.prevCursor! });
expect(mockedEndpoint.mock.calls[2][0].url.search).toBe(
'?cursor=prevcursor',
);
+6 -7
View File
@@ -210,7 +210,7 @@ export class CatalogClient implements CatalogApi {
async queryEntities(
request: QueryEntitiesRequest = {},
options?: CatalogRequestOptions,
): Promise<QueryEntitiesResponse> {
) {
const params: string[] = [];
if (isQueryEntitiesInitialRequest(request)) {
@@ -246,12 +246,11 @@ export class CatalogClient implements CatalogApi {
}
const query = params.length ? `?${params.join('&')}` : '';
return this.requestRequired<{
entities: Entity[];
totalItems: number;
nextCursor?: string;
prevCursor?: string;
}>('GET', `/entities/by-query${query}`, options);
return this.requestRequired<QueryEntitiesResponse>(
'GET',
`/entities/by-query${query}`,
options,
);
}
/**
+6 -4
View File
@@ -427,10 +427,12 @@ export type QueryEntitiesResponse = {
entities: Entity[];
/* The number of entities among all the requests */
totalItems: number;
/* The cursor for the next batch of entities */
nextCursor?: string;
/* The cursor for the previous batch of entities */
prevCursor?: string;
pageInfo: {
/* The cursor for the next batch of entities */
nextCursor?: string;
/* The cursor for the previous batch of entities */
prevCursor?: string;
};
};
/**