graphql - 基于嵌套对象过滤查询
问题描述
我正在寻找一种基于嵌套字段过滤查询的解决方案。
我收集了一些食品卡车,有很多预订。每个预订都有一个位置、一个食品卡车和一个时间表。
因此,我想获得所有有特定位置和时间表的食品卡车。
我试试这个:
const query = qs.stringify({
_where: {
reservations: [
{ location: "60be40f06a15ab675c91f415" },
{ schedule: "60d0cd9a9f4886438c90b932" },
],
},
});
//Get foodtrucks by user with Axios
const { data:foodtrucksSSP = await getAxiosAPI(`/foodtrucks?${query}`);
但它什么也没返回。
和这个 :
const qs = require("qs");
const query = qs.stringify({
_where: [
{ "reservations.location": "60be40f06a15ab675c91f415" },
{ "reservations.schedule": "60d0cd9a9f4886438c90b932" },
],
});
//Get foodtrucks by user with Axios
const { data: foodtrucksSSP } = await getAxiosAPI(`/foodtrucks?${query}`);
但它会返回每辆预订了位置或时间表的食品卡车,而不仅仅是一个。
我尝试使用graphql,但我遇到了同样的问题......
query FoodtrucksReservationsLocation($location: ID!, $date: String!) {
foodtrucks(
where: {
_where: [
{
reservations: {
location: { id: $location }
schedule: { scheduleDate: $date }
}
}
]
}
) {
title
}
}
难道我做错了什么 ?
我可以让我的查询按预期工作的唯一方法是首先查询预订:
query FoodtruckyByReservation($location: ID!, $date: String!) {
reservations(
where: { location: $location, schedule: { scheduleDate: $date } }
) {
location {
title
id
}
schedule {
scheduleDate
id
}
foodtruck {
...foodtruckDetail
}
}
}
可以吗 ?
解决方案
推荐阅读
- azure - 使用 Connect-AzAccount 保存 ClientId 和 ClientSecret 以向 Azure 进行身份验证的安全方法
- html - 使用 py2.7 和 py3.7 出现此错误
- c# - 如何在 UWP 中滚动到文本框的末尾?
- javascript - 使用 three.js 的 3D 图
- tvos - 如何使用 Xamarin 从 tvOS 应用程序调用获取 REST API?
- html - bootstrap sm 调整大小不刹车
- android - 如何使用 Gradle 6.1.1 为 APK 设置压缩?
- angular - 模块结构Angular,是否在模块中使用共享组件?
- asp.net-core - 如何使用证书保护 .Net Core 应用程序以进行试用
- reactjs - 在 Next.js 中更改 Ant Design 的主题颜色