Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Make all queries traceable (DebugPanel) #1264

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/charts/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ColumnConfig, TableFields } from "@/configurator";
import { ComponentsQuery } from "@/graphql/query-hooks";
import { DataCubeMetadata } from "@/graphql/types";
import { RDFCubeViewQueryMock } from "@/test/cube-view-query-mock";

import bathingWaterData from "../test/__fixtures/data/DataCubeMetadataWithComponentValues-bathingWater.json";
import forestAreaData from "../test/__fixtures/data/forest-area-by-production-region.json";
Expand All @@ -11,6 +12,8 @@ import {
getPossibleChartTypes,
} from "./index";

RDFCubeViewQueryMock;
Copy link
Collaborator Author

@bprusinowski bprusinowski Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a nicer way of doing this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead ignore the eslint rule that remove it automatically in case of no use, at least the ignore would be at the place of the import and we would directly understand it.


describe("initial config", () => {
it("should create an initial table config with column order based on dimension order", () => {
const config = getInitialConfig({
Expand Down
3 changes: 3 additions & 0 deletions app/charts/shared/chart-helpers.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import { Observation } from "@/domain/data";
import { InteractiveFiltersState } from "@/stores/interactive-filters";
import map1Fixture from "@/test/__fixtures/config/int/map-nfi.json";
import line1Fixture from "@/test/__fixtures/config/prod/line-1.json";
import { RDFCubeViewQueryMock } from "@/test/cube-view-query-mock";

RDFCubeViewQueryMock;

const makeCubeNsGetters = (cubeIri: string) => ({
col: (col: string) => `${cubeIri}/dimension/${col}`,
Expand Down
3 changes: 3 additions & 0 deletions app/configurator/components/field.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { fireEvent, render } from "@testing-library/react";

import { TimeInput } from "@/configurator/components/field";
import { getD3TimeFormatLocale } from "@/locales/locales";
import { RDFCubeViewQueryMock } from "@/test/cube-view-query-mock";

RDFCubeViewQueryMock;

describe("TimeInput", () => {
const expectedValue = "2020-05-24";
Expand Down
3 changes: 3 additions & 0 deletions app/configurator/components/filters.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { TemporalDimension, TimeUnit } from "@/graphql/resolver-types";
import { getD3TimeFormatLocale } from "@/locales/locales";
import { RDFCubeViewQueryMock } from "@/test/cube-view-query-mock";

import { getTimeFilterOptions } from "./filters";

RDFCubeViewQueryMock;

describe("TimeFilter", () => {
const dimension = {
timeFormat: "%Y",
Expand Down
3 changes: 3 additions & 0 deletions app/configurator/configurator-state.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import covid19TableChartConfig from "@/test/__fixtures/config/dev/chartConfig-ta
import { data as fakeVizFixture } from "@/test/__fixtures/config/prod/line-1.json";
import bathingWaterMetadata from "@/test/__fixtures/data/DataCubeMetadataWithComponentValues-bathingWater.json";
import covid19Metadata from "@/test/__fixtures/data/DataCubeMetadataWithComponentValues-covid19.json";
import { RDFCubeViewQueryMock } from "@/test/cube-view-query-mock";
import * as api from "@/utils/chart-config/api";
import {
migrateChartConfig,
Expand All @@ -45,6 +46,8 @@ import {

const mockedApi = api as jest.Mocked<typeof api>;

RDFCubeViewQueryMock;

jest.mock("@/utils/chart-config/api", () => ({
fetchChartConfig: jest.fn(),
}));
Expand Down
12 changes: 5 additions & 7 deletions app/graphql/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import { RequestQueryMeta } from "./query-meta";

export const MAX_BATCH_SIZE = 500;

export const getRawCube = async (sourceUrl: string, iri: string) => {
const source = createSource({ endpointUrl: sourceUrl });
export const getRawCube = async (sparqlClient: ParsingClient, iri: string) => {
const source = createSource(sparqlClient);
const cube = new ExtendedCube({
parent: source,
term: rdf.namedNode(iri),
Expand All @@ -48,11 +48,11 @@ export const getRawCube = async (sourceUrl: string, iri: string) => {
// 60_000
// );

const createCubeLoader = (sourceUrl: string) => {
const createCubeLoader = (sparqlClient: ParsingClient) => {
return (cubeIris: readonly string[]) => {
return Promise.all(
cubeIris.map(async (iri) => {
return getRawCube(sourceUrl, iri);
return getRawCube(sparqlClient, iri);
})
);
};
Expand All @@ -62,11 +62,10 @@ const createLoaders = async (
locale: string,
sparqlClient: ParsingClient,
geoSparqlClient: ParsingClient,
sourceUrl: string,
cache: LRUCache | undefined
) => {
return {
cube: new DataLoader(createCubeLoader(sourceUrl)),
cube: new DataLoader(createCubeLoader(sparqlClient)),
dimensionValues: new DataLoader(
createCubeDimensionValuesLoader(sparqlClient, cache),
{
Expand Down Expand Up @@ -181,7 +180,6 @@ const createContextContent = async ({
locale,
sparqlClient,
geoSparqlClient,
sourceUrl,
contextCache
);

Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"postgres-migrations": "^5.2.0",
"prisma": "^4.5.0",
"qs": "^6.10.1",
"rdf-cube-view-query": "^1.12.0",
"rdf-cube-view-query": "^2.1.0",
"rdf-ext": "^1.3.2",
"react-beautiful-dnd": "^13.1.1",
"react-error-boundary": "^3.1.3",
Expand Down
7 changes: 2 additions & 5 deletions app/pages/_cube-checker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ const describeCubes = async (

const getCubeDimensions = async (
sparqlClient: ParsingClient,
sourceUrl: string,
cubeIris: readonly string[]
) => {
return Promise.all(
cubeIris.map(async (cubeIri) => {
const rawCube = await getRawCube(sourceUrl, cubeIri);
const rawCube = await getRawCube(sparqlClient, cubeIri);

if (rawCube) {
return await _getCubeDimensions({
Expand Down Expand Up @@ -386,9 +385,7 @@ export const getServerSideProps: GetServerSideProps = async ({ query }) => {
string,
ResolvedDimension[] | undefined,
unknown
>((cubeIri) =>
getCubeDimensions(sparqlClient, datasource.url, cubeIri)
),
>((cubeIri) => getCubeDimensions(sparqlClient, cubeIri)),
},
};
const runCheck = async (check: Check) => {
Expand Down
5 changes: 3 additions & 2 deletions app/rdf/create-source.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Source } from "rdf-cube-view-query";
import rdf from "rdf-ext";
import ParsingClient from "sparql-http-client/ParsingClient";

export const pragmas = `#pragma describe.strategy cbd
#pragma join.hash off
`;

export const createSource = ({ endpointUrl }: { endpointUrl: string }) => {
export const createSource = (sparqlClient: ParsingClient) => {
return new Source({
endpointUrl,
client: sparqlClient,
queryOperation: "postUrlencoded",
queryPrefix: pragmas,
sourceGraph: rdf.defaultGraph(),
Expand Down
11 changes: 11 additions & 0 deletions app/test/cube-view-query-mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const RDFCubeViewQueryMock = jest.mock("rdf-cube-view-query", () => ({
Node: class {
constructor() {}
},
Source: class {
constructor() {}
},
Cube: class {
constructor() {}
},
}));
14 changes: 10 additions & 4 deletions app/typings/rdf.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,20 @@ declare module "rdf-cube-view-query" {
}

export type SourceOptions = NodeInit & {
endpointUrl: string;
sourceGraph?: string | DefaultGraphExt;
user?: string;
password?: string;
queryOperation?: "get" | "postUrlencoded" | "postDirect";
queryPrefix?: string;
term?: Term;
};
} & (
| {
endpointUrl: string;
user?: string;
password?: string;
}
| {
client?: ParsingClient;
}
);
export class Source extends Node {
constructor(options: SourceOptions);
async cube(term: Term | string): Promise<Cube | null>;
Expand Down
Loading
Loading