- šŗšøUnited States mglaman WI, USA
I don't like adding non-standard parameters for
include.\Drupal\jsonapi\Context\FieldResolver::resolveInternalIncludePathis 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::deduplicateat 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\IncludeResolverand 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::createis not aware of the resource types used. š” but\Drupal\jsonapi_resources\Unstable\DocumentExtractor::extractResourceObjectdoes 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
over 1 year ago 4:09pm 2 May 2024 - šŗšøUnited States mglaman WI, USA
Okay, I'm happy with the MR and approach.
 - Status changed to RTBC
over 1 year ago 4:39pm 2 May 2024 - šŗšøUnited States mglaman WI, USA
Saving issue credits. japerry helped review
 - 
            
              mglaman ā
             committed e6ba9a4c on 8.x-1.x
Issue #3172884 by mglaman, lisotton, zenphp, japerry: Include parameter...
 
- 
            
              mglaman ā
             committed e6ba9a4c on 8.x-1.x
 - Status changed to Fixed
over 1 year 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
+1, this issue seems to have cropped back up again.
 - š®šŖ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
about 1 year 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 I'm experiencing this error with the latest Drupal version when using JSON API with Search API indexes containing multiple content types.
Setup:
Search API index includes two different content types
Only one content type has the relationship field being included
JSON API query uses the include parameter for this relationshipError Behavior:
ā Fails with 400 Bad Request when search results contain only items from the content type that lacks the relationship field
ā Works correctly when search results include at least one item from the content type that has the relationship field
400 Bad Request: `field_page` are not valid relationship names. Possible values: node_type, revision_uid, uid, menu_link, field_faqs, field_layout, field_dialogs, field_page, field_related_itemsIs there any way to fix this with a patch?