0



I am using lighthouse-php as Api Gateway in a micro services architecture.
So for all my types I make a request internally through Guzzle.
But I am needing to implement filters that are suitable for any type and that give flexibility when making queries.

I need to implement a query like this:

query news (
        order_by: {publication_date: desc}
        where: {
            _or: {categories_id: { _eq: 1 }, title: { _ilike: "news" } }
        }
        limit: 10
        offset: 20
    ) {
      id     
      category_name: name
      photo
      publication_date
      text
      title
    }

But I have no idea how to implement this "where" filter that receives a composite object as in this example.

Remember that this query will not use any model within lumen, since it will be a custom query that will make a request to the microservice of news. What I need is the way that my query receives whatever comes in where, limit and order, to send it on request. But I have no idea how to build something like this in the scheme.

Anyone have any idea how to do it?
Thanks friends.

  • I don't have any experience in this, but I think you could check [this](https://github.com/nuwave/lighthouse/tree/master/src/WhereConstraints) and make something similar that, instead of use an Eloquent model, just translates to query params. I think you could also use a JSON type for your `where` arg (but here you lose all graphql benefits, and your users could pass everything) – Enzo Notario Dec 13 '19 at 12:47
  • The documentation that Enzo refers to seems to have moved to here: https://lighthouse-php.com/4.9/eloquent/complex-where-conditions.html – Hendrik Jan Feb 15 '20 at 15:58

1 Answers1

0

Yes, you can. Just now I'm making an component that will receive criterias to filter in graphql query so I need to fill filter's where params with those criterias.

Imagine the following schema:

type News{
 id: ID!
 title: String!
 views: Int!
}
type Query{
 getNews(where: _ @whereConditions(columns:["title", "views"])) : [News!] @all
}

We can make a query and fill where variables later

query GetNews($whereNews: [GetNewsWhereWhereConditions!]){
 getNews(where: {OR: $whereNews}){
  title
  views
 }
}

When querying we can fill the variables sending an object like

{
 "where":[
   {"column": "TITLE", "operator": "LIKE", "value": "Amazing title"},
   {"column": "VIEWS", "operator": "GTE", "value": 10,
  ]
}
Kluivert
  • 91
  • 3