From a5ced784135aa9738971fd086cfbac7248f51714 Mon Sep 17 00:00:00 2001 From: Brendan D Date: Tue, 18 Jun 2024 20:13:35 +0200 Subject: [PATCH] feat: add getDatasets --- src/api.ts | 38 +++++++++++++++++++++++++++++++++++ tests/integration/api.test.ts | 9 +++++++++ 2 files changed, 47 insertions(+) diff --git a/src/api.ts b/src/api.ts index 28f256a..56ccb18 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1405,6 +1405,44 @@ export class API { } // Dataset + + /** + * List all datasets in the platform. + * + * @returns The names and ids of all datasets. + */ + public async getDatasets(): Promise<{ id: string; name: string }[]> { + const query = `query GetDatasets ($after: ID) { + datasets( + after: $after + first: 100 + ) { + edges { + node { + id + name + } + } + pageInfo { + endCursor + hasNextPage + } + } + }`; + + const items: { id: string; name: string }[] = []; + + let cursor = null; + do { + const result = await this.makeGqlCall(query, { after: cursor }); + const { pageInfo, edges } = result.data.datasets; + cursor = pageInfo.hasNextPage ? pageInfo.endCursor : null; + items.push(...edges.map((edge: any) => edge.node)); + } while (cursor); + + return items; + } + /** * Creates a new dataset in the database. * diff --git a/tests/integration/api.test.ts b/tests/integration/api.test.ts index 905688f..b805080 100644 --- a/tests/integration/api.test.ts +++ b/tests/integration/api.test.ts @@ -375,6 +375,15 @@ describe('End to end tests for the SDK', function () { }); describe('dataset api', () => { + it('should list datasets', async () => { + const list = await client.api.getDatasets(); + expect(list).toBeInstanceOf(Array); + expect(list[0]).toEqual({ + id: expect.any(String), + name: expect.any(String) + }); + }); + it('should create a dataset', async () => { const datasetName = `test_${uuidv4()}`; const dataset = await client.api.createDataset({