-
Notifications
You must be signed in to change notification settings - Fork 16
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
crevillo
wants to merge
27
commits into
ezsystems:dev
Choose a base branch
from
crevillo:refactor-query-mapper
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
0dbc81e
add compiler pass for search query mappers
crevillo ffa7bf7
add dedicated file for search query mappers and load it
crevillo cb3f444
define interface for searchCriterion and first of them
crevillo 83bf501
create rest of the current available search criterions
crevillo 8f0ad91
rename method name
crevillo 4639965
add method to check if inputField can be mapped to a criteria
crevillo 4b19c66
extract sortByPart logic to dedicate method
crevillo 2279ce2
update namespaces after conflict resolution
crevillo a0925a7
add dedicated file for search query mappers and load it
crevillo 6d9b245
define interface for searchCriterion and first of them
crevillo 75ec18d
create rest of the current available search criterions
crevillo 594c2a0
rename method name
crevillo 832969c
updated namespaces after conflict
crevillo 8ed08be
some typehints
crevillo eea3c5c
rename file with the visitors
crevillo 05aa445
add querybuilder and adapt all the visitors to the new interface
crevillo cd4cb88
use "class" constant instead of string
crevillo a0b555e
remove unneded var
crevillo 4494d2a
add basic criterion visitor
crevillo e6fab24
spec for querybuilder and searchQueryMapper
crevillo 7184393
deleted unneded folder
crevillo 37dcd75
cs
crevillo acc7834
spec for querybuilder and searchQueryMapper
crevillo 7b22af1
wip
crevillo d4a0b70
wip
crevillo 4cf468b
Merge branch 'refactor-query-mapper' of github.com:crevillo/ezplatfor…
crevillo af2fbf6
refactor to have visitors for sort clauses
crevillo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
spec/EzSystems/EzPlatformGraphQL/GraphQL/InputMapper/Search/QueryBuilderSpec.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace spec\EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\Search; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\Query; | ||
use eZ\Publish\API\Repository\Values\Content\Query\Criterion; | ||
use EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\Search\QueryBuilder; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
class QueryBuilderSpec extends ObjectBehavior | ||
{ | ||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(QueryBuilder::class); | ||
} | ||
|
||
function it_builds_a_query_when_no_citerion_is_defined() | ||
{ | ||
$query = $this->buildQuery(); | ||
$query->shouldBeAnInstanceOf(Query::class); | ||
} | ||
|
||
function it_builds_a_query_when_only_one_criterion_is_criterion($criterion) | ||
{ | ||
$criterion->beADoubleOf(Criterion::class); | ||
$this->addCriterion($criterion); | ||
$query = $this->buildQuery(); | ||
$query->filter->shouldBe($criterion); | ||
} | ||
|
||
function it_builds_a_query_when_more_than_criterion_is_passed($criterion1, $criterion2) | ||
{ | ||
$criterion1->beADoubleOf(Criterion::class); | ||
$criterion2->beADoubleOf(Criterion::class); | ||
|
||
$this->addCriterion($criterion1); | ||
$this->addCriterion($criterion2); | ||
|
||
$query = $this->buildQuery(); | ||
|
||
$query->filter->shouldBeAnInstanceOf(Criterion\LogicalAnd::class); | ||
} | ||
|
||
function it_builds_a_query_with_sort_criterias($sortBy) | ||
{ | ||
$sortBy->beADoubleOf(Query\SortClause::class); | ||
$this->setSortBy($sortBy); | ||
|
||
$query = $this->buildQuery(); | ||
$query->sortClauses->shouldBeArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/DependencyInjection/Compiler/SearchQueryMappersPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace EzSystems\EzPlatformGraphQL\DependencyInjection\Compiler; | ||
|
||
use EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\SearchQueryMapper; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
class SearchQueryMappersPass implements CompilerPassInterface | ||
{ | ||
const ID = SearchQueryMapper::class; | ||
|
||
public function process(ContainerBuilder $container) | ||
{ | ||
if (!$container->has(self::ID)) { | ||
return; | ||
} | ||
|
||
$definition = $container->findDefinition(self::ID); | ||
$taggedServices = $container->findTaggedServiceIds('ezplatform_graphql.query_input_visitor'); | ||
|
||
$queryInputVisitors = []; | ||
foreach ($taggedServices as $id => $tags) { | ||
foreach ($tags as $tag) { | ||
if (isset($tag['inputKey'])) { | ||
$queryInputVisitors[$tag['inputKey']] = new Reference($id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: the advantage of this is that a query input visitor can be overridden using the key. Useful. |
||
} | ||
} | ||
} | ||
|
||
$definition->setArgument('$queryInputVisitors', $queryInputVisitors); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\Search\Criterion; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\Query; | ||
|
||
class Created extends DateMetadata | ||
{ | ||
const TARGET = Query\Criterion\DateMetadata::CREATED; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually wouldn't use a class constant for that. It doesn't deduplicate much, and does so at the cost of readability. I'd use
SearchQueryMapper::class
directly inside the method.