How do you construct complex filters like CONTAINS or IN? #985
-
Would it be possible to add a more complex I have tried the following and it only brings back a single item rather than an array: const { data } = await $jsonApi.get('/node/hubpage', {
params: {
filter: {
drupal_internal__nid: {
operator: 'IN',
value: [1, 2]
}
}
}
}) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
The query in your example serializes to this:
which is not valid array syntax for most modern implementations. Many deserializers will require the arrays to be suffixed with The behaviour described above seems to be specifically discouraged in Drupal
To produce queries according to Drupals liking, you will have to format your queries like this
which produces output as expected by Drupal
|
Beta Was this translation helpful? Give feedback.
-
What is the URL query structure you are expecting to get sent to the API? Many of the server implementations implement complex filtering in vastly different ways so it is not clear what the result of the object you've provided is intended to be. The library is fairly open ended to allow for these variances so you'll be able to construct the URL if we know what the API you are using expects the filter params to look like. E.g one of the JSON:API servers I am currently working with expects complex filters like this: client.get('playerpoints', {
params: {
filter: "or(equals(rank,'17'),equals(rank,'18'))"
} }) |
Beta Was this translation helpful? Give feedback.
The query in your example serializes to this:
which is not valid array syntax for most modern implementations.
Many deserializers will require the arrays to be suffixed with
[]
like thisparams[filter][drupal_internal_nid][value][]=1
. This behaviour can be enabled in kitsu by providing themodern
flag when creating yourKitsu
instance https://github.com/wopian/kitsu/tree/master/packages/kitsu#parametersThe behaviour described above seems to be specifically discouraged in Drupal
https://www.drupal.org/docs/core-modules-and-themes/core-modules/jso…