Skip to content

Commit

Permalink
fix: Caching per cube iri in geo queries
Browse files Browse the repository at this point in the history
  • Loading branch information
bprusinowski committed Jul 8, 2024
1 parent 5592973 commit 330039a
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 65 deletions.
8 changes: 5 additions & 3 deletions app/charts/map/chart-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ export const ChartMapVisualization = (props: VisualizationProps<MapConfig>) => {
},
] = useDataCubeDimensionGeoShapesQuery({
variables: {
// FIXME: This assumes that there is only one cube.
cubeIri: chartConfig.cubes[0].iri,
dimensionIri: geoShapesIri!,
sourceType: dataSource.type,
sourceUrl: dataSource.url,
locale,
cubeFilter: {
// FIXME: This assumes that there is only one cube.
iri: chartConfig.cubes[0].iri,
dimensionIri: geoShapesIri!,
},
},
pause: !geoShapesIri || geoShapesIri === "",
});
Expand Down
94 changes: 46 additions & 48 deletions app/graphql/queries/data-cubes.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
query SearchPage($sourceType: String!, $sourceUrl: String!, $locale: String!) {
allTermsets(sourceType: $sourceType, sourceUrl: $sourceUrl, locale: $locale) {
count
termset
}
}

query SearchCubes(
$sourceType: String!
$sourceUrl: String!
$locale: String!
$query: String
$order: SearchCubeResultOrder
$includeDrafts: Boolean
$filters: [SearchCubeFilter!]
) {
searchCubes(
sourceType: $sourceType
sourceUrl: $sourceUrl
locale: $locale
query: $query
order: $order
includeDrafts: $includeDrafts
filters: $filters
) {
highlightedTitle
highlightedDescription
cube
}
}

query DataCubeLatestIri(
$sourceType: String!
$sourceUrl: String!
Expand All @@ -24,6 +55,20 @@ query DataCubeComponents(
)
}

query DataCubeDimensionGeoShapes(
$sourceType: String!
$sourceUrl: String!
$locale: String!
$cubeFilter: DataCubeDimensionGeoShapesCubeFilter!
) {
dataCubeDimensionGeoShapes(
sourceType: $sourceType
sourceUrl: $sourceUrl
locale: $locale
cubeFilter: $cubeFilter
)
}

query DataCubeMetadata(
$sourceType: String!
$sourceUrl: String!
Expand All @@ -45,10 +90,10 @@ query DataCubeComponentTermsets(
$cubeFilter: DataCubeTermsetFilter!
) {
dataCubeComponentTermsets(
cubeFilter: $cubeFilter
sourceType: $sourceType
sourceUrl: $sourceUrl
locale: $locale
cubeFilter: $cubeFilter
)
}

Expand Down Expand Up @@ -80,30 +125,6 @@ query DataCubePreview(
)
}

query SearchCubes(
$sourceType: String!
$sourceUrl: String!
$locale: String!
$query: String
$order: SearchCubeResultOrder
$includeDrafts: Boolean
$filters: [SearchCubeFilter!]
) {
searchCubes(
sourceType: $sourceType
sourceUrl: $sourceUrl
locale: $locale
query: $query
order: $order
includeDrafts: $includeDrafts
filters: $filters
) {
highlightedTitle
highlightedDescription
cube
}
}

query PossibleFilters(
$sourceType: String!
$sourceUrl: String!
Expand All @@ -119,26 +140,3 @@ query PossibleFilters(
value
}
}

query DataCubeDimensionGeoShapes(
$cubeIri: String!
$dimensionIri: String!
$sourceType: String!
$sourceUrl: String!
$locale: String!
) {
dataCubeDimensionGeoShapes(
cubeIri: $cubeIri
dimensionIri: $dimensionIri
sourceType: $sourceType
sourceUrl: $sourceUrl
locale: $locale
)
}

query SearchPage($sourceType: String!, $sourceUrl: String!, $locale: String!) {
allTermsets(sourceType: $sourceType, sourceUrl: $sourceUrl, locale: $locale) {
count
termset
}
}
16 changes: 9 additions & 7 deletions app/graphql/query-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export type DataCubeComponentFilter = {
};


export type DataCubeDimensionGeoShapesCubeFilter = {
iri: Scalars['String'];
dimensionIri: Scalars['String'];
};

export type DataCubeLatestIriFilter = {
iri: Scalars['String'];
};
Expand Down Expand Up @@ -197,11 +202,10 @@ export type QuerySearchCubesArgs = {


export type QueryDataCubeDimensionGeoShapesArgs = {
cubeIri: Scalars['String'];
dimensionIri: Scalars['String'];
sourceType: Scalars['String'];
sourceUrl: Scalars['String'];
locale: Scalars['String'];
cubeFilter: DataCubeDimensionGeoShapesCubeFilter;
};


Expand Down Expand Up @@ -357,11 +361,10 @@ export type PossibleFiltersQueryVariables = Exact<{
export type PossibleFiltersQuery = { __typename: 'Query', possibleFilters: Array<{ __typename: 'ObservationFilter', iri: string, type: string, value?: Maybe<any> }> };

export type DataCubeDimensionGeoShapesQueryVariables = Exact<{
cubeIri: Scalars['String'];
dimensionIri: Scalars['String'];
sourceType: Scalars['String'];
sourceUrl: Scalars['String'];
locale: Scalars['String'];
cubeFilter: DataCubeDimensionGeoShapesCubeFilter;
}>;


Expand Down Expand Up @@ -499,13 +502,12 @@ export function usePossibleFiltersQuery(options: Omit<Urql.UseQueryArgs<Possible
return Urql.useQuery<PossibleFiltersQuery>({ query: PossibleFiltersDocument, ...options });
};
export const DataCubeDimensionGeoShapesDocument = gql`
query DataCubeDimensionGeoShapes($cubeIri: String!, $dimensionIri: String!, $sourceType: String!, $sourceUrl: String!, $locale: String!) {
query DataCubeDimensionGeoShapes($sourceType: String!, $sourceUrl: String!, $locale: String!, $cubeFilter: DataCubeDimensionGeoShapesCubeFilter!) {
dataCubeDimensionGeoShapes(
cubeIri: $cubeIri
dimensionIri: $dimensionIri
sourceType: $sourceType
sourceUrl: $sourceUrl
locale: $locale
cubeFilter: $cubeFilter
)
}
`;
Expand Down
12 changes: 9 additions & 3 deletions app/graphql/resolver-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export type DataCubeComponentFilter = {
};


export type DataCubeDimensionGeoShapesCubeFilter = {
iri: Scalars['String'];
dimensionIri: Scalars['String'];
};

export type DataCubeLatestIriFilter = {
iri: Scalars['String'];
};
Expand Down Expand Up @@ -197,11 +202,10 @@ export type QuerySearchCubesArgs = {


export type QueryDataCubeDimensionGeoShapesArgs = {
cubeIri: Scalars['String'];
dimensionIri: Scalars['String'];
sourceType: Scalars['String'];
sourceUrl: Scalars['String'];
locale: Scalars['String'];
cubeFilter: DataCubeDimensionGeoShapesCubeFilter;
};


Expand Down Expand Up @@ -346,6 +350,7 @@ export type ResolversTypes = ResolversObject<{
String: ResolverTypeWrapper<Scalars['String']>;
Boolean: ResolverTypeWrapper<Scalars['Boolean']>;
DataCubeComponents: ResolverTypeWrapper<Scalars['DataCubeComponents']>;
DataCubeDimensionGeoShapesCubeFilter: DataCubeDimensionGeoShapesCubeFilter;
DataCubeLatestIriFilter: DataCubeLatestIriFilter;
DataCubeMetadata: ResolverTypeWrapper<Scalars['DataCubeMetadata']>;
DataCubeMetadataFilter: DataCubeMetadataFilter;
Expand Down Expand Up @@ -391,6 +396,7 @@ export type ResolversParentTypes = ResolversObject<{
String: Scalars['String'];
Boolean: Scalars['Boolean'];
DataCubeComponents: Scalars['DataCubeComponents'];
DataCubeDimensionGeoShapesCubeFilter: DataCubeDimensionGeoShapesCubeFilter;
DataCubeLatestIriFilter: DataCubeLatestIriFilter;
DataCubeMetadata: Scalars['DataCubeMetadata'];
DataCubeMetadataFilter: DataCubeMetadataFilter;
Expand Down Expand Up @@ -496,7 +502,7 @@ export type QueryResolvers<ContextType = VisualizeGraphQLContext, ParentType ext
dataCubePreview?: Resolver<ResolversTypes['DataCubePreview'], ParentType, ContextType, RequireFields<QueryDataCubePreviewArgs, 'sourceType' | 'sourceUrl' | 'locale' | 'cubeFilter'>>;
possibleFilters?: Resolver<Array<ResolversTypes['ObservationFilter']>, ParentType, ContextType, RequireFields<QueryPossibleFiltersArgs, 'sourceType' | 'sourceUrl' | 'cubeFilter'>>;
searchCubes?: Resolver<Array<ResolversTypes['SearchCubeResult']>, ParentType, ContextType, RequireFields<QuerySearchCubesArgs, 'sourceType' | 'sourceUrl'>>;
dataCubeDimensionGeoShapes?: Resolver<Maybe<ResolversTypes['GeoShapes']>, ParentType, ContextType, RequireFields<QueryDataCubeDimensionGeoShapesArgs, 'cubeIri' | 'dimensionIri' | 'sourceType' | 'sourceUrl' | 'locale'>>;
dataCubeDimensionGeoShapes?: Resolver<Maybe<ResolversTypes['GeoShapes']>, ParentType, ContextType, RequireFields<QueryDataCubeDimensionGeoShapesArgs, 'sourceType' | 'sourceUrl' | 'locale' | 'cubeFilter'>>;
allTermsets?: Resolver<Array<ResolversTypes['TermsetCount']>, ParentType, ContextType, RequireFields<QueryAllTermsetsArgs, 'sourceType' | 'sourceUrl' | 'locale'>>;
}>;

Expand Down
5 changes: 3 additions & 2 deletions app/graphql/resolvers/rdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@ export const searchCubes: NonNullable<QueryResolvers["searchCubes"]> = async (

export const dataCubeDimensionGeoShapes: NonNullable<
QueryResolvers["dataCubeDimensionGeoShapes"]
> = async (_, { cubeIri, dimensionIri, locale }, { setup }, info) => {
> = async (_, { locale, cubeFilter }, { setup }, info) => {
const { iri, dimensionIri } = cubeFilter;
const { loaders, sparqlClient, cache } = await setup(info);
const dimension = await getResolvedDimension(dimensionIri, {
cubeIri,
cubeIri: iri,
locale,
sparqlClient,
loaders,
Expand Down
8 changes: 6 additions & 2 deletions app/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ input DataCubePossibleFiltersCubeFilter {
filters: SingleFilters!
}

input DataCubeDimensionGeoShapesCubeFilter {
iri: String!
dimensionIri: String!
}

type TermsetCount {
termset: Termset!
count: Int!
Expand Down Expand Up @@ -183,11 +188,10 @@ type Query {
filters: [SearchCubeFilter!]
): [SearchCubeResult!]!
dataCubeDimensionGeoShapes(
cubeIri: String!
dimensionIri: String!
sourceType: String!
sourceUrl: String!
locale: String!
cubeFilter: DataCubeDimensionGeoShapesCubeFilter!
): GeoShapes
allTermsets(
sourceType: String!
Expand Down

0 comments on commit 330039a

Please sign in to comment.