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: support for denormalized response from server #196

Merged
merged 7 commits into from
Jan 17, 2024

Conversation

jimmycallin
Copy link
Contributor

  • I have added automatic tests where applicable
  • The PR title is suitable as a release note
  • The PR contains a description of what has been changed
  • The description contains manual test instructions

Changes

Adds support for denormalized response from server

Test

Make sure the response is denormalized, that decoding is skipped as expected, and that there cannot be any cyclical references in the output.

@jimmycallin jimmycallin requested a review from a team as a code owner January 16, 2024 23:34
Copy link
Contributor

@gismya gismya left a comment

Choose a reason for hiding this comment

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

Looks good.

@jimmycallin jimmycallin merged commit 5590451 into main Jan 17, 2024
5 checks passed
@jimmycallin jimmycallin deleted the denormalize-response-support branch January 17, 2024 15:38
@ffMathy
Copy link
Contributor

ffMathy commented Jan 17, 2024

Curious. What does this do? Seems interesting.

@jimmycallin
Copy link
Contributor Author

Curious. What does this do? Seems interesting.

by default our API returns results in a normalized manner, e.g. this query:

[
  {
    "action": "query",
    "expression": "select project.full_name from Task limit 2"
  }
]

would result in this:

[
  {
    "action": "query",
    "data": [
      {
        "__entity_type__": "Task",
        "id": "19d33e8e-8bff-11eb-b5d3-c2ffbce28b68",
        "project": {
          "__entity_type__": "Project",
          "id": "33b1e354-8b3d-11eb-8e99-c2ffbce28b68",
          "full_name": "Sync"
        }
      },
      {
        "__entity_type__": "Task",
        "id": "2b5dda84-8b4f-11eb-b695-c2ffbce28b68",
        "project": {
          "__entity_type__": "Project",
          "id": "33b1e354-8b3d-11eb-8e99-c2ffbce28b68",
          // NOTE - NO FULL_NAME HERE
        }
      }
    ],
    "metadata": {
      "next": {
        "offset": 2
      }
    }
  }
]

We are then in the javascript client recursively merging all entities with same ID to ensure all attributes are available where expected. This can in some cases lead to cyclical object references, meaning that we cannot JSON.stringify them, and things like hashing the result become a problem.

We have just added support for a denormalized response in the api which will return the result in a more expected manner:

[
  {
    "action": "query",
    "data": [
      {
        "__entity_type__": "Task",
        "id": "19d33e8e-8bff-11eb-b5d3-c2ffbce28b68",
        "project": {
          "__entity_type__": "Project",
          "id": "33b1e354-8b3d-11eb-8e99-c2ffbce28b68",
          "full_name": "Sync"
        }
      },
      {
        "__entity_type__": "Task",
        "id": "2b5dda84-8b4f-11eb-b695-c2ffbce28b68",
        "project": {
          "__entity_type__": "Project",
          "id": "33b1e354-8b3d-11eb-8e99-c2ffbce28b68",
          // NOTE - FULL NAME HERE AS EXPECTED
          "full_name": "Sync"
        }
      }
    ],
    "metadata": {
      "next": {
        "offset": 2
      }
    }
  }
]

this in turn means we don't need to recursively merge all entities, and the result is thus serializable.

Hope this explains it!

@ffMathy
Copy link
Contributor

ffMathy commented Jan 17, 2024

Thank you for that elaboration! We didn't know this, and we'd definitely prefer the non-circular one.

Very nice feature! Thanks for keeping the library up to date regularly! 😍

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