Skip to content

Commit

Permalink
Associations cannot use like operator
Browse files Browse the repository at this point in the history
This is a breaking change in schema, since an operator is removed for
some filters. However this is not a breaking change for using apps,
because it never worked and always crashed PHP.
  • Loading branch information
PowerKiKi committed Dec 28, 2020
1 parent 6ad0f04 commit 663bce7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 37 deletions.
44 changes: 24 additions & 20 deletions src/Factory/Type/FilterGroupConditionTypeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,31 +194,35 @@ private function getFieldConfiguration(string $typeName, string $fieldName, arra
*/
private function getOperators(string $fieldName, LeafType $leafType, bool $isAssociation, bool $isCollection): array
{
$scalarOperators = [
BetweenOperatorType::class,
EqualOperatorType::class,
GreaterOperatorType::class,
GreaterOrEqualOperatorType::class,
InOperatorType::class,
LessOperatorType::class,
LessOrEqualOperatorType::class,
LikeOperatorType::class,
NullOperatorType::class,
GroupOperatorType::class,
];

$associationOperators = [
HaveOperatorType::class,
EmptyOperatorType::class,
];

// For a single pure scalar
$operatorKeys = [];
if (!$isAssociation && !$isCollection) {
array_push($operatorKeys, ...[
LikeOperatorType::class,
]);
}

// An association can share some operators independently if it's a single entity or collection of entities
if ($isAssociation) {
$operatorKeys = array_merge($operatorKeys, $associationOperators);
array_push($operatorKeys, ...[
HaveOperatorType::class,
EmptyOperatorType::class,
]);
}

// We can share most operators for scalar and single entity association
if (!$isCollection) {
$operatorKeys = array_merge($operatorKeys, $scalarOperators);
array_push($operatorKeys, ...[
BetweenOperatorType::class,
EqualOperatorType::class,
GreaterOperatorType::class,
GreaterOrEqualOperatorType::class,
InOperatorType::class,
LessOperatorType::class,
LessOrEqualOperatorType::class,
NullOperatorType::class,
GroupOperatorType::class,
]);
}

$operators = array_fill_keys($operatorKeys, $leafType);
Expand Down
2 changes: 1 addition & 1 deletion tests/data/ModelWithTraitsFilter.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ input ModelWithTraitsFilterGroupConditionCustomFromTrait {

"""Type to specify a condition on a specific field"""
input ModelWithTraitsFilterGroupConditionId {
like: LikeOperatorID
between: BetweenOperatorID
equal: EqualOperatorID
greater: GreaterOperatorID
greaterOrEqual: GreaterOrEqualOperatorID
in: InOperatorID
less: LessOperatorID
lessOrEqual: LessOrEqualOperatorID
like: LikeOperatorID
null: NullOperatorID
group: GroupOperatorID
}
Expand Down
29 changes: 13 additions & 16 deletions tests/data/PostFilter.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -336,28 +336,28 @@ input NoInversedByFilterGroupCondition {

"""Type to specify a condition on a specific field"""
input NoInversedByFilterGroupConditionCreationDate {
like: LikeOperatorDateTime
between: BetweenOperatorDateTime
equal: EqualOperatorDateTime
greater: GreaterOperatorDateTime
greaterOrEqual: GreaterOrEqualOperatorDateTime
in: InOperatorDateTime
less: LessOperatorDateTime
lessOrEqual: LessOrEqualOperatorDateTime
like: LikeOperatorDateTime
null: NullOperatorDateTime
group: GroupOperatorDateTime
}

"""Type to specify a condition on a specific field"""
input NoInversedByFilterGroupConditionId {
like: LikeOperatorID
between: BetweenOperatorID
equal: EqualOperatorID
greater: GreaterOperatorID
greaterOrEqual: GreaterOrEqualOperatorID
in: InOperatorID
less: LessOperatorID
lessOrEqual: LessOrEqualOperatorID
like: LikeOperatorID
null: NullOperatorID
group: GroupOperatorID
modulo: ModuloOperatorInt
Expand Down Expand Up @@ -420,28 +420,28 @@ input PostFilterGroupCondition {

"""Type to specify a condition on a specific field"""
input PostFilterGroupConditionBody {
like: LikeOperatorString
between: BetweenOperatorString
equal: EqualOperatorString
greater: GreaterOperatorString
greaterOrEqual: GreaterOrEqualOperatorString
in: InOperatorString
less: LessOperatorString
lessOrEqual: LessOrEqualOperatorString
like: LikeOperatorString
null: NullOperatorString
group: GroupOperatorString
}

"""Type to specify a condition on a specific field"""
input PostFilterGroupConditionCreationDate {
like: LikeOperatorDateTime
between: BetweenOperatorDateTime
equal: EqualOperatorDateTime
greater: GreaterOperatorDateTime
greaterOrEqual: GreaterOrEqualOperatorDateTime
in: InOperatorDateTime
less: LessOperatorDateTime
lessOrEqual: LessOrEqualOperatorDateTime
like: LikeOperatorDateTime
null: NullOperatorDateTime
group: GroupOperatorDateTime
}
Expand All @@ -453,14 +453,14 @@ input PostFilterGroupConditionCustom {

"""Type to specify a condition on a specific field"""
input PostFilterGroupConditionId {
like: LikeOperatorID
between: BetweenOperatorID
equal: EqualOperatorID
greater: GreaterOperatorID
greaterOrEqual: GreaterOrEqualOperatorID
in: InOperatorID
less: LessOperatorID
lessOrEqual: LessOrEqualOperatorID
like: LikeOperatorID
null: NullOperatorID
group: GroupOperatorID
modulo: ModuloOperatorInt
Expand All @@ -477,49 +477,48 @@ input PostFilterGroupConditionNoInversedBy {
in: InOperatorID
less: LessOperatorID
lessOrEqual: LessOrEqualOperatorID
like: LikeOperatorID
null: NullOperatorID
group: GroupOperatorID
}

"""Type to specify a condition on a specific field"""
input PostFilterGroupConditionPublicationDate {
like: LikeOperatorDateTime
between: BetweenOperatorDateTime
equal: EqualOperatorDateTime
greater: GreaterOperatorDateTime
greaterOrEqual: GreaterOrEqualOperatorDateTime
in: InOperatorDateTime
less: LessOperatorDateTime
lessOrEqual: LessOrEqualOperatorDateTime
like: LikeOperatorDateTime
null: NullOperatorDateTime
group: GroupOperatorDateTime
}

"""Type to specify a condition on a specific field"""
input PostFilterGroupConditionStatus {
like: LikeOperatorPostStatus
between: BetweenOperatorPostStatus
equal: EqualOperatorPostStatus
greater: GreaterOperatorPostStatus
greaterOrEqual: GreaterOrEqualOperatorPostStatus
in: InOperatorPostStatus
less: LessOperatorPostStatus
lessOrEqual: LessOrEqualOperatorPostStatus
like: LikeOperatorPostStatus
null: NullOperatorPostStatus
group: GroupOperatorPostStatus
}

"""Type to specify a condition on a specific field"""
input PostFilterGroupConditionTitle {
like: LikeOperatorString
between: BetweenOperatorString
equal: EqualOperatorString
greater: GreaterOperatorString
greaterOrEqual: GreaterOrEqualOperatorString
in: InOperatorString
less: LessOperatorString
lessOrEqual: LessOrEqualOperatorString
like: LikeOperatorString
null: NullOperatorString
group: GroupOperatorString
}
Expand All @@ -535,7 +534,6 @@ input PostFilterGroupConditionUser {
in: InOperatorID
less: LessOperatorID
lessOrEqual: LessOrEqualOperatorID
like: LikeOperatorID
null: NullOperatorID
group: GroupOperatorID
}
Expand Down Expand Up @@ -568,57 +566,57 @@ input UserFilterGroupCondition {

"""Type to specify a condition on a specific field"""
input UserFilterGroupConditionCreationDate {
like: LikeOperatorDateTime
between: BetweenOperatorDateTime
equal: EqualOperatorDateTime
greater: GreaterOperatorDateTime
greaterOrEqual: GreaterOrEqualOperatorDateTime
in: InOperatorDateTime
less: LessOperatorDateTime
lessOrEqual: LessOrEqualOperatorDateTime
like: LikeOperatorDateTime
null: NullOperatorDateTime
group: GroupOperatorDateTime
}

"""Type to specify a condition on a specific field"""
input UserFilterGroupConditionEmail {
like: LikeOperatorString
between: BetweenOperatorString
equal: EqualOperatorString
greater: GreaterOperatorString
greaterOrEqual: GreaterOrEqualOperatorString
in: InOperatorString
less: LessOperatorString
lessOrEqual: LessOrEqualOperatorString
like: LikeOperatorString
null: NullOperatorString
group: GroupOperatorString
}

"""Type to specify a condition on a specific field"""
input UserFilterGroupConditionId {
like: LikeOperatorID
between: BetweenOperatorID
equal: EqualOperatorID
greater: GreaterOperatorID
greaterOrEqual: GreaterOrEqualOperatorID
in: InOperatorID
less: LessOperatorID
lessOrEqual: LessOrEqualOperatorID
like: LikeOperatorID
null: NullOperatorID
group: GroupOperatorID
modulo: ModuloOperatorInt
}

"""Type to specify a condition on a specific field"""
input UserFilterGroupConditionIsAdministrator {
like: LikeOperatorBoolean
between: BetweenOperatorBoolean
equal: EqualOperatorBoolean
greater: GreaterOperatorBoolean
greaterOrEqual: GreaterOrEqualOperatorBoolean
in: InOperatorBoolean
less: LessOperatorBoolean
lessOrEqual: LessOrEqualOperatorBoolean
like: LikeOperatorBoolean
null: NullOperatorBoolean
group: GroupOperatorBoolean
}
Expand All @@ -634,21 +632,20 @@ input UserFilterGroupConditionManager {
in: InOperatorID
less: LessOperatorID
lessOrEqual: LessOrEqualOperatorID
like: LikeOperatorID
null: NullOperatorID
group: GroupOperatorID
}

"""Type to specify a condition on a specific field"""
input UserFilterGroupConditionName {
like: LikeOperatorString
between: BetweenOperatorString
equal: EqualOperatorString
greater: GreaterOperatorString
greaterOrEqual: GreaterOrEqualOperatorString
in: InOperatorString
less: LessOperatorString
lessOrEqual: LessOrEqualOperatorString
like: LikeOperatorString
null: NullOperatorString
group: GroupOperatorString
}
Expand Down

0 comments on commit 663bce7

Please sign in to comment.