I want to pass on a query string ?parameter_foo=bar to my /jsonapi endpoint but I was hoping to see that query string on the link section so that, in my case gatsby, can follow up child links with the same parameter.

I worked around this on gatsby with an interceptor, but as requested on Slack, posting the bug/question here.

It doesn't seem as a cache issue.

Comments

hanoii created an issue. See original summary.

gabesullice’s picture

Title: Using a custom query string doesn't seem to be carried over to the links in the json output » Undefined (but valid) query parameters are not mirrored in the response document's `self` link
Status: Active » Postponed (maintainer needs more info)
Issue tags: +API-First Initiative

I'm conflicted about whether this is a bug report or a feature request. Since the spec says:

The top-level links object MAY contain the following members:

  • self: the link that generated the current response document.

I therefore think this is a bug report.

If the query parameter is valid, I think we should ensure that it's mirrored in top-level self link.

@hanoii, would the above solve your need?

If the query parameter also needs to be mirrored in next and previous links of the response document I think this becomes more of a feature request.

hanoii’s picture

For some reason I don't have next and previous on my json on any entity (!?), but I'd say all.

On the root `/jsonapi` I would need the query string on every sub entity type, so that gatsby can properly follow all links with the same query string, so it seems it's not just `_self`.

hanoii’s picture

Adding organization

wim leers’s picture

I don't have next and previous on my json on any entity

That only happens for resource collections, not for individual resources. So for example, you should see them on /jsonapi/node/article, but not on /jsonapi/node/article/UUID.

On the root `/jsonapi` I would need the query string on every sub entity type, so that gatsby can properly follow all links with the same query string, so it seems it's not just `_self`.

What is the rationale behind this? What does this query parameter convey? Because for example a ?filter query parameter's value usually only makes sense for a particular resource type (e.g. node--article), not for all resource types.

wim leers’s picture

Title: Undefined (but valid) query parameters are not mirrored in the response document's `self` link » Undefined (but valid) query parameters are not mirrored in every resource type collection link in the entry point
Category: Bug report » Feature request

Per #3, I think this is clearly a feature request.

wim leers’s picture

Title: Undefined (but valid) query parameters are not mirrored in every resource type collection link in the entry point » In the entry point, mirror undefined (but valid) query parameters on every resource type collection link
hanoii’s picture

What is the rationale behind this? What does this query parameter convey? Because for example a ?filter query parameter's value usually only makes sense for a particular resource type (e.g. node--article), not for all resource types.

My use case is a typical (mostly) microsite approach. The driver for each microsite is a taxonomy term that is present exclusively on the content types. A goal for this project was to keep the drupal part as easy as possible, both in terms of admin and in terms of maintainability/development. Less fields, less entities nesting, less complex options in favor of more concrete and flexible coding approaches. So I have content types that have paragraphs that have other related entities as medias. Also I wanted to avoid mulit-site if at all possible. Entity access, although still an option, I still think, IMO, that adds unnecessary complexity.

I use this for Gatsby, so Gatsby needs to pulls the content for each microsite. So far I have been pulling everything and doing the filtering on gatsby's graphql side, which is OK, but to take advantage of some design decisions on gatsby and to prevent each microsite taking a lot to build once there's enough content in there I rather just make sure that jsonapi only outputs what the microsite needs.

So my rationale is to give gatsby the follwing URL for the jsonapi backend:

https://www.example.com/jsonapi?micro_site=TID

I am already successfully altering the queries to properly filter what I need with hook_query_TAG_alter() as mentioned on #3023444: Add a query tag to the entity query for other modules to perform alterations, but gatsby crawls all subsequent entities without this query string, as it follows what comes out of the initial `/jsonapi`.

I hope this helps.

I have a workaround in place with an interceptor on the gatsby request that appends this query string to every URL, I just `expected` that the querystring would be there.

hanoii’s picture

And just to note something on the titile, I wonder if it's just the entry point, and not every single URL generated on the `_links` section of every endpoint.

wim leers’s picture

Issue tags: +D8 cacheability

The reason we originally did not mirror those query arguments is simple: it destroys our cacheability.

Right now we only respect and therefore vary by the officially supported URL query parameters. If we mirror them, we need to support them all.

gabesullice’s picture

Having read the reasoning, I think the use case is sound and that enabling this kind of functionality is worth doing. However, I don't think the original concept I had of "mirroring" the query parameter is the right way to do it.

Instead, I think the "right" approach for us to take is to enable link customizations by landing #2995960: Add a Link and LinkCollection class to support RFC8288 web linking. and then using the JSON:API Hypermedia module (experimentally) to alter the self links that already exist. That alteration can be based on the current microsite context. Then, the cache will not need to vary by random query parameters, it will instead vary by a cache context for the "active microsite" that would be added to the altered links.

wim leers’s picture

Title: In the entry point, mirror undefined (but valid) query parameters on every resource type collection link » [PP-1] In the entry point, mirror undefined (but valid) query parameters on every resource type collection link
Status: Postponed (maintainer needs more info) » Postponed

Per #11.

wim leers’s picture

Title: [PP-1] In the entry point, mirror undefined (but valid) query parameters on every resource type collection link » In the entry point, mirror undefined (but valid) query parameters on every resource type collection link
Project: JSON:API » Drupal core
Version: 8.x-2.x-dev » 8.9.x-dev
Component: Code » jsonapi.module
Status: Postponed » Active
Related issues: +#2995960: Add a Link and LinkCollection class to support RFC8288 web linking.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.