Closed (fixed)
Project:
JSON:API
Version:
8.x-1.x-dev
Component:
Code
Priority:
Major
Category:
Task
Assigned:
Issue tags:
Reporter:
Created:
26 Jan 2018 at 09:58 UTC
Updated:
28 Feb 2018 at 15:09 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
gabesulliceComment #3
gabesulliceThis patch also depends on #2937961: ResourceType should provide related ResourceTypes
This was a bit of a deep dive. Since we now have a solid way to get relationship data from a resource type, it no longer makes sense to let the relationship routes to be as dynamic (and therefore complex) as they are.
This patch defines a route for every valid relationship and removes the
relatedroute parameter.Comment #5
wim leersThat is a very big change, which means we'll definitely need sign-off from @e0ipso.
Too late ATM to start reviewing a >40K patch. Will do so tomorrow.
Comment #6
gabesullice💯%
Comment #7
gabesulliceRerolled since #2937961: ResourceType should provide related ResourceTypes landed. Which knocks about 10k off the patch :)
To give a little more credence to this change I'll point out some of my reasoning.
One step toward support for relationship fields which aren't direct entity reference derivatives.
The client can no longer cause an Internal Server Error.
We no longer need to do our own 404 checking.
Less code duplication.
This code doesn't work in a world with internal resources. It will incorrectly respond with a 404 if the first relationship is internal, but other relationships are public.
Comment #8
gabesulliceComment #10
gabesulliceComment #11
gabesulliceThis issue describes a similar problem to #7.5
#2930217: getRelated() not working when related entity field is empty
Comment #12
e0ipsoThis in #3
and this in #5
Make me wonder if we want to take a different approach to the patch: split in two to get the MVP in (Do not provide routes for internal resource types), and then add a follow up for the maintainability bit (Define related and relationship routes statically).
Thoughts?
Comment #13
wim leersI agree that @e0ipso's proposal would make this much easier to review and commit. But I suspect that the "no routes for internal resource types" bit becomes much simpler if "define related and relationship routes" lands first. So the latter may need to be a blocker rather than a follow-up.
Comment #14
gabesulliceWell, #7 is already finished and passing tests/ready for review. So "MVP" is already met/exceeded. I understand that it may be harder to review though. So, I've made a patch that just removes support for internal resource/relationship routes and also doesn't create base individual/collection routes.
Once you decide to just define all routes statically, it becomes so trivial to remove the relationship routes in a follow-up that it might just be too much process and you end up with #7.
The code below is what the follow-up would be:
We have two patches ready for review:
Routes.phpthough. We'll need to remove most of the tests introduced by this patch when/if we do the "static routing" follow-up.My personal preference is #7. I can see both sides of the argument WRT a more difficult review process though, so I'll leave it up to @e0ipso/@WimLeers.
Comment #15
gabesulliceHere's a re-roll of #7.
Comment #16
wim leersSo @e0ipso was right: statically defined routes (well, explicit routes, really) can be a follow-up.
I think #14 is much easier to understand and hence land. The explicit routes portion can then be a pure refactoring-for-maintainability-reasons follow-up. This issue is in fact the necessary task, the bugfix. The follow-up isn't.
Understanding/analysis:
👍 All this logic now can elegantly live in this helper method.
👍 These are the essential changes: they solve the problem described in the title.
👍 This is testing the essential changes.
Remarks:
Docblock not updated.
If we're changing this
::buildEntityResource()helper anyway, shouldn't we just let it receive a singleResourceTypeparameter, i.e. basically receiving this$resource_typeobject that we're manually constructing here?Nah, never mind, that is again expanding scope. That'd be another nice small refactoring issue that could go in easily later.
Are the changes to this test actually necessary?
It's effectively changing this from a kernel test to a unit test. I think the whole point was that this was testing what a particular set of modules was resulting in?
Comment #17
wim leersAlso, now that #2932035: ResourceTypes should be internal when EntityType::isInternal is TRUE is in, this should be adding an integration test similar to core's
\Drupal\Tests\content_moderation\Kernel\ContentModerationStateResourceTest.Comment #18
gabesulliceRerolled and integration test done 💥
Comment #20
wim leersNit: Can be
assertSame().Nit: Should get a more specific typehint than
array.Comment #21
gabesullice#16.2 was a scope expansion that you wanted to do later no?
#16.3 Quickly, yes. We should not be adding invalid links to the entry point, that really breaks the point of HATEOAS. For that reason, I think we need to be testing that we are adding the proper links there. Maybe I'm missing your point though?
Edit: looks like you edited a bit of the review
Comment #22
wim leersSorry, for #20.3, I meant
ResourceTypeInterface[].I think it'd be better to keep it as a functional test and instead add the
jsonapi_entity_testmodule that you added in #2939705: Do not include internal resource types under `include`. Then we're not testing a mocked world, but the real world.EDIT: Because that module includes an entity type that is internal and should therefore NOT show up in the entry point!
Comment #23
gabesulliceAh, yeah, now that we have an integration test, that's much better.
Comment #24
wim leers#2939705: Do not include internal resource types under `include` was reverted because it broke JSON API on Drupal 8.6, I reverted it, so this is now blocked again.
Comment #25
wim leers#23 looks great!
Let's hear what @e0ipso thinks.
Comment #26
e0ipsoThis looks good to me 🎊.
Nit: Now that the tests have been collapsed to a single test, let's add these comments inline.
Comment #27
wim leers#2939705: Do not include internal resource types under `include` was recommitted. Having @e0ipso RTBC this is wonderful :) Now retesting…
Comment #29
wim leersThat didn't work — patch no longer applies obviously.
This is a rebase automatically performed by git.
Comment #31
wim leersGreen! Two unused statements and @e0ipso's remark in #26, but I can fix those upon commit :)
Except … those lines @e0ipso pointed out don't exist in the patch! So rather than waiting for Mateu to clarify, I'm deferring that to a follow-up if necessary. Because more likely than not, this was something on Mateu's local instance.
Comment #32
e0ipsoAh, that's totally fine. What I meant was to add the intention of those comments in the new relevant parts of the code. I seem to recall a similar code was elsewhere. I don't think this deserves a single more second of consideration, let's move on to important things.
🎉❗️
Comment #34
wim leersGuess what, I failed to commit the commit interdiff from #29 😂😅
#32: happy to still do that though :) But the second comment you mention actually already exists at
\Drupal\Tests\jsonapi\Functional\InternalEntitiesTest::testEntryPoint()!