php – filter query on multiple fields in single query-ThrowExceptions

Exception or error:

My setup is Symfony 5 with the latest API-Platform version running on PHP 7.3.
So I would like to be able to query both on name and username (maybe even email).
Do I need to write a custom resolver?

This is what I’ve tried so far but this results in a WHERE name = $name AND username = $name.

query SearchUsers ($name: String!) {
  users(name: $name, username: $name) {
    edges {
       node {

My entity:

 * @ApiResource
 * @ApiFilter(SearchFilter::class, properties={
 *   "name": "ipartial",
 *   "username": "ipartial",
 *   "email": "ipartial",
 * })
 * @ORM\Table(name="users")
 * @ORM\Entity(repositoryClass="Domain\Repository\UserRepository")
 * @ORM\HasLifecycleCallbacks()
class User
  private $name;
  private $username;
  private $email;
  // ... code omitted ...
How to solve:

The OR condition in the search filter is not handled by default in API Platform, you need a custom filter to do this (

See also:

Leave a Reply

Your email address will not be published. Required fields are marked *