Skip to content

Commit

Permalink
feat: add getDatasets (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
Granipouss authored Jun 20, 2024
1 parent 451446e commit 0d474b6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,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.
*
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,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({
Expand Down

0 comments on commit 0d474b6

Please sign in to comment.