Add frontend server logic for querying a dataset
This commit is contained in:
parent
92beaa6aaf
commit
b9be26afc5
1 changed files with 44 additions and 12 deletions
|
|
@ -13,18 +13,20 @@ export type Dataset = {
|
|||
description: string;
|
||||
};
|
||||
|
||||
export async function list_datasets(): Promise<Dataset[]> {
|
||||
const query = `
|
||||
query {
|
||||
datasets {
|
||||
id
|
||||
name
|
||||
description
|
||||
}
|
||||
}
|
||||
`;
|
||||
return (await query_graphql<{datasets: Dataset[]}>(query)).datasets;
|
||||
}
|
||||
export type Location = {
|
||||
id: number,
|
||||
name: string,
|
||||
lat: number,
|
||||
lon: number;
|
||||
};
|
||||
|
||||
export type Record = {
|
||||
id: number,
|
||||
dataset_id: number,
|
||||
location_id: number | undefined,
|
||||
timestamp: string,
|
||||
data: string;
|
||||
};
|
||||
|
||||
async function query_graphql<T>(query: string): Promise<T> {
|
||||
const response = await fetch('http://host.containers.internal:3000/graphql', {
|
||||
|
|
@ -47,3 +49,33 @@ async function query_graphql<T>(query: string): Promise<T> {
|
|||
|
||||
return result.data!;
|
||||
}
|
||||
|
||||
export async function list_datasets(): Promise<Dataset[]> {
|
||||
const query = `
|
||||
query {
|
||||
datasets {
|
||||
id
|
||||
name
|
||||
description
|
||||
}
|
||||
}
|
||||
`;
|
||||
return (await query_graphql<{ datasets: Dataset[] }>(query)).datasets;
|
||||
}
|
||||
|
||||
export async function query_dataset(id: string): Promise<Record> {
|
||||
// TODO: Maybe just interpolating the id like this isn't the best way to do it.
|
||||
const query = `
|
||||
query {
|
||||
queryDataset(id: ${id}) {
|
||||
id
|
||||
locationId
|
||||
data
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
return (await query_graphql<{
|
||||
queryDataset: Record,
|
||||
}>(query)).queryDataset;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue