- 🇺🇸United States mglaman WI, USA
I don't like adding non-standard parameters for
include
.\Drupal\jsonapi\Context\FieldResolver::resolveInternalIncludePath
is what throws this error.$public_field_name = $path_parts[0]; $internal_field_name = $resource_type->getInternalName($public_field_name); $relatable_resource_types = $resource_type->getRelatableResourceTypesByField($public_field_name); if (empty($relatable_resource_types)) { $message = "`$public_field_name` is not a valid relationship field name."; if (!empty(($possible = implode(', ', array_keys($resource_type->getRelatableResourceTypes()))))) { $message .= " Possible values: $possible."; } throw new CacheableBadRequestHttpException($cacheability, $message); }
The exploded paths is the include parameter
// $include_parameter: 'one.two.three, one.two.four'. $include_paths = array_map('trim', explode(',', $include_parameter)); // $exploded_paths: [['one', 'two', 'three'], ['one', 'two', 'four']]. $exploded_paths = array_map(function ($include_path) { return array_map('trim', explode('.', $include_path)); }, $include_paths);
So we could follow the patch's approach of iterating over each data, getting the resource type and checking if the include applies to the resource object. Then run
\Drupal\jsonapi\JsonApiResource\Data::deduplicate
at the end. The main difference if performing the check ourselves versus ignoring the exception.Maybe we should provide our own include resolver which wraps
\Drupal\jsonapi\IncludeResolver
and supports missing relationships, only for jsonapi_resources resources. But I feel like there should still be some kind of error if a relationship is requested that doesn't exist, at all. Maybe.Instead of checking the resource types in the data, we could just check the resource types defined by the route? However,
\Drupal\jsonapi_resources\Unstable\ResourceResponseFactory::create
is not aware of the resource types used. 💡 but\Drupal\jsonapi_resources\Unstable\DocumentExtractor::extractResourceObject
does this, which it also could!/** @var \Drupal\jsonapi\ResourceType\ResourceType[] $route_resource_types */ $route_resource_types = $request->attributes->get('resource_types');
- Merge request !11Support include parameter with mixed resource object types → (Merged) created by mglaman
- 🇺🇸United States mglaman WI, USA
Okay, I came back to this later than I wanted to, but I have an MR opened with a failing test.
- Status changed to Needs review
8 months ago 4:09pm 2 May 2024 - Status changed to RTBC
8 months ago 4:39pm 2 May 2024 - Status changed to Fixed
8 months ago 4:41pm 2 May 2024 Automatically closed - issue fixed for 2 weeks with no activity.
- 🇮🇳India Anul Delhi
I am still facing this issue using the stable latest release for this module. In my JSON API search it still throws the error and this time it actually shows multiple fields and same field it shows in Possible values also.
When I am using the older version of this module with the patch: https://www.drupal.org/files/issues/2020-09-24/fix-include-3172884-2.patch →
It is working fine for me.
I think we should reopen this bug and see what we can fix.
- 🇮🇪Ireland jouwdan
As above, the contents of this file: https://git.drupalcode.org/project/jsonapi_resources/-/blob/e6ba9a4c6e23...
seems to fix it. Has this been overwritten?
- Status changed to Needs work
4 months ago 6:14pm 16 August 2024 - 🇺🇸United States mglaman WI, USA
I didn't see the newest comments. Reopening to review
- 🇺🇸United States mglaman WI, USA
This was broken by one of the following:
- 📌 Implement ValueResolverInterface instead of ArgumentValueResolverInterface Active
- 📌 Automated Drupal 11 compatibility fixes for jsonapi_resources Fixed
- 🐛 GET requests broken Fixed