Closed (fixed)
Project:
JSON:API
Version:
8.x-2.x-dev
Component:
Code
Priority:
Major
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
28 Feb 2019 at 00:34 UTC
Updated:
19 Mar 2019 at 03:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
gabesulliceComment #3
gabesulliceI switched the relationship direction.
Comment #5
gabesulliceThe whole patch is:
6 files changed, 207 insertions(+), 167 deletions(-)However:
git df 8.x-2.x --stat src/Normalizer/JsonApiDocumentTopLevelNormalizer.phpis a net reduction.The bulk of the "new" logic is in the
JsonApiResourcenamespace, where this patch adds anOmittedDataclass, makesNullDataextendIncludedDataand addsgetAccessibleandgetOmissionstoResourceObjectData(and its descendants). The end result is seen inJsonApiDocumentTopLevel:Which makes omissions significantly simpler to reason about in the top level normalizer.
Comment #6
gabesulliceSweet, got a test run, I'll get this green tomorrow.
Comment #7
gabesulliceSince #3035149: Use ResourceObjectData with cardinality 1 for individual responses is RTBC, I'm marking this as postponed on it so that I can reroll this patch on top of it. Leaving as NW for that.
Comment #8
gabesullice#3035149: Use ResourceObjectData with cardinality 1 for individual responses landed.
This is both rerolled and fairly different from #2. Therefore, I don't think an interdiff would be helpful.
Comment #9
gabesulliceI had moved
getRelationshipLinks()fromEntityReferenceFieldNormalizertoEntityResource. I'm not totally happy with that. The alternative was to make it public on the normalizer, which felt worse. BUT, #3036285: Add a \JsonApiResource\Relationship object to carry relationship data, metadata and a link collection. will end up deleting this method anyway.Thinking about it more, I think the new method on
ResourceTypeshould just be in-lined rather than creating another public method.Leaving as NR to get any high-level remarks.
Comment #10
gabesulliceImplementing #9's thought about the new method.
Also:
... which means I might as well leave it on the normalizer to minimize the change set and make it easier to review. Done.
Comment #11
gabesulliceActually, why stop there? Let's just put it all back the way it was.
Comment #12
wim leers🤔 First thought: adding a new normalizer seems unrelated to cleaning up
JsonApiDocumentTopLevelNormalizer?✅ These surely were added to this patch accidentally, removing.
🤔 It's not crystal-clear after reading the patch why this new normalizer is necessary.
🥳
🤔 Shouldn't this then be renamed
NullIncludesData?Genius additions. 👏 I wish I had pointed this out :) This is indeed a perfect two-way split, thanks to this in the constructor:
assert(Inspector::assertAllObjects($data, ResourceObject::class, EntityAccessDeniedHttpException::class));.🤔 Can this not instead use
CacheableOmission?🤔 Fascinating addition. But AFAICT that
$additional_cacheabilityis not yet used anywhere. It may be better to not yet add this method in this issue, it seems to expand the scope unnecessarily, and given the second parameter is used, I'm not yet fully confident this will actually be used as intended?🤔 This looks like we're re-normalizing
$normalized_values. I think this is confusing.It feels like this is impossible to understand without stepping through it with a debugger?
🤔 If I read this, I immediately think "why is this not using
CacheableOmission?". But that's only for "NULL normalizations".This is where our naming could still use some love.
Perhaps renaming
$omittedto$communicate_omissionsor something like that? (I still don't like that name, but that concept is what we should name it after.)Oh, how about
$omission_links?👍🤔 Nice addition, but makes this patch harder to review and technically out-of-scope. How about we split this off into a separate issue and land that first?
👍
🤔 Hm, this means all these might useYes, it does, because it's not tied to "primary data omissions",CacheableOmission. Does that make sense?\Drupal\jsonapi\Normalizer\Value\CacheableOmissionis already generalized away from that (original) use case in HEAD.The more I think about it, the more elegant I think this is.
This snippet of code is a huge step forward actually in terms of understandability! 🥳
Comment #13
gabesullice1. I agree. I think we should just rescope the issue. Retitled, updated the IS slightly.
2. Thanks!
3. It sets up #3036285: Add a \JsonApiResource\Relationship object to carry relationship data, metadata and a link collection.. DataNormalizer normalizes data objects for: (1) primary data for individual, collections and relationships, (2) included and (3) relationship object data (within a resource object). I think that's enough reuse for it to be justified :)
4. :)
5. Sure. Done. That'll mean a 1 line Extras update. nbd.
6. :D
7.
🤔 hmm, I'm not sure if this will break something or not. I don't think it's been our behavior to omit empty fields. I'll add some code for it to see if it breaks tests.Tried this, it broke some tests. I think this would be an acceptable, or even desirable change, but I think it'd be better as a followup.8. Yeah, you're right. This was used more widely in earlier iterations of the patch, but I think there's no longer a super clear justification for it.
9. Yeah, this is really confusing, even to me after working on this. Rather than figure this out and clean it up here, that's what #3036284: Clean-up: *Exception::buildErrors returns an array of errors, but never returns >1 error. is for. Errors are wrapped in some unnecessary arrays.
10. I used
$ommission_linkslike you suggested. This is still ugly and, like #9, I'm leaving this largely alone so we can address it in #3036279: Clean-up: Use a LinkCollection for document omission links.. A major motivating goal of this issue is to detanglenormalizeValuesso that things can be made sensible. Right now,JsonApiDocumentTopLevel::normalizeValueshas omissions, errors, links and metadata all tangled together so it's hard to make any changes to any of them without making changes to all of them.11. Eh, I think the updated title and summary bring this into scope, no? I think you can appreciate that I'm a little hesitant to chain more issues together ATM ;)
12. Glad you like it! I was feeling pretty warm and fuzzy about it too.
Comment #14
gabesulliceWhoops, removed the usages of
CacheableNormalization::map, but forgot to delete the method.Comment #15
gabesulliceComment #16
wim leers#13: good answers, thanks!
Final round:
👏🥳 I like how we're now truly explicitly constructing a document, and the top-level keys prescribed by https://jsonapi.org/format are clearly here: that makes it crystal clear even to any developer reading this source code what's going on here :)
(Which definitely cannot be said of the code in HEAD.)
This is also the heart of the patch.
I don't think this comment is accurate anymore. Could be removed on commit.
(Also: this is where
DataNormalizeris used, which together with #13.3 forms the answer to my scepticism in #12.1: theDataNormalizeris there to normalize whichever primary data the generated JSON:API document contains.)Comment #17
gabesulliceNeeded a reroll after #3037452: Clean-up: ResourceObject should not be coupled to entities. I also did #16.2.
Will commit if tests pass.
Comment #19
gabesulliceThis needs to update Extras in #3035134: Compatibility with upcoming JSON:API 2.4 release: JSON:API Extras 3.5 because of the change of
NullDatatoNullIncludedData.Comment #20
dwwThis was the only issue with "Needs follow-up" including hyphen.
Consolidating tags.