【问题标题】:GraphQL Where: greater than / less thanGraphQL 其中:大于/小于
【发布时间】:2021-11-16 07:03:48
【问题描述】:

我正在尝试弄清楚如何使用 GraphQL 向 strpi 后端(使用 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;

【问题讨论】:

    标签: reactjs graphql apollo strapi


    【解决方案1】:

    您说您想要大于和小于,但您的描述表明您想要大于或等于且小于或等于,所以我的建议是。如果您不想包含限制,您可以将_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
      }
    
      ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-25
      • 1970-01-01
      • 2019-02-16
      相关资源
      最近更新 更多