Closed laurencefass closed 2 years ago
Dear @laurencefass ,
The rules of shortcuts are used from the following documentation on Drupal.org https://www.drupal.org/docs/core-modules-and-themes/core-modules/jsonapi-module/filtering#shortcuts.
apiParams .addFilter('title', 'cat', 'CONTAINS') .addFields('node--article', ['body', 'title'])
The above code should generate something like below,
filter[title][condition][path]=title&filter[title][condition][value]=cat&filter[title][condition][operator]=CONTAINS&fields[node--article]=body,title
i.e. it will also contain filter[title][condition][path]=title&
part.
The reason it is not "shortened" is due to the use of "CONTAINS" operator. "Shortcuts" are applied only for equality ("="). Could you please point me to the documentation where it says there are other ways to shorten the query?
heres a working example of the short form above. works with CONTAINS. https://latest.syntapse.co.uk/jsonapi/node/article?filter[title][operator]=CONTAINS&filter[title][value]=cat&fields[node--article]=body,title
@laurencefass ,
Interesting, it does seems like "condition" can be omitted. I would be happy to work on the optimisation if it is officially documented.
Let me share this issue with Drupal's slack and get other's opinion about it.
Update: Am discussing this in the slack channel https://drupal.slack.com/archives/C5A70F7D1/p1644928776753089 to get more input on this topic.
@laurencefass , I have created an issue on drupal.org https://www.drupal.org/project/drupal/issues/3264769 Based on if the shortcuts are officially supported or not, would consider adding support in this library.
Hope I got your Drupal user name correct while mentioning credits.
Apparently there is indeed documentation on Drupal.org about shortening of query. More details here : https://www.drupal.org/docs/core-modules-and-themes/core-modules/jsonapi-module/filtering#s-7-filter-for-nodes-where-title-contains-foo
This is a bug because, the library lies that it would create a short query, but it doest -.-".
This has been fixed in the latest release 2.0.0
Ive just started testing this.
The readme states:
"...it also tries to optimise the query by using the short form, whenever possible."
I have constructed a very simple query but I seem to be getting the long result.
which generates:
which can be more efficiently constructed as follows to give same result.