Make backend and frontend work together well, and add datasets/ page to frontend

This commit is contained in:
Zeph Levy 2026-01-14 11:23:43 +01:00
parent 6f551a83bf
commit 50b670916b
8 changed files with 107 additions and 5 deletions

View file

@ -0,0 +1,49 @@
type GraphQLResponse<T> = {
data?: T;
errors?: Array<{
message: string;
locations?: { line: number; column: number }[];
path?: string[];
}>;
};
export type Dataset = {
id: number;
name: string;
description: string;
};
export async function list_datasets(): Promise<Dataset[]> {
const query = `
query {
datasets {
id
name
description
}
}
`;
const response = await fetch('http://host.containers.internal:3000/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ query }),
});
if (!response.ok) {
throw new Error(`Error - status ${response.status}`);
}
const result = await response.json() as GraphQLResponse<{
datasets: Dataset[];
}>;
if (result.errors) {
throw new Error(result.errors.map(e => e.message).join(', '));
}
return result.data!.datasets;
}