Skip to content

Commit 1d56b4d

Browse files
committed
Operator on primary key must have ID as their leaf type
1 parent 209d173 commit 1d56b4d

File tree

3 files changed

+52
-92
lines changed

3 files changed

+52
-92
lines changed

src/Factory/Type/FilterTypeFactory.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,13 @@ private function getConditionFieldsType(string $className, string $typeName): In
179179

180180
// Get all scalar fields
181181
foreach ($metadata->fieldMappings as $mapping) {
182-
/** @var LeafType $leafType */
183-
$leafType = $this->types->get($mapping['type']);
182+
if ($mapping['id'] ?? false) {
183+
$leafType = Type::id();
184+
} else {
185+
/** @var LeafType $leafType */
186+
$leafType = $this->types->get($mapping['type']);
187+
}
188+
184189
$fieldName = $mapping['fieldName'];
185190
$operators = $this->getOperators($fieldName, $leafType, false, false);
186191

tests/data/ModelWithTraitsFilter.graphqls

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,44 @@ schema {
33
mutation: mutation
44
}
55

6-
input BetweenOperatorInt {
7-
from: Int!
8-
to: Int!
6+
input BetweenOperatorID {
7+
from: ID!
8+
to: ID!
99
not: Boolean = false
1010
}
1111

12-
input EqualOperatorInt {
13-
value: Int!
12+
input EqualOperatorID {
13+
value: ID!
1414
not: Boolean = false
1515
}
1616

17-
input GreaterOperatorInt {
18-
value: Int!
17+
input GreaterOperatorID {
18+
value: ID!
1919
not: Boolean = false
2020
}
2121

22-
input GreaterOrEqualOperatorInt {
23-
value: Int!
22+
input GreaterOrEqualOperatorID {
23+
value: ID!
2424
not: Boolean = false
2525
}
2626

27-
input InOperatorInt {
28-
values: [Int!]!
27+
input InOperatorID {
28+
values: [ID!]!
2929
not: Boolean = false
3030
}
3131

32-
input LessOperatorInt {
33-
value: Int!
32+
input LessOperatorID {
33+
value: ID!
3434
not: Boolean = false
3535
}
3636

37-
input LessOrEqualOperatorInt {
38-
value: Int!
37+
input LessOrEqualOperatorID {
38+
value: ID!
3939
not: Boolean = false
4040
}
4141

42-
input LikeOperatorInt {
43-
value: Int!
42+
input LikeOperatorID {
43+
value: ID!
4444
not: Boolean = false
4545
}
4646

@@ -76,15 +76,15 @@ input ModelWithTraitsFilterConditionFieldCustomFromTrait {
7676

7777
# Type to specify a condition on a specific field
7878
input ModelWithTraitsFilterConditionFieldId {
79-
between: BetweenOperatorInt
80-
equal: EqualOperatorInt
81-
greater: GreaterOperatorInt
82-
greaterOrEqual: GreaterOrEqualOperatorInt
83-
in: InOperatorInt
84-
less: LessOperatorInt
85-
lessOrEqual: LessOrEqualOperatorInt
86-
like: LikeOperatorInt
87-
null: NullOperatorInt
79+
between: BetweenOperatorID
80+
equal: EqualOperatorID
81+
greater: GreaterOperatorID
82+
greaterOrEqual: GreaterOrEqualOperatorID
83+
in: InOperatorID
84+
less: LessOperatorID
85+
lessOrEqual: LessOrEqualOperatorID
86+
like: LikeOperatorID
87+
null: NullOperatorID
8888
}
8989

9090
# Type to specify conditions on fields
@@ -98,7 +98,7 @@ input ModelWithTraitsFilterJoins {
9898

9999
}
100100

101-
input NullOperatorInt {
101+
input NullOperatorID {
102102
not: Boolean = false
103103
}
104104

tests/data/PostFilter.graphqls

Lines changed: 18 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ input BetweenOperatorID {
2121
not: Boolean = false
2222
}
2323

24-
input BetweenOperatorInt {
25-
from: Int!
26-
to: Int!
27-
not: Boolean = false
28-
}
29-
3024
input BetweenOperatorString {
3125
from: String!
3226
to: String!
@@ -56,11 +50,6 @@ input EqualOperatorID {
5650
not: Boolean = false
5751
}
5852

59-
input EqualOperatorInt {
60-
value: Int!
61-
not: Boolean = false
62-
}
63-
6453
input EqualOperatorString {
6554
value: String!
6655
not: Boolean = false
@@ -81,11 +70,6 @@ input GreaterOperatorID {
8170
not: Boolean = false
8271
}
8372

84-
input GreaterOperatorInt {
85-
value: Int!
86-
not: Boolean = false
87-
}
88-
8973
input GreaterOperatorString {
9074
value: String!
9175
not: Boolean = false
@@ -106,11 +90,6 @@ input GreaterOrEqualOperatorID {
10690
not: Boolean = false
10791
}
10892

109-
input GreaterOrEqualOperatorInt {
110-
value: Int!
111-
not: Boolean = false
112-
}
113-
11493
input GreaterOrEqualOperatorString {
11594
value: String!
11695
not: Boolean = false
@@ -138,11 +117,6 @@ input InOperatorID {
138117
not: Boolean = false
139118
}
140119

141-
input InOperatorInt {
142-
values: [Int!]!
143-
not: Boolean = false
144-
}
145-
146120
input InOperatorString {
147121
values: [String!]!
148122
not: Boolean = false
@@ -179,11 +153,6 @@ input LessOperatorID {
179153
not: Boolean = false
180154
}
181155

182-
input LessOperatorInt {
183-
value: Int!
184-
not: Boolean = false
185-
}
186-
187156
input LessOperatorString {
188157
value: String!
189158
not: Boolean = false
@@ -204,11 +173,6 @@ input LessOrEqualOperatorID {
204173
not: Boolean = false
205174
}
206175

207-
input LessOrEqualOperatorInt {
208-
value: Int!
209-
not: Boolean = false
210-
}
211-
212176
input LessOrEqualOperatorString {
213177
value: String!
214178
not: Boolean = false
@@ -229,11 +193,6 @@ input LikeOperatorID {
229193
not: Boolean = false
230194
}
231195

232-
input LikeOperatorInt {
233-
value: Int!
234-
not: Boolean = false
235-
}
236-
237196
input LikeOperatorString {
238197
value: String!
239198
not: Boolean = false
@@ -261,10 +220,6 @@ input NullOperatorID {
261220
not: Boolean = false
262221
}
263222

264-
input NullOperatorInt {
265-
not: Boolean = false
266-
}
267-
268223
input NullOperatorString {
269224
not: Boolean = false
270225
}
@@ -321,15 +276,15 @@ input PostFilterConditionFieldCustom {
321276

322277
# Type to specify a condition on a specific field
323278
input PostFilterConditionFieldId {
324-
between: BetweenOperatorInt
325-
equal: EqualOperatorInt
326-
greater: GreaterOperatorInt
327-
greaterOrEqual: GreaterOrEqualOperatorInt
328-
in: InOperatorInt
329-
less: LessOperatorInt
330-
lessOrEqual: LessOrEqualOperatorInt
331-
like: LikeOperatorInt
332-
null: NullOperatorInt
279+
between: BetweenOperatorID
280+
equal: EqualOperatorID
281+
greater: GreaterOperatorID
282+
greaterOrEqual: GreaterOrEqualOperatorID
283+
in: InOperatorID
284+
less: LessOperatorID
285+
lessOrEqual: LessOrEqualOperatorID
286+
like: LikeOperatorID
287+
null: NullOperatorID
333288
modulo: ModuloOperatorInt
334289
}
335290

@@ -455,15 +410,15 @@ input UserFilterConditionFieldEmail {
455410

456411
# Type to specify a condition on a specific field
457412
input UserFilterConditionFieldId {
458-
between: BetweenOperatorInt
459-
equal: EqualOperatorInt
460-
greater: GreaterOperatorInt
461-
greaterOrEqual: GreaterOrEqualOperatorInt
462-
in: InOperatorInt
463-
less: LessOperatorInt
464-
lessOrEqual: LessOrEqualOperatorInt
465-
like: LikeOperatorInt
466-
null: NullOperatorInt
413+
between: BetweenOperatorID
414+
equal: EqualOperatorID
415+
greater: GreaterOperatorID
416+
greaterOrEqual: GreaterOrEqualOperatorID
417+
in: InOperatorID
418+
less: LessOperatorID
419+
lessOrEqual: LessOrEqualOperatorID
420+
like: LikeOperatorID
421+
null: NullOperatorID
467422
modulo: ModuloOperatorInt
468423
}
469424

0 commit comments

Comments
 (0)