From 330039adedcfefd1e5ef56c90c6adbfb57a46845 Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Mon, 8 Jul 2024 09:58:10 +0200 Subject: [PATCH] fix: Caching per cube iri in geo queries --- app/charts/map/chart-map.tsx | 8 ++- app/graphql/queries/data-cubes.graphql | 94 +++++++++++++------------- app/graphql/query-hooks.ts | 16 +++-- app/graphql/resolver-types.ts | 12 +++- app/graphql/resolvers/rdf.ts | 5 +- app/graphql/schema.graphql | 8 ++- 6 files changed, 78 insertions(+), 65 deletions(-) diff --git a/app/charts/map/chart-map.tsx b/app/charts/map/chart-map.tsx index e560c1571..62bba7f41 100644 --- a/app/charts/map/chart-map.tsx +++ b/app/charts/map/chart-map.tsx @@ -76,12 +76,14 @@ export const ChartMapVisualization = (props: VisualizationProps) => { }, ] = 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 === "", }); diff --git a/app/graphql/queries/data-cubes.graphql b/app/graphql/queries/data-cubes.graphql index 65593556d..291e6f307 100644 --- a/app/graphql/queries/data-cubes.graphql +++ b/app/graphql/queries/data-cubes.graphql @@ -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! @@ -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! @@ -45,10 +90,10 @@ query DataCubeComponentTermsets( $cubeFilter: DataCubeTermsetFilter! ) { dataCubeComponentTermsets( - cubeFilter: $cubeFilter sourceType: $sourceType sourceUrl: $sourceUrl locale: $locale + cubeFilter: $cubeFilter ) } @@ -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! @@ -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 - } -} diff --git a/app/graphql/query-hooks.ts b/app/graphql/query-hooks.ts index 4cc1180dc..ddbe69348 100644 --- a/app/graphql/query-hooks.ts +++ b/app/graphql/query-hooks.ts @@ -55,6 +55,11 @@ export type DataCubeComponentFilter = { }; +export type DataCubeDimensionGeoShapesCubeFilter = { + iri: Scalars['String']; + dimensionIri: Scalars['String']; +}; + export type DataCubeLatestIriFilter = { iri: Scalars['String']; }; @@ -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; }; @@ -357,11 +361,10 @@ export type PossibleFiltersQueryVariables = Exact<{ export type PossibleFiltersQuery = { __typename: 'Query', possibleFilters: Array<{ __typename: 'ObservationFilter', iri: string, type: string, value?: Maybe }> }; export type DataCubeDimensionGeoShapesQueryVariables = Exact<{ - cubeIri: Scalars['String']; - dimensionIri: Scalars['String']; sourceType: Scalars['String']; sourceUrl: Scalars['String']; locale: Scalars['String']; + cubeFilter: DataCubeDimensionGeoShapesCubeFilter; }>; @@ -499,13 +502,12 @@ export function usePossibleFiltersQuery(options: Omit({ 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 ) } `; diff --git a/app/graphql/resolver-types.ts b/app/graphql/resolver-types.ts index 5819c8dd7..26e301d0f 100644 --- a/app/graphql/resolver-types.ts +++ b/app/graphql/resolver-types.ts @@ -55,6 +55,11 @@ export type DataCubeComponentFilter = { }; +export type DataCubeDimensionGeoShapesCubeFilter = { + iri: Scalars['String']; + dimensionIri: Scalars['String']; +}; + export type DataCubeLatestIriFilter = { iri: Scalars['String']; }; @@ -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; }; @@ -346,6 +350,7 @@ export type ResolversTypes = ResolversObject<{ String: ResolverTypeWrapper; Boolean: ResolverTypeWrapper; DataCubeComponents: ResolverTypeWrapper; + DataCubeDimensionGeoShapesCubeFilter: DataCubeDimensionGeoShapesCubeFilter; DataCubeLatestIriFilter: DataCubeLatestIriFilter; DataCubeMetadata: ResolverTypeWrapper; DataCubeMetadataFilter: DataCubeMetadataFilter; @@ -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; @@ -496,7 +502,7 @@ export type QueryResolvers>; possibleFilters?: Resolver, ParentType, ContextType, RequireFields>; searchCubes?: Resolver, ParentType, ContextType, RequireFields>; - dataCubeDimensionGeoShapes?: Resolver, ParentType, ContextType, RequireFields>; + dataCubeDimensionGeoShapes?: Resolver, ParentType, ContextType, RequireFields>; allTermsets?: Resolver, ParentType, ContextType, RequireFields>; }>; diff --git a/app/graphql/resolvers/rdf.ts b/app/graphql/resolvers/rdf.ts index 76947c645..5716ac9fb 100644 --- a/app/graphql/resolvers/rdf.ts +++ b/app/graphql/resolvers/rdf.ts @@ -100,10 +100,11 @@ export const searchCubes: NonNullable = 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, diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index 151159b23..e0897f52d 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -123,6 +123,11 @@ input DataCubePossibleFiltersCubeFilter { filters: SingleFilters! } +input DataCubeDimensionGeoShapesCubeFilter { + iri: String! + dimensionIri: String! +} + type TermsetCount { termset: Termset! count: Int! @@ -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!