Skip to content

Commit

Permalink
feat: Unversion cube iri for LightCube
Browse files Browse the repository at this point in the history
...as the DataCubePreview will be re-used in #1890
  • Loading branch information
bprusinowski committed Nov 20, 2024
1 parent 04eeb38 commit 61535ba
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
15 changes: 12 additions & 3 deletions app/graphql/resolvers/rdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,10 @@ export const dataCubeComponentTermsets: NonNullable<
> = async (_, { locale, cubeFilter }, { setup }, info) => {
const { sparqlClient } = await setup(info);
const { iri } = cubeFilter;
const cube = new LightCube({ iri, locale, sparqlClient });
const unversionedIri =
(await queryCubeUnversionedIri(sparqlClient, iri)) ?? iri;
const cube = new LightCube({ iri, unversionedIri, locale, sparqlClient });

return await cube.fetchComponentTermsets();
};

Expand All @@ -397,7 +400,10 @@ export const dataCubeMetadata: NonNullable<
> = async (_, { locale, cubeFilter }, { setup }, info) => {
const { sparqlClient } = await setup(info);
const { iri } = cubeFilter;
const cube = new LightCube({ iri, locale, sparqlClient });
const unversionedIri =
(await queryCubeUnversionedIri(sparqlClient, iri)) ?? iri;
const cube = new LightCube({ iri, unversionedIri, locale, sparqlClient });

return await cube.fetchMetadata();
};

Expand Down Expand Up @@ -445,7 +451,10 @@ export const dataCubePreview: NonNullable<
> = async (_, { locale, cubeFilter }, { setup }, info) => {
const { sparqlClient } = await setup(info);
const { iri } = cubeFilter;
const cube = new LightCube({ iri, locale, sparqlClient });
const unversionedIri =
(await queryCubeUnversionedIri(sparqlClient, iri)) ?? iri;
const cube = new LightCube({ iri, unversionedIri, locale, sparqlClient });

return await cube.fetchPreview();
};

Expand Down
6 changes: 5 additions & 1 deletion app/rdf/light-cube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {

type LightCubeOptions = {
iri: string;
unversionedIri: string;
locale: string;
sparqlClient: ParsingClient;
};
Expand All @@ -23,15 +24,17 @@ type LightCubeOptions = {
*/
export class LightCube {
public iri: string;
public unversionedIri: string;
private locale: string;
public metadata: DataCubeMetadata | undefined;
public preview: DataCubePreview | undefined;
public components: DataCubeComponents | undefined;
private sparqlClient: ParsingClient;

constructor(options: LightCubeOptions) {
const { iri, locale, sparqlClient } = options;
const { iri, unversionedIri, locale, sparqlClient } = options;
this.iri = iri;
this.unversionedIri = unversionedIri;
this.locale = locale;
this.sparqlClient = sparqlClient;
}
Expand Down Expand Up @@ -61,6 +64,7 @@ export class LightCube {

public async fetchPreview() {
this.preview = await getCubePreview(this.iri, {
unversionedIri: this.unversionedIri,
locale: this.locale,
sparqlClient: this.sparqlClient,
});
Expand Down
4 changes: 2 additions & 2 deletions app/rdf/parse-search-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ function buildSearchCubes(
const dim = bySubjectAndPredicate.get(x.object.value);
return {
iri: stringifyComponentId({
// TODO
// Technically we don't need to unversion the cube iri here, as
// search cubes are temporary and dimensions coming from here
// aren't stored in chart config, but would be nice to be consistent.
// aren't stored in chart config.
// We don't do it due to performance reasons.
unversionedCubeIri: iri,
unversionedComponentIri: x.object.value,
}),
Expand Down
15 changes: 4 additions & 11 deletions app/rdf/query-cube-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ import { buildLocalizedSubQuery } from "./query-utils";
export const getCubePreview = async (
iri: string,
options: {
unversionedIri: string;
locale: string;
sparqlClient: ParsingClient;
}
): Promise<DataCubePreview> => {
const { sparqlClient, locale } = options;
const { unversionedIri, sparqlClient, locale } = options;
const qs = await sparqlClient.query.construct(
`PREFIX cube: <https://cube.link/>
PREFIX meta: <https://cube.link/meta/>
Expand Down Expand Up @@ -228,11 +229,7 @@ CONSTRUCT {
Object.entries(observation).map(([k, v]) => {
return [
stringifyComponentId({
// TODO
// Technically we don't need to unversion the cube iri here, as
// cube preview is temporary and dimensions coming from here
// aren't stored in chart config, but would be nice to be consistent.
unversionedCubeIri: iri,
unversionedCubeIri: unversionedIri,
unversionedComponentIri: k,
}),
v,
Expand Down Expand Up @@ -282,12 +279,8 @@ CONSTRUCT {

const baseComponent: BaseComponent = {
cubeIri: iri,
// TODO
// Technically we don't need to unversion the cube iri here, as
// cube preview is temporary and dimensions coming from here
// aren't stored in chart config, but would be nice to be consistent.
id: stringifyComponentId({
unversionedCubeIri: iri,
unversionedCubeIri: unversionedIri,
unversionedComponentIri: dimIri,
}),
label: qLabel?.object.value ?? "",
Expand Down

0 comments on commit 61535ba

Please sign in to comment.