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

Returning normalised data #34

Open
zaidjan-devrev opened this issue Dec 6, 2024 · 3 comments
Open

Returning normalised data #34

zaidjan-devrev opened this issue Dec 6, 2024 · 3 comments
Labels
question Further information is requested

Comments

@zaidjan-devrev
Copy link

I have a use case where I want the returned value from the useQuery hook should be the normalised data instead of the reconstructed denormalised data. Would it be possible to configure this kind of behaviour

@klis87
Copy link
Owner

klis87 commented Dec 6, 2024

You can use https://github.com/klis87/normy/blob/master/packages/normy-react-query/src/create-query-normalizer.ts#L47C5-L47C22 to read normalized state at any time. But I am not sure it should be read actually. Please provide your use case, why you actually need that.

Ideally please provide also some snippets, with useQuery example, and what response you would expect and what you try to achieve.

Then we will think how to solve your problem.

@klis87 klis87 added the question Further information is requested label Dec 6, 2024
@zaidjan-devrev
Copy link
Author

zaidjan-devrev commented Dec 6, 2024

We have a DuckDB setup in our application with pre-normalized data, and an API that returns denormalized data. We want to use each data source independently based on different conditions, but need a common abstraction so that both sources return the same data structure.

Since denormalizing the DuckDB data at runtime would require too many API calls to the server, we've decided to normalize the API data instead.

The API returns deeply nested data like this:
{ "id": "obj_123", "type": "primary", "parent": { "id": "parent_456", "type": "container", "metadata": { "id": "meta_789", "reference": "REF-001" } }, "assignee": { "id": "user_101", "details": { "id": "profile_202", "level": "standard" } }, "components": [ { "id": "comp_303", "subcomponent": { "id": "sub_404", "status": "active" } } ], "status": { "id": "status_505", "current": { "id": "state_606", "name": "in_progress" } } }

While DuckDB contains normalized data like this:

{ "id": "obj_123", "type": "primary", "parent": "parent_456" }, "assignee": "user_101", "components": [ "comp_303" ], "status": "status_505" }

I attempted to use 'normy' to normalize the API data, but when querying through react-query, it still returned the denormalized structure."

@klis87
Copy link
Owner

klis87 commented Dec 6, 2024

What normy does, is that it keeps normalized store separately, outside of useQuery. UseQuery will always return original server data, usually this is what we want. The biggest normy usecase is to normalize data in order to have features like:

  • automatic data updates
  • being able to get nodes by id, without even knowing query id
  • being able to refetch dependent queries, even without knowing what keys to update, as this will be calculated by normy

Did you try to use getNormalizeData I pasted before?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants