-
Notifications
You must be signed in to change notification settings - Fork 9
fix linked cards occasionally missing. Use value.data.id #2430
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
base: main
Are you sure you want to change the base?
Conversation
Host Test Results 1 files ±0 1 suites ±0 29m 37s ⏱️ -58s Results for commit b097255. ± Comparison against base commit 04478cd. This pull request removes 8 and adds 15 tests. Note that renamed tests count towards both.
♻️ This comment has been updated with latest results. |
7df492d
to
6a9c51d
Compare
packages/base/card-api.gts
Outdated
@@ -966,7 +966,11 @@ class LinksTo<CardT extends CardDefConstructor> implements Field<CardT> { | |||
cachedInstance[isSavedInstance] = true; | |||
return cachedInstance as BaseInstanceType<CardT>; | |||
} | |||
let resourceId = new URL(value.links.self, relativeTo).href; | |||
let relativeId = | |||
value.data && Array.isArray(value.data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a LinksTo relationship, not a LinksToMany, why would the value here ever be an array? (keep in mind value
here is the JSONAPI serialization for the relationship).
packages/base/card-api.gts
Outdated
let relativeId = | ||
value.data && Array.isArray(value.data) | ||
? undefined // we don't know the id of the parent | ||
: value.data?.id ?? relativeTo; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generally we strive to serialize with the links.self
when sending the serialized form of the instance to the server. both links.self
and links.data.id
are supported, using both though, can lead to the potential of conflicts if they were ever configured differently from each other. which is why we have opted to pick one (links.self is more concise). i'm super curious what the scenario is when you are deserializing a payload and links.data.id is populated and links.self is not. I think that is the actual bug if this is what is fixing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another thought is to remove links.self altogether and purely only use links.data.id (this this also means we should not serialize this so we don't introduce confusion).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and another though is to favor links.self, but fallback to links.data.id if links self is not populated and links.data.id is populated. the drawback is that that gets into the confusing place of having these at odds with one another....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the input. The issue is really that value.links.self
is relative. In addition, doc.data.id
seems like the wrong id to be relative to anyway.
The data values are
value.links.self
../Category/someCategory
doc.data.id
http://test-realm/test/listing
value.data.id
http://test-realm/test/Category/someCategory
resourceId
http://test-realm/Category/someCategory
The expected value
resourceId
http://test-realm/test/Category/someCategory
I have added the serialization-test
test "can resolve relative URLs in linksToMany fields irrespective of location of linked cards"
another thought is to remove links.self altogether and purely only use links.data.id (this this also means we should not serialize this so we don't introduce confusion).
I think value.data.id seems to return an absolute url which is actually what I want. Perhaps, this is what we want to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.

The JSON API docs consider data to be kinda optional actually. Tho it seems links.self are also treated as optional. I can see why implementation wise it can get unnecessarily complex
I think in deserialization we can prefer value.data.id but I think in general, if we fallback to links.self the deserialization may be wrong
removal of serialization however, lets talk about it perhaps after standup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it’s especially tricky too, because I don’t think you can look at your contained card (or contained contained card, etc as the case may be), to see the id of the outermost document that you are relative too. That would be perfect if you could.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we need to thread thru a new parameter thru the deserialzation: the id of the document (if there is one), aka “relativeTo” so that we can resolve any relative hrefs. If we did that, there’s about 4-5 places that the relativeTo value would need to be added to function parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you like maybe we can pair on this after standup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes pls that wud be helpful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking one argument for not using links.data.id is that it makes it more challenging to copy a set of cards to a different realm. As relative references can be moved more easily.
6a9c51d
to
844163d
Compare
This PR is to fix the issue where linked data is missing