Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor query mapper #8

Open
wants to merge 27 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0dbc81e
add compiler pass for search query mappers
crevillo Jan 26, 2019
ffa7bf7
add dedicated file for search query mappers and load it
crevillo Jan 26, 2019
cb3f444
define interface for searchCriterion and first of them
crevillo Jan 26, 2019
83bf501
create rest of the current available search criterions
crevillo Jan 26, 2019
8f0ad91
rename method name
crevillo Jan 26, 2019
4639965
add method to check if inputField can be mapped to a criteria
crevillo Jan 26, 2019
4b19c66
extract sortByPart logic to dedicate method
crevillo Jan 26, 2019
2279ce2
update namespaces after conflict resolution
crevillo Jan 28, 2019
a0925a7
add dedicated file for search query mappers and load it
crevillo Jan 26, 2019
6d9b245
define interface for searchCriterion and first of them
crevillo Jan 26, 2019
75ec18d
create rest of the current available search criterions
crevillo Jan 26, 2019
594c2a0
rename method name
crevillo Jan 26, 2019
832969c
updated namespaces after conflict
crevillo Jan 28, 2019
8ed08be
some typehints
crevillo Jan 28, 2019
eea3c5c
rename file with the visitors
crevillo Jan 28, 2019
05aa445
add querybuilder and adapt all the visitors to the new interface
crevillo Jan 29, 2019
cd4cb88
use "class" constant instead of string
crevillo Feb 1, 2019
a0b555e
remove unneded var
crevillo Feb 1, 2019
4494d2a
add basic criterion visitor
crevillo Feb 4, 2019
e6fab24
spec for querybuilder and searchQueryMapper
crevillo Feb 24, 2019
7184393
deleted unneded folder
crevillo Feb 25, 2019
37dcd75
cs
crevillo Feb 25, 2019
acc7834
spec for querybuilder and searchQueryMapper
crevillo Feb 26, 2019
7b22af1
wip
crevillo Feb 27, 2019
d4a0b70
wip
crevillo Mar 2, 2019
4cf468b
Merge branch 'refactor-query-mapper' of github.com:crevillo/ezplatfor…
crevillo Mar 2, 2019
af2fbf6
refactor to have visitors for sort clauses
crevillo Mar 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
spec for querybuilder and searchQueryMapper
  • Loading branch information
crevillo committed Feb 26, 2019
commit acc7834d0598ca4d1ea957a66c9d126c8d3b56f3
4 changes: 1 addition & 3 deletions src/DependencyInjection/Compiler/SearchQueryMappersPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@

class SearchQueryMappersPass implements CompilerPassInterface
{
const ID = SearchQueryMapper::class;

public function process(ContainerBuilder $container)
{
if (!$container->has(self::ID)) {
return;
}

$definition = $container->findDefinition(self::ID);
$definition = $container->findDefinition(SearchQueryMapper::class);
$taggedServices = $container->findTaggedServiceIds('ezplatform_graphql.query_input_visitor');

$queryInputVisitors = [];
Expand Down
8 changes: 8 additions & 0 deletions src/Exceptions/InvalidOperatorException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace EzSystems\EzPlatformGraphQL\Exceptions;

class InvalidOperatorException extends \InvalidArgumentException
{

}
6 changes: 6 additions & 0 deletions src/GraphQL/InputMapper/Search/Criterion/Created.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
namespace EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\Search\Criterion;

use eZ\Publish\API\Repository\Values\Content\Query;
use EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\Search\QueryBuilder;

class Created extends DateMetadata
{
const TARGET = Query\Criterion\DateMetadata::CREATED;

public function visit(QueryBuilder $queryBuilder, $value): void
{
$this->visitCriterion($queryBuilder, $value, self::TARGET);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
use EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\Search\QueryBuilder;
use EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\Search\QueryInputVisitor;

class Standard implements QueryInputVisitor
class CriterionClass implements QueryInputVisitor
{
/**
* @var string
*/
private $criterionClass;

public function __construct($criterionClass)
public function __construct(string $criterionClass)
{
$this->criterionClass = $criterionClass;
}
Expand Down
6 changes: 3 additions & 3 deletions src/GraphQL/InputMapper/Search/Criterion/DateMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
use EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\Search\QueryBuilder;
use EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\Search\QueryInputVisitor;

class DateMetadata implements QueryInputVisitor
abstract class DateMetadata implements QueryInputVisitor
{
public function visit(QueryBuilder $queryBuilder, $value): void
protected function visitCriterion(QueryBuilder $queryBuilder, $value, string $criterion): void
{
$dateOperatorsMap = [
'on' => Query\Criterion\Operator::EQ,
Expand All @@ -23,7 +23,7 @@ public function visit(QueryBuilder $queryBuilder, $value): void
}

$queryBuilder->addCriterion(new Query\Criterion\DateMetadata(
static::TARGET,
$criterion,
$dateOperatorsMap[$operator],
strtotime($dateString)
));
Expand Down
6 changes: 6 additions & 0 deletions src/GraphQL/InputMapper/Search/Criterion/Modified.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
namespace EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\Search\Criterion;

use eZ\Publish\API\Repository\Values\Content\Query;
use EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\Search\QueryBuilder;

class Modified extends DateMetadata
{
const TARGET = Query\Criterion\DateMetadata::MODIFIED;

public function visit(QueryBuilder $queryBuilder, $value): void
{
$this->visitCriterion($queryBuilder, $value, self::TARGET);
}
}
13 changes: 6 additions & 7 deletions src/GraphQL/InputMapper/Search/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
namespace EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\Search;

use eZ\Publish\API\Repository\Values\Content\Query;
use eZ\Publish\Core\REST\Server\Input\Parser\Criterion;

class QueryBuilder
{
/**
* @var array
* @var Criterion[]
*/
private $criterions = [];
private $criteria = [];

/**
* @var Query\SortClause
crevillo marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -18,7 +19,7 @@ class QueryBuilder

public function addCriterion(Query\Criterion $criterion): void
{
$this->criterions[] = $criterion;
$this->criteria[] = $criterion;
}

public function setSortBy(Query\SortClause $sortClause): void
Expand All @@ -30,15 +31,13 @@ public function buildQuery(): Query
{
$query = new Query();

if (count($this->criterions) === 0) {
if (count($this->criteria) === 0) {
return $query;
}

$query->filter = count($this->criterions) === 1 ? $this->criterions[0] : new Query\Criterion\LogicalAnd($this->criterions);
$query->filter = count($this->criteria) === 1 ? $this->criteria[0] : new Query\Criterion\LogicalAnd($this->criteria);

print 'bh';
if ($this->sortBy) {
print 'ah';
$query->sortClauses = $this->sortBy;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\Search;

class SortBy implements QueryInputVisitor
class SortClauseVisitor implements QueryInputVisitor
{
public function visit(QueryBuilder $queryBuilder, $value): void
{
Expand Down
8 changes: 4 additions & 4 deletions src/Resources/config/query_input_visitors.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
services:
EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\Search\Criterion\ContentTypeId:
class: EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\Search\Criterion\Standard
class: EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\Search\Criterion\CriterionClass
arguments:
$criterionClass: 'eZ\Publish\API\Repository\Values\Content\Query\Criterion\ContentTypeId'
tags:
- {name: 'ezplatform_graphql.query_input_visitor', inputKey: 'ContentTypeId'}

EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\Search\Criterion\Text:
class: EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\Search\Criterion\Standard
class: EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\Search\Criterion\CriterionClass
arguments:
$criterionClass: 'eZ\Publish\API\Repository\Values\Content\Query\Criterion\Fulltext'
tags:
- {name: 'ezplatform_graphql.query_input_visitor', inputKey: 'Text'}

EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\Search\Criterion\ParentLocationId:
class: EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\Search\Criterion\Standard
class: EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\Search\Criterion\CriterionClass
arguments:
$criterionClass: 'eZ\Publish\API\Repository\Values\Content\Query\Criterion\ParentLocationId'
tags:
Expand All @@ -33,6 +33,6 @@ services:
tags:
- {name: 'ezplatform_graphql.query_input_visitor', inputKey: 'Field'}

EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\Search\SortBy:
EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\Search\SortClauseVisitor:
tags:
- {name: 'ezplatform_graphql.query_input_visitor', inputKey: 'SortBy'}