Skip to content

Commit 8d477de

Browse files
[5.x] Expose field conditions from GraphQL API (#11607)
1 parent 49c7a46 commit 8d477de

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/GraphQL/Types/FieldType.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ public function fields(): array
4646
return $field->config()['width'] ?? 100;
4747
},
4848
],
49+
'if' => [
50+
'type' => GraphQL::type(ArrayType::NAME),
51+
'resolve' => function ($field) {
52+
return $field->config()['if'] ?? null;
53+
},
54+
],
55+
'unless' => [
56+
'type' => GraphQL::type(ArrayType::NAME),
57+
'resolve' => function ($field) {
58+
return $field->config()['unless'] ?? null;
59+
},
60+
],
4961
'config' => [
5062
'type' => GraphQL::type(ArrayType::NAME),
5163
'resolve' => function ($field) {

tests/Feature/GraphQL/FormTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ public function it_queries_the_fields()
121121
'invalid' => 'This isnt in the fieldtypes config fields so it shouldnt be output',
122122
'width' => 50,
123123
],
124-
'subject' => ['type' => 'select', 'options' => ['disco' => 'Disco', 'house' => 'House']],
125-
'message' => ['type' => 'textarea', 'width' => 33],
124+
'subject' => ['type' => 'select', 'options' => ['disco' => 'Disco', 'house' => 'House'], 'if' => ['name' => 'not empty']],
125+
'message' => ['type' => 'textarea', 'width' => 33, 'unless' => ['subject' => 'equals spam']],
126126
]);
127127

128128
BlueprintRepository::shouldReceive('find')->with('forms.contact')->andReturn($blueprint);
@@ -137,6 +137,8 @@ public function it_queries_the_fields()
137137
instructions
138138
width
139139
config
140+
if
141+
unless
140142
}
141143
}
142144
}
@@ -158,6 +160,8 @@ public function it_queries_the_fields()
158160
'config' => [
159161
'placeholder' => 'Type here...',
160162
],
163+
'if' => null,
164+
'unless' => null,
161165
],
162166
[
163167
'handle' => 'subject',
@@ -168,6 +172,8 @@ public function it_queries_the_fields()
168172
'config' => [
169173
'options' => ['disco' => 'Disco', 'house' => 'House'],
170174
],
175+
'if' => ['name' => 'not empty'],
176+
'unless' => null,
171177
],
172178
[
173179
'handle' => 'message',
@@ -176,6 +182,8 @@ public function it_queries_the_fields()
176182
'instructions' => null,
177183
'width' => 33,
178184
'config' => [],
185+
'if' => null,
186+
'unless' => ['subject' => 'equals spam'],
179187
],
180188
],
181189
],

0 commit comments

Comments
 (0)