Conditional filters in query

Similar to How to send null values to query from text box

I have written this query

query MyQuery(
  $limit: Int, 
  $offset: Int, 
  $first_name: String,
  $last_name: String,
  $email: String,
  $gateway: String,
  $start_date: timestamp, 
  $end_date: timestamp) {
  payment_transactions(
    where: {
      _and: [
        { 
          created_at: { 
            _gte: $start_date, 
            _lte: $end_date
          } 
        },
        { 
          transaction_id : { _eq: $gateway }
        },
        { 
          nft_buys: { 
            user: {
              _or: [
                { 
                  first_name: { _ilike: $first_name }
                }, 
                { 
                  last_name: { _ilike: $last_name }
                },
                { 
                  email: { _ilike: $email }
                }
                
              ]
            },
            
          }
        }
      ]
    },
    limit: $limit,
    offset: $offset
  ) {
    id
    amount
    status
    ip
    created_at
    service
    transaction_id
    order_number
    platform_fee
    blockchain_fee
    nft_buys {
      contract_address
      slug
      token_id
      status
      tx_hash
      transaction_id
      nft_data
      invoice_link
      user {
        email
        crypto_address
        first_name
        last_name
        affiliate {
          email
        }
      }
    }
  }
}

I want to get the data in specific range using some filters. So it becomes and operation. But when I hit the query it returns nothing bcz the variables first_name, last_name, email have no values.

So can u guide me how to fix the problem.

The Goal is:

  • Get data in specific range
  • If filters are defined then get the data in specific range with the defined filters