Problem/Motivation

A JSON:API URL with more than one include query parameter causes a crash.
This happens with both of these formats:

- /jsonapi/node/page/ce999bee-5173-4d9d-bb3e-f26db6ab4c76?include[]=uid&include[]=node_type
- /jsonapi/node/page/ce999bee-5173-4d9d-bb3e-f26db6ab4c76?include[0]=uid&include[1]=node_type

TypeError: Argument 2 passed to Drupal\jsonapi\IncludeResolver::resolveInternalIncludePaths() must be of the type array, null given, called in /var/www/web/core/modules/jsonapi/src/IncludeResolver.php on line 187 in Drupal\jsonapi\IncludeResolver::resolveInternalIncludePaths() (line 207 of core/modules/jsonapi/src/IncludeResolver.php).

Drupal\jsonapi\IncludeResolver::resolveInternalIncludePaths(Object, NULL) (Line: 187)
Drupal\jsonapi\IncludeResolver::toIncludeTree(Object, Array) (Line: 73)
Drupal\jsonapi\IncludeResolver->resolve(Object, Array) (Line: 1103)
Drupal\jsonapi\Controller\EntityResource->getIncludes(Object, Object) (Line: 212)
Drupal\jsonapi\Controller\EntityResource->getIndividual(Object, Object)

There is apparently no clear standard on how to format multiple copies of a query parameter (see https://stackoverflow.com/questions/24059773/correct-way-to-pass-multipl...).

But the Symfony Request class outputs the '?include[0]=uid&include[1]=node_type' format, so logically this should be accepted.

It's possible that the '?include[]=uid&include[]=node_type' is the wrong URL format to include two relationships (the docs do not say how to do this, so I am experimenting!). But it shouldn't cause a crash, even if it is wrong!

Steps to reproduce

Request a JSONAPI resource with two include parameters in the format 'include[]=ONE&include[]=TWO'

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3218028

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim created an issue. See original summary.

joachim’s picture

Issue summary: View changes

joachim’s picture

Status: Active » Needs review
bbrala’s picture

Category: Bug report » Feature request
Status: Needs review » Closed (won't fix)

Hi, thanks for the issue!

The JSON:API specification is very explicit how the include parameter should be formatted. Unfortunately this means include[] is not allow.

https://jsonapi.org/format/#fetching-includes

The value of the include parameter MUST be a comma-separated (U+002C COMMA, “,”) list of relationship paths. A relationship path is a dot-separated (U+002E FULL-STOP, “.”) list of relationship names.

Therefor this change would mean we do not follow the specification. Sorry.