关于在同一查询中使用@eq 和@paginate 进行数据搜索的问题

Questions about using @eq and @paginate in same query for data search

这是我的数据库 tables:

这是我的查询:

products(
        product_id: String! @eq
        orderBy: _ @orderBy(columns: ["created_at", "product_id"])
    ): [Product!]! @paginate(defaultCount: 10)

第一个问题是:
我需要这样传递

products( product_id: "" or null )

它会 return 来自数据库的空话。但是当 "product_id" 得到空字符串或 null 时,我想 return 所有数据。
当 "product_id" 得到空字符串或 null 时,有什么方法可以忽略 "product_id" 吗?

第二个问题是:
如您所见,DB tables 如果我想做一个查询来搜索 "products" table 和 "product name" 在 "product_langs" table 中。 @eq 在这种情况下似乎不支持。对这种情况有什么建议吗?
或者我需要创建一个带有自定义搜索和分页的查询?如果是,我该怎么做?有没有关于如何创建自定义分页和搜索的示例?


谢谢和问候!

我目前无法试用,因此未经测试。 请注意,我是新手,只是提供建议,因为这已经有一段时间没有得到答复了。

关于你的第一个问题,尝试删除 ! 看看会发生什么。这应该值得一试。


product_id: String! @eq
product_id: String @eq

你也可以试试这个 https://lighthouse-php.com/master/eloquent/complex-where-conditions.html

关于你的第二个问题,我相信这就是你要找的。

https://lighthouse-php.com/master/eloquent/complex-where-conditions.html#wherehasconditions

假设您正在 eloquent 中的 Product 模型上定义关系 productLang


products(
        hasProductLang: _ @whereHasConditions(columns: ["product_name"])
        orderBy: _ @orderBy(columns: ["created_at", "product_id"])
    ): [Product!]! @paginate(defaultCount: 10)


products(hasProductLang: { column: PRODUCT_NAME, operator: EQ, value: $searchString })