Skip to content

Commit 307e260

Browse files
authored
fix(jit): enumerations array validation (#2963)
1 parent 1d2c2eb commit 307e260

File tree

5 files changed

+145
-5
lines changed

5 files changed

+145
-5
lines changed

src/core/jit/synth/synth.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,20 @@ where
155155
)
156156
}
157157
} else if self.plan.field_is_enum(node) {
158-
if value
159-
.as_str()
160-
.map(|v| self.plan.field_validate_enum_value(node, v))
161-
.unwrap_or(false)
162-
{
158+
let check_valid_enum = |value: &Value| -> bool {
159+
value
160+
.as_str()
161+
.map(|v| self.plan.field_validate_enum_value(node, v))
162+
.unwrap_or(false)
163+
};
164+
165+
let is_valid_enum = if let Some(vec) = value.as_array() {
166+
vec.iter().all(check_valid_enum)
167+
} else {
168+
check_valid_enum(value)
169+
};
170+
171+
if is_valid_enum {
163172
Ok(value.clone())
164173
} else {
165174
Err(
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
source: tests/core/spec.rs
3+
expression: response
4+
---
5+
{
6+
"status": 200,
7+
"headers": {
8+
"content-type": "application/json"
9+
},
10+
"body": {
11+
"data": {
12+
"color": {
13+
"departments": [
14+
"ENGINEERING",
15+
"MARKETING"
16+
]
17+
}
18+
}
19+
}
20+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
source: tests/core/spec.rs
3+
expression: formatted
4+
---
5+
scalar Bytes
6+
7+
type DTA {
8+
departments: [Department]
9+
}
10+
11+
scalar Date
12+
13+
scalar DateTime
14+
15+
enum Department {
16+
BLUE
17+
ENGINEERING
18+
MARKETING
19+
}
20+
21+
scalar Email
22+
23+
scalar Empty
24+
25+
scalar Int128
26+
27+
scalar Int16
28+
29+
scalar Int32
30+
31+
scalar Int64
32+
33+
scalar Int8
34+
35+
scalar JSON
36+
37+
scalar PhoneNumber
38+
39+
type Query {
40+
color: DTA
41+
}
42+
43+
scalar UInt128
44+
45+
scalar UInt16
46+
47+
scalar UInt32
48+
49+
scalar UInt64
50+
51+
scalar UInt8
52+
53+
scalar Url
54+
55+
schema {
56+
query: Query
57+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
source: tests/core/spec.rs
3+
expression: formatter
4+
---
5+
schema @server @upstream {
6+
query: Query
7+
}
8+
9+
enum Department {
10+
BLUE
11+
ENGINEERING
12+
MARKETING
13+
}
14+
15+
type DTA {
16+
departments: [Department]
17+
}
18+
19+
type Query {
20+
color: DTA @expr(body: {departments: ["ENGINEERING", "MARKETING"]})
21+
}

tests/execution/jit-enum-array.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Test expr with mustache
2+
3+
```graphql @config
4+
schema {
5+
query: Query
6+
}
7+
8+
enum Department {
9+
ENGINEERING
10+
MARKETING
11+
BLUE
12+
}
13+
14+
type Query {
15+
color: DTA @expr(body: {departments: ["ENGINEERING", "MARKETING"]})
16+
}
17+
18+
type DTA {
19+
departments: [Department]
20+
}
21+
```
22+
23+
```yml @test
24+
- method: POST
25+
url: http://localhost:8000/graphql
26+
body:
27+
query: |
28+
{
29+
color {
30+
departments
31+
}
32+
}
33+
```

0 commit comments

Comments
 (0)