过滤trapi中嵌套组件的字段值

时间:2019-12-19 15:19:23

标签: graphql strapi

我试图以某种方式过滤在组件(以前是组)中设置的字段值。我以为我的对象结构很简单,但无法正常工作。

这是我的(简化的)结构,取自生成的graphql模式:

type Product {
  name: String!
  description: String
  systemtype: Systemtype
  applicationAreas: [ComponentContentApplicationArea]
  id: ID!
  created_at: DateTime!
  updated_at: DateTime!
}

type ComponentContentApplicationArea {
  rating: Int!
  statement: String!
  applicationareaname: Applicationareaname
  id: ID!
}

type Applicationareaname {
  name: String!
  description: String!
  id: ID!
  created_at: DateTime!
  updated_at: DateTime!
}

我的GraphQL基本查询没有任何过滤器:

query {
  products {
    applicationAreas {
      rating
      applicationareaname{
        name
      }
    }
  }
}

结果:

{
  "data": {
    "products": [
      {
        "applicationAreas": [
          {
            "rating": 5,
            "applicationareaname": {
              "name": "Area A"
            }
          },
          {
            "rating": 7,
            "applicationareaname": {
              "name": "Area B"
            }
          },
          {
            "rating": 7,
            "applicationareaname": {
              "name": "Area C"
            }
          }
        ]
      }
    ]
  }
}

我的理解是,我可以通过这种方式过滤评​​分字段值-但显然我错了:

query {
  products (where: {applicationAreas: {rating: 5}}) {
    applicationAreas {
      rating
      applicationareaname{
        name
      }
    }
  }
}

执行上面的查询时出现此错误:

{
  "errors": [
    {
      "message": "Your filters contain a field 'applicationAreas.rating' that doesn't appear on your model definition nor it's relations",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "products"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "status": 400,
          "stacktrace": [...]
        }
      }
    }
  ],
  "data": {
    "products": null
  }
}

任何帮助我都表示赞赏,因为我对此一无所知。

非常感谢!

0 个答案:

没有答案