cube
cube copied to clipboard
graphQL does not use variables correctly
Describe the bug The cubejs graphQL endpoint does not seem to parse graphQL variables correctly?
If I make a hardcoded query to our cubejs graphQL endpoint like this:
query {
cube {
myCubeName(where: {
device_id: {
equals: 123
}
}) {
status
device_id
}
}
}
It works with no issues and filters my data on device_id
and returns 1 result (correct).
However, hardcoding filters like this is generally not best practice in GraphQL so naturally I want to make use of variables to accomplish this like so:
query ($where: MyCubeNameWhereInput) {
cube {
myCubeName(where: $where) {
status
device_id
}
}
}
variables;
{
"where": {
"device_id": {
"equals": 123
}
}
}
However when sending this, the filter does not get applied, and it returns all the results for every device_id.
the MyCubeNameWhereInput
in this case comes from the cubeJS graphQL schema.
Expected behavior I would expect it to filter on device_id like the hardcoded example.
Minimally reproducible Cube Schema Sorry, I'm a frontend developer, and wasn't part of the cubeJS setup, so I'm not sure how this works. But I can reproduce this problem on any cubes we filter on.
Version: 0.29.4
Here's an example request as cURL:
curl 'https://my-endpoint.cubecloudapp.dev/cubejs-api/graphql' \
-H 'authority: my-endpoint.cubecloudapp.dev' \
-H 'accept: */*' \
-H 'accept-language: en-US,en;q=0.9' \
-H 'authorization: Bearer XXX-MY-AUTH-TOKEN' \
-H 'content-type: application/json' \
-H 'origin: https://studio.apollographql.com' \
-H 'referer: https://studio.apollographql.com/graph/colonygraph/explorer?variant=current' \
-H 'sec-fetch-dest: empty' \
-H 'sec-fetch-mode: cors' \
-H 'sec-fetch-site: cross-site' \
-H 'sec-gpc: 1' \
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' \
--data-raw '{"query":"query($where: CloudNacLatestStatusByInterfaceWhereInput) {\n cube {\n cloudNacLatestStatusByInterface(where: $where) {\n device_id\n status\n }\n }\n}","variables":{"where":{"device_id":{"equals":168128}}}}' \
--compressed
@MarkLyck Hey Mark! I can confirm this one just wasn't implemented yet.
If you are interested in working on this issue, please leave a comment below and we will be happy to assign the issue to you. If this is the first time you are contributing a Pull Request to Cube.js, please check our contribution guidelines. You can also post any questions while contributing in the #contributors channel in the Cube.js Slack.
@paveltiunov any plans on adding this? Being able to use variables is essential to being able to use this in production.
We've hit this too - here's a workaround
query ($where: MyCubeNameWhereInput) {
cube(
myCubeName: { where: $where }
) {
myCubeName {
status
device_id
}
}
}
Graphql is community-contributed, so we're looking for contributors here. @lvauvillier this one seems to be popular if you have time by any chance.