如何使用过滤器创建 graphql 查询?

时间:2021-05-08 07:30:10

标签: graphql

我是 graphql 的初学者,我正在尝试使用如下字段查询项目:

const listCountries = gql`
          query listCountries {
            listCountries {
              countries (where: { country_id: ${countryData.country_id} }) {
                id
                country_id
                country_name
              }
            }
          }
        `;

执行此操作时,出现错误 "Validation error of type FieldUndefined: Field 'listCountries' in type 'Query' is undefined @ 'listCountries'"

我尝试修改查询,但出现错误。应该如何修改通过country_id获取country

1 个答案:

答案 0 :(得分:0)

我想通了。我使用了以下代码。

const listCountries = gql`
            query listCountries {
              listCountrys(filter: {country_id: {eq: ${countryData.country_id}}}) {
                items {
                  id
                  country_id
                  country_name
                  _deleted
                }
              }
            }
          `;