在hasura查询中

发布于 2025-02-13 17:21:57 字数 1485 浏览 0 评论 0原文

For example the following query:

 query getAttributeValues($language_code: String, $id_attribute: Int, $search: String) {
                v4_bo_v_attribute_values(
                    where: {
                        _and: [
                            { id_attribute: { _eq: $id_attribute } }
                            { _or: [{ language_code: { _eq: $language_code } }, { language_code: { _is_null: true } }] }
                            { _or: [{ attribute_value_translation: { _ilike: $search } }, { attribute_value: { _ilike: $search } }] }
                        ]
                    }
                    order_by: { attribute_value_translation: asc, attribute_value: asc }
                    limit: 100
                ) {
                    attribute_value
                    attribute_value_translation
                }
                v4_bo_v_attribute_values_aggregate(
                    where: {
                        _and: [
                            { id_attribute: { _eq: $id_attribute } }
                            { _or: [{ language_code: { _eq: $language_code } }, { language_code: { _is_null: true } }] }
                            { _or: [{ attribute_value_translation: { _ilike: $search } }, { attribute_value: { _ilike: $search } }] }
                        ]
                    }
                ) {
                    aggregate {
                        count
                    }
                }
            }
For example the following query:

 query getAttributeValues($language_code: String, $id_attribute: Int, $search: String) {
                v4_bo_v_attribute_values(
                    where: {
                        _and: [
                            { id_attribute: { _eq: $id_attribute } }
                            { _or: [{ language_code: { _eq: $language_code } }, { language_code: { _is_null: true } }] }
                            { _or: [{ attribute_value_translation: { _ilike: $search } }, { attribute_value: { _ilike: $search } }] }
                        ]
                    }
                    order_by: { attribute_value_translation: asc, attribute_value: asc }
                    limit: 100
                ) {
                    attribute_value
                    attribute_value_translation
                }
                v4_bo_v_attribute_values_aggregate(
                    where: {
                        _and: [
                            { id_attribute: { _eq: $id_attribute } }
                            { _or: [{ language_code: { _eq: $language_code } }, { language_code: { _is_null: true } }] }
                            { _or: [{ attribute_value_translation: { _ilike: $search } }, { attribute_value: { _ilike: $search } }] }
                        ]
                    }
                ) {
                    aggregate {
                        count
                    }
                }
            }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我喜欢麦丽素 2025-02-20 17:21:57

我们可以使用变量,即使在情况下也可以使用:

const searchQuery = search ? `%${search}%` : "%%";
const query = {       
    query: gql`
        query getAttributeValues($where: v4_bo_v_attribute_values_bool_exp) {
            v4_bo_v_attribute_values(
                where: $where
                order_by: { attribute_value_translation: asc, attribute_value: asc }
                limit: 100
            ) {
                attribute_value
                attribute_value_translation
            }
            v4_bo_v_attribute_values_aggregate(
                where: $where
            ) {
                aggregate {
                    count
                }
            }
        }
    `,
    variables: {
        where: {
            _and: [
                { id_attribute: { _eq: id_attribute } },
                { _or: [{ language_code: { _eq: tradLanguage } }, { language_code: { _is_null: true } }] },
                { _or: [{ attribute_value_translation: { _ilike: searchQuery } }, { attribute_value: { _ilike: searchQuery } }] }
            ]
        }
    }

We can use variables, even for where condition:

const searchQuery = search ? `%${search}%` : "%%";
const query = {       
    query: gql`
        query getAttributeValues($where: v4_bo_v_attribute_values_bool_exp) {
            v4_bo_v_attribute_values(
                where: $where
                order_by: { attribute_value_translation: asc, attribute_value: asc }
                limit: 100
            ) {
                attribute_value
                attribute_value_translation
            }
            v4_bo_v_attribute_values_aggregate(
                where: $where
            ) {
                aggregate {
                    count
                }
            }
        }
    `,
    variables: {
        where: {
            _and: [
                { id_attribute: { _eq: id_attribute } },
                { _or: [{ language_code: { _eq: tradLanguage } }, { language_code: { _is_null: true } }] },
                { _or: [{ attribute_value_translation: { _ilike: searchQuery } }, { attribute_value: { _ilike: searchQuery } }] }
            ]
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文