Skip to content

Filtering after results fetched #2816

@CvekCoding

Description

@CvekCoding

Hello.
I would to be able to filter collection after receiving it from persistence layer.
Example (everything below is about GraphQl).

Parent class (just an owner of collection):

/**
 * @ApiResource()
 *
 * @ORM\Entity(repositoryClass="App\Repository\DocumentRepository")
 */
class Document
{
    /**
     * @var AbstractItem[]
     *
     * @ApiSubresource()
     *
     * @ORM\OneToMany(targetEntity="App\Entity\AbstractItem", mappedBy="document")
     */
    protected $items;
}

Child abstract class:

/**
 * @ApiResource()
 * 
 * This filter is not working for both fields:
 * @ApiFilter(SearchFilter::class, properties={"persistedData": "exact", "calculatedData": "exact"})
 *
 * @ORM\Entity(repositoryClass="App\Repository\AbstractItemRepository")
 *
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorColumn(name="item_type", type="string")
 * @ORM\DiscriminatorMap({
 *     "TYPE1"="App\Entity\Item1",
 *     "TYPE2"="App\Entity\Item2"
 * })
 */
abstract class AbstractItem
{
    /**
     * @var Document
     *
     * @ORM\ManyToOne(targetEntity="App\Entity\Document", inversedBy="items")
     */
    protected $document;
}

Inheritance classes:

/**
 * @ApiResource()
 *
 * @ORM\Entity(repositoryClass="App\Repository\Item1")
 */
class Item1 extends AbstractItem
{
   // Data calculates somehow and is not persisted directly in ORM
   public $calculatedData;

   // Data persisted in ORM and can be class-specific
   public $persistedData;
}

/**
 * @ApiResource()
 *
 * @ORM\Entity(repositoryClass="App\Repository\Item2")
 */
class Item2 extends AbstractItem
{
   public $calculatedData;

   public $persistedData;
}

if then I launch query it doesnt work:

{
  document(id: "api/documents/1") {
     items(persistedData: "foo", calculatedData: "bar") {
        persistedData
        calculatedData
     }
  }
}

Due to the fact that both calculatedData and persistedData fields are presented in final classes but not in AbstractItem, I cant use built-in AbstractFilter on AbstractItem for several reasons:

  • some data is not even persisted so ORM filter is not applicable
  • some data is not visible from AbstractItem.

If Im right and there is no a proper way to filter/order by these fields (correct me please if Im wrong), I would like to propose to add feature - allow to process query results after receiving them from persistence layer and before further processing. I think here:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions