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

feat: Add a way to retrieve dimensions from multiple cubes #1244

Merged
merged 20 commits into from
Nov 17, 2023

Conversation

bprusinowski
Copy link
Collaborator

@bprusinowski bprusinowski commented Nov 2, 2023

This PR adapts the application logic to support retrieving dimensions from multiple cubes at once.

GQL / SPARQL

  • Consolidated several GQL queries together into DataCubesComponents that supports retrieving the components from several cubes at once
  • Removed Components query (replaced by DataCubesComponents)
  • Removed ComponentsWithHierarchies and DimensionHierarchy queries (hierarchies are now fetched by default in DataCubesComponents). As we generally use them in many different places across the app, it's more developer-friendly to have one source of truth (and also, it might be even more performant to have one query, instead of several different ones fired from different parts of the app). We can also see how the new version of query-cube-hierarchy library improves performance, as then it might be even less worrying, or we can bring back the old way of separating hierarchies fetching to the specific places that use them
  • Removed DimensionValues query (no need to have a separate query to fetch dimension values, as we can just specify one dimensionIri in DataCubesComponents to get the same result)
  • Removed dimensions & measures from SearchCubes query
  • We will now get all hierarchy levels, not limited to 6 as before (by using scalar instead of nested retrieval)
  • To further improve performance and limit resolver chains, I've extracted the dimension types from GQL to TypeScript. It also means that we now explicitly parse them inside the resolver
  • Removed DimensionMetadataFragment type, which means we can now better type Dimension and Measure, instead of mostly using the type that contains both

Misc

  • Fixed default empty filter selection when initializing a segment and hierarchy is not present

Context

This PR is a first part of preparations for merging the cubes. For the technical concept, see this Notion document.

  • DataCubesComponents
  • DataCubesMetadata
  • DataCubesObservations

How to test

  1. Click around in the application and make sure nothing is broken 💥
  2. Open GQL playground and send e.g. the following query to see that all dimensions from both cubes were fetched.

Query

query DataCubesComponents(
  $sourceType: String!
  $sourceUrl: String!
  $locale: String!
  $filters: [DataCubeFilter!]!
) {
  dataCubesComponents(
    sourceType: $sourceType
    sourceUrl: $sourceUrl
    locale: $locale
    filters: $filters
  )
}

Variables

{
  "sourceType": "sparql",
  "sourceUrl": "https://lindas.admin.ch/query",
  "locale": "en",
  "filters": [{ "iri": "https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen/9", "latest": true }, { "iri": "https://environment.ld.admin.ch/foen/ubd0104/6", "latest": true }]
}

Copy link

vercel bot commented Nov 2, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
visualization-tool ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 15, 2023 9:18am

@bprusinowski bprusinowski force-pushed the feat/several-cubes-in-the-same-chart branch from ce452cd to 3375e3f Compare November 14, 2023 14:04
@bprusinowski bprusinowski changed the title feat: Several cubes in the same chart feat: Add a way to retrieve dimensions from multiple cubes Nov 14, 2023
@bprusinowski bprusinowski force-pushed the feat/several-cubes-in-the-same-chart branch from edde81d to 8cb95cc Compare November 14, 2023 16:12
@Rdataflow
Copy link
Contributor

@bprusinowski can you add an additional point for how to test CI screenshots 😄

@bprusinowski
Copy link
Collaborator Author

Hi @Rdataflow, in fact we would need to switch back to Argos for screenshot testing, as we used the limit already on Percy (so not possible to check them on CI now) 😞

lloydrichards added a commit that referenced this pull request Nov 15, 2023
* test(e2e): ✅ fix data-testid on chart type buttons
* fix(e2e): ✅ filter selector in tooltip content
* fix(e2e): ✅ rework selectors for Sections for sorting tests
* fix(e2e): ✅ fix selectors for ordinal-measures
* fix(e2e): ✅ fix selector for color-mapping-maps
* test(e2e): ✅ skip multi root hierarchy retrieval until refactored in #1244
* fix(e2e): ✅ change map NFI config to Prod
* refactor(e2e): ✅ remove the config for nfi dataset
* fix(e2e): ✅ fix import when slugs missing
* fix(e2e): ✅ id for hierarchical filter
* test: Comment out fragile e2e test
* fix(e2e): ✅ skip tests that are fragile in CI

---------

Co-authored-by: Bartosz Prusinowski <[email protected]>
@ptbrowne
Copy link
Collaborator

I followed the direction and clicked around : I am getting a 405 on "Verkehrsleistung auf den Flugplätzen", when going to the table. Not sure this is related to the PR.

image

@ptbrowne
Copy link
Collaborator

ptbrowne commented Nov 16, 2023

I will retake a look tomorrow.

What I like

  • Simplifying resolver chain
  • Less different type of queries
  • Better typing client side

What I have questions on

  • Why we put everything into 1 query client side ? Seems like it would not be as cache friendly & we would have unwanted invalidations when adding a new cube to compare.
    • To solve this problem, seems like the client hooks could hide that they are doing multiple graphql requests & merge everything client side. We use this kind of technique on UIS.
    • Technically, useDataCubesComponentsQuery could be a custom hook relying on
      multiple useDataCubesComponentQuery urql hook calls (without "s") calls

a.position ?? a.value ?? undefined,
b.position ?? b.value ?? undefined
)
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: This could be done in the dimensionValuesLoader right ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup, this could be moved there 👍

sourceType: String!
sourceUrl: String!
locale: String!
filters: [DataCubeFilter!]!
Copy link
Collaborator

Choose a reason for hiding this comment

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

Was wondering if cubeFilters could not be more explicit as we already use filters for value filters ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this name should be more clear :)

app/graphql/resolvers/rdf.ts Outdated Show resolved Hide resolved
app/charts/shared/chart-state.ts Outdated Show resolved Hide resolved
@bprusinowski
Copy link
Collaborator Author

Thanks for reviewing @ptbrowne. I agree it would be better to separate the components queries per cube, so cube-specific queries are not re-fetched when adding another one 👍 I would be interested to learn how to do it, I guess we would need to use client.query directly instead of current useXYZQuery hook so we have several queries combined together in Promise.all?

@bprusinowski bprusinowski merged commit 8fe6d16 into main Nov 17, 2023
4 of 6 checks passed
@bprusinowski bprusinowski deleted the feat/several-cubes-in-the-same-chart branch November 17, 2023 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants