【问题标题】:GRAPHQL STRAPI turn full array of filters to be a variableGRAPHQL STRAPI 将完整的过滤器数组变成一个变量
【发布时间】:2022-07-21 07:06:55
【问题描述】:

我正在使用带有 graphql 的strapi 这是我当前获取所有过滤类别的查询

 query GetRecommendedStuff(
    $answer1: String!
    $answer2: String!
    $answer3: String!
  ) {
    tools(
      filters: {
        and: [
          { categories: { category: { eq: $answer1 } } }
          { categories: { category: { eq: $answer2 } } }
          { categories: { category: { eq: $answer3 } } }
        ]
      }
    ) {
      data {
        attributes {
          toolname
          app_categories {
            data {
              attributes {
                category
              }
            }
          }
        }
      }
    }
  }

我想把它变成这样的东西,以便在查询过滤后的数据时过滤器可以是动态的。

  query GetRecommendedStuff(
    $answers: [Objects]!
  ) {
    tools(
      filters: { and: $answers }
    ) {
      data {
        attributes {
          toolname
          app_categories {
            data {
              attributes {
                category
              }
            }
          }
        }
      }
    }
  }

这可能吗?

【问题讨论】:

    标签: reactjs graphql apollo-client react-apollo strapi


    【解决方案1】:
    query GetRecommendedStuff(
        $toolFilters: ToolFiltersInput
      ) {
        tools(
          filters: $toolFilters
        ) {
          data {
            attributes {
              toolname
              app_categories {
                data {
                  attributes {
                    category
                  }
                }
              }
            }
          }
        }
      }
    
    //pass variables as a whole
    variables: {toolFilters: {
                and: [
                  { categories: { category: { eq: "" } } }
                  { categories: { category: { eq: "" } } }
                  { categories: { category: { eq: "" } } }
                ]
              }}
    

    【讨论】:

      猜你喜欢
      • 2021-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-17
      • 2018-12-05
      • 2022-01-01
      • 2021-09-23
      • 1970-01-01
      相关资源
      最近更新 更多