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

Value object gets overwritten becuase it is normalized #27

Closed
jonaskello opened this issue May 27, 2019 · 3 comments · Fixed by #41
Closed

Value object gets overwritten becuase it is normalized #27

jonaskello opened this issue May 27, 2019 · 3 comments · Fixed by #41

Comments

@jonaskello
Copy link
Member

Entities have ID while value objects does not. If an entity has a value object it still gets normalized with a generated ID.

For example

{
  issues {
    id
    contact {
     name
    }
}

Here we get a list of issues, where each issue have an ID. Each issue have a contact object which does not have an ID (it is part of the issue).

Now somewhere else we get a single issue and only the phone of the contact:

query($issue: ID) {
  issueById($issue) {
    id
    contact {
     phone
    }
}

Now the normalized issue will have the same ID and get merged in cache, but the contact will get a different generated ID so the issue will point to a new contact ID which only has the phone attribute. The first query will re-run and find that the contact object is missing name and re-fetch and overwrite issue.contact with an object which only have name. Now the second query will re-run and find that issue.contact is missing name and we have an infinite loop.

@jonaskello
Copy link
Member Author

There are two ways to solve this:

  1. Give the value object an ID.
  2. Don't normalize value objects but instead keep their content inside the owning entity, and merge them on refetch.

@geon
Copy link
Member

geon commented May 28, 2019

Added test case: d85565a

@jonaskello
Copy link
Member Author

Since the value object is logically part of the closest entity, perhaps an alternative way to solve it would be to automatically generate ID for the value object starting from the parent ID. I think today the automatically generated path is the full path in the query which will generate different IDs depending on where in the query the parent entity exists.

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 a pull request may close this issue.

2 participants