GraphQL 其中:大于/小于
GraphQL Where: greater than / less than
我正在尝试弄清楚如何使用 GraphQL 向 strapi 后端查询“小于”/“大于”(使用 React/Apollo)。基本上我希望奖金数额“不小于”$min_bonus,并且“不大于”$max_bonus...
对此有什么好的解决方案?
我的查询:
import { gql } from "@apollo/client";
const BONUSES_QUERY = gql`
query bonuses($min_bonus, $max_bonus, $welcome_bonus: Boolean, $deposit_bonus: Boolean, $monthly_bonus: Boolean, $weekly_bonus: Boolean, $slots_bonus: Boolean, $nodeposit_bonus: Boolean ) {
welcome_bonuses: bonuses(where:
{
welcome_bonus: $welcome_bonus
})
{
...BonusParts
}
deposit_bonuses: bonuses(where: { deposit_bonus: $deposit_bonus })
{
...BonusParts
}
monthly_bonuses: bonuses(where: { monthly_bonus: $monthly_bonus })
{
...BonusParts
}
weekly_bonuses: bonuses(where: { weekly_bonus: $weekly_bonus })
{
...BonusParts
}
slots_bonuses: bonuses(where: { slots_bonus: $slots_bonus })
{
...BonusParts
}
nodeposit_bonuses: bonuses(where: { nodeposit_bonus: $nodeposit_bonus })
{
...BonusParts
}
}
fragment BonusParts on Bonuses {
name
casino {
name
aff_link
logo {
url
}
}
slug
title
amount
code
min_deposit
value
wager
cashable
bonus_type {
name
}
}
`;
export default BONUSES_QUERY;
你说你想要大于和小于,但你的描述表明你想要大于或等于和小于或等于,所以我的建议是这样。如果您不想包含限制,可以将 _gt
替换为 _gte
等。
Here is the relevent Strapi documentation.
您可以像这样将 _gte
和 _lte
附加到 where
子句中的字段。
import { gql } from "@apollo/client";
const BONUSES_QUERY = gql`
query bonuses($min_bonus, $max_bonus, $welcome_bonus: Boolean, $deposit_bonus: Boolean, $monthly_bonus: Boolean, $weekly_bonus: Boolean, $slots_bonus: Boolean, $nodeposit_bonus: Boolean ) {
welcome_bonuses: bonuses(where:
{
deposit_bonus_gt: $min_bonus,
deposit_bonus_lt: $max_bonus,
welcome_bonus: $welcome_bonus
})
{
...BonusParts
}
deposit_bonuses: bonuses(where:
{
deposit_bonus_gt: $min_bonus,
deposit_bonus_lt: $max_bonus,
deposit_bonus: $deposit_bonus
})
{
...BonusParts
}
...
我正在尝试弄清楚如何使用 GraphQL 向 strapi 后端查询“小于”/“大于”(使用 React/Apollo)。基本上我希望奖金数额“不小于”$min_bonus,并且“不大于”$max_bonus...
对此有什么好的解决方案?
我的查询:
import { gql } from "@apollo/client";
const BONUSES_QUERY = gql`
query bonuses($min_bonus, $max_bonus, $welcome_bonus: Boolean, $deposit_bonus: Boolean, $monthly_bonus: Boolean, $weekly_bonus: Boolean, $slots_bonus: Boolean, $nodeposit_bonus: Boolean ) {
welcome_bonuses: bonuses(where:
{
welcome_bonus: $welcome_bonus
})
{
...BonusParts
}
deposit_bonuses: bonuses(where: { deposit_bonus: $deposit_bonus })
{
...BonusParts
}
monthly_bonuses: bonuses(where: { monthly_bonus: $monthly_bonus })
{
...BonusParts
}
weekly_bonuses: bonuses(where: { weekly_bonus: $weekly_bonus })
{
...BonusParts
}
slots_bonuses: bonuses(where: { slots_bonus: $slots_bonus })
{
...BonusParts
}
nodeposit_bonuses: bonuses(where: { nodeposit_bonus: $nodeposit_bonus })
{
...BonusParts
}
}
fragment BonusParts on Bonuses {
name
casino {
name
aff_link
logo {
url
}
}
slug
title
amount
code
min_deposit
value
wager
cashable
bonus_type {
name
}
}
`;
export default BONUSES_QUERY;
你说你想要大于和小于,但你的描述表明你想要大于或等于和小于或等于,所以我的建议是这样。如果您不想包含限制,可以将 _gt
替换为 _gte
等。
Here is the relevent Strapi documentation.
您可以像这样将 _gte
和 _lte
附加到 where
子句中的字段。
import { gql } from "@apollo/client";
const BONUSES_QUERY = gql`
query bonuses($min_bonus, $max_bonus, $welcome_bonus: Boolean, $deposit_bonus: Boolean, $monthly_bonus: Boolean, $weekly_bonus: Boolean, $slots_bonus: Boolean, $nodeposit_bonus: Boolean ) {
welcome_bonuses: bonuses(where:
{
deposit_bonus_gt: $min_bonus,
deposit_bonus_lt: $max_bonus,
welcome_bonus: $welcome_bonus
})
{
...BonusParts
}
deposit_bonuses: bonuses(where:
{
deposit_bonus_gt: $min_bonus,
deposit_bonus_lt: $max_bonus,
deposit_bonus: $deposit_bonus
})
{
...BonusParts
}
...