Problem/Motivation
With #3015438: Wrap entity objects in a ResourceObject which carries a ResourceType done, renaming EntityCollection to ResourceObjectCollection will make the code simpler to understand and hence maintain.
Because EntityCollection is used in quite a few parts of the code base, and EntityCollection containing ResourceObject is a clear case of a confusing mismatch.
Proposed resolution
Rename it.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #33 | 3032679-33.patch | 42.86 KB | gabesullice |
| #24 | jsonapi-extras-3032679-23.patch | 997 bytes | gabesullice |
| #20 | 3032679-20.patch | 42.96 KB | gabesullice |
| #20 | interdiff.txt | 8.36 KB | gabesullice |
| #19 | 3032679-19.patch | 38.84 KB | gabesullice |
Comments
Comment #2
wim leersPostponed on #3015438: Wrap entity objects in a ResourceObject which carries a ResourceType.
Comment #3
wim leersContrib modules JSON:API Extras and JSON:API Defaults have been verified to still work without any changes after this is applied.
Comment #4
gabesulliceIf we're gonna rename it, let's just rename it to
PrimaryData, because that is the JSON:API member it represents.Comment #5
wim leersActually, "(resource) collection" is also mentioned in the spec twenty times. Naming it
PrimaryDataonly makes sense in some use cases. Naming itPrimaryDataresults in:That doesn't quite make sense either?
That probably indicates that we're using one value object for different semantical purposes.
Comment #6
wim leers#3015438: Wrap entity objects in a ResourceObject which carries a ResourceType just landed.
Comment #7
gabesulliceWhat about
ResourceData?Comment #8
wim leersWhy is that preferable to #3?
Comment #9
gabesulliceI'm trying to draw the connection to the
datamember of the top-level object."Collection" just feels strange to me because it can have a cardinality of 1 (yes, "data" is also plural, but it works for both "the node data" too).
Also, it can technically carry
ResourceIdentifiersandEntityAccessDeniedExceptionsin addition toResourceObjectsComment #10
effulgentsia commentedPer #5, is the same class also used for the
includedmember?Comment #11
effulgentsia commentedAlso, is this class ever used for a member that isn't
dataorincluded? For example, is it ever used forrelationships.foo?Comment #12
gabesullice#10, yep. However, from the spec's perspective, there's no behavioral difference between the
includedmember and thedatamember when cardinality is >1. IOW,includedis just "secondary/tertiary/n-ary data" depending on how many relationships have been traversed by an include.Comment #13
effulgentsia commented@gabesullice explained to me that this class would eventually represent the data that goes into one of the following document members:
dataincluded(which has the same syntax and semantics asdata)(data|included).relationships.foo.data(which ends in.data)Therefore, I like the name containing the word
Data.Per the spec, this data can be any one of:
ResourceObjectResourceIdentifierResourceObjectsResourceIdentifiersTherefore, I don't like the name containing the word
Collection(as it misleads with respect to some of those cases).So, +1 to
ResourceData.Comment #14
effulgentsia commentedBut, I just realized that the word Resource also misleads, since the Data can be about either a resource or a collection of resources.
Therefore, I propose
ResourceOrCollectionData, since that uses the spec's terminology of being data about a resource or a collection of resources.If people are -1 to the word "Or" in a class name, then I think
Datais a reasonable alternative as well, since there's nothing in JSON:API other than resources and resource collections that have data.Comment #15
effulgentsia commentedUpon further reflection, I prefer simply
Data, since per the last paragraph of #14, "resource or collection" is redundant.I wonder if we even want to make
Dataan abstract class, and then havePrimaryData,IncludedDataandRelationshipDataextend from it? Those child classes might not need to implement or override anything, but could just be there for naming clarity?Comment #16
gabesulliceIt like this idea the most. This is using class extension right by providing "specializations". The one thing I would have them do is have an
assert()in the constructors ensuring that the includes and primary data only containResourceObjectsand thatRelationshipDataonly includesResourceIdentifiers. Also,IncludedDatacould always set the$cardinalityargument to-1(unlimited).Comment #17
gabesulliceLet's leave the "specialization" of the
Dataclass to another issue though.Comment #18
effulgentsia commented+1: #3033123: Add ResourceObjectData, IncludedData, and RelationshipData specializations of Data.
Comment #19
gabesulliceComment #20
gabesulliceForgot a few things.
Comment #21
wim leersHm. The downside of
Datais that it is pretty much the most abstract imaginable. Will need to think a bit more about this.Comment #22
gabesullice@Wim Leers, does your opinion change if we commit #3033123: Add ResourceObjectData, IncludedData, and RelationshipData specializations of Data in conjunction with this issue? That makes the abstract
Dataclassabstract😇Comment #23
wim leers#22: that issue does make it much better IMHO yes :) I'm fine with doing it in two steps knowing that's the next step.
The only thing preventing me from RTBC'ing: what's the impact of this issue and the combined patch on JSON:API Extras and Consumer Image Styles?
Comment #24
gabesulliceThere's a one-line change required for JSON:API Extras. Consumer Image Styles is unaffected AFAICT.
Comment #25
wim leersGreat! And the interesting is that if we convert JSON:API Extras
EntityToJsonApiservice/API to using subrequests, that this change wouldn't even be necessary. @e0ipso has indicated he's fine with that, so I'll work on a patch to make that happen.Comment #27
gabesulliceIt was the Extras patch that failed.
Comment #30
wim leersI did what I described in #25: #3035045-4: Make EntityToJsonApi use subrequests so that it never breaks again.
Comment #31
gabesulliceCool!
Are you proposing that we wait for that vs. the one line change?
Comment #32
wim leers… that is a very good point! We can leave the choice to @e0ipso to go with either #3053045: Author username and publish date bug or #24.
Still, as soon as we commit this, we should create an issue in JSON:API Extras' issue queue for JSON:API 2.4.
I wrote this in #23:
@gabesullice addressed that in #24.
Comment #33
gabesulliceNeeds a reroll. Will commit if tests pass.
Comment #36
gabesulliceOpened #3035134: Compatibility with upcoming JSON:API 2.4 release: JSON:API Extras 3.5
Comment #37
wim leers#36: 👍 — was gonna ask for that, but you already did, thanks!