0
votes

Here is my DB tables:
enter image description here
Here is my query :

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

First question is :
I need to pass it like this

products( product_id: "" or null )

And it will return nothings from db. But i want to return all data when "product_id" get empty string or null.
Is there any ways to ignore "product_id" when the "product_id" get empty string or null?

Second question is :
As you see the DB tables If i want to do a query to search "products" table with "product name" which is in "product_langs" table. @eq seems not support in this case. Is there any suggestion for this case?
Or i need to create a query with custom search and paginate? If yes, how can i do it? Is there any example about how to create custom paginate and search?


Thanks and regards!

1

1 Answers

0
votes

I can't try it out at the moment so it's untested. Please note that I'm a newbie and only providing suggestions as this has been unanswered for a little while.

Regarding your first question, try removing ! and see what happens. That should be worth a try.


product_id: String! @eq
product_id: String @eq

You could also try this https://lighthouse-php.com/master/eloquent/complex-where-conditions.html

For your second questions I believe this is what you are looking for.

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

Say you are defining a relationship productLang on your Product model in eloquent.


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 })