Skip to content

Commit 9a2ebf7

Browse files
authored
fix: Ensure correct EditorBlock.type field resolution (#316)
1 parent c09aeb7 commit 9a2ebf7

14 files changed

+60
-3
lines changed

.changeset/thin-donuts-float.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@wpengine/wp-graphql-content-blocks": patch
3+
---
4+
5+
fix: Ensure correct `EditorBlock.type` field resolution.

includes/Type/InterfaceType/EditorBlockInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ public static function register_type(): void {
141141
'type' => [
142142
'type' => 'String',
143143
'description' => __( 'The (GraphQL) type of the block', 'wp-graphql-content-blocks' ),
144+
'resolve' => static function ( $block ) {
145+
return WPGraphQLHelpers::get_type_name_for_block( $block['blockName'] ?? null );
146+
},
144147
],
145148
],
146149
'resolveType' => static function ( $block ) {

tests/unit/BlockQueriesTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public function test_retrieve_non_flatten_editor_blocks() {
5656
databaseId
5757
editorBlocks(flat: false) {
5858
name
59+
type
5960
}
6061
}
6162
}
@@ -70,6 +71,7 @@ public function test_retrieve_non_flatten_editor_blocks() {
7071
// There should be only one block using that query when not using flat: true
7172
$this->assertEquals( 1, count( $node['editorBlocks'] ) );
7273
$this->assertEquals( 'core/columns', $node['editorBlocks'][0]['name'] );
74+
$this->assertEquals( 'CoreColumns', $node['editorBlocks'][0]['type'] );
7375
}
7476

7577
public function test_retrieve_flatten_editor_blocks() {
@@ -79,8 +81,9 @@ public function test_retrieve_flatten_editor_blocks() {
7981
nodes {
8082
databaseId
8183
editorBlocks(flat: true) {
82-
name
83-
parentClientId
84+
name
85+
parentClientId
86+
type
8487
}
8588
}
8689
}
@@ -97,18 +100,23 @@ public function test_retrieve_flatten_editor_blocks() {
97100
$this->assertEquals( 5, count( $node['editorBlocks'] ) );
98101

99102
$this->assertEquals( 'core/columns', $node['editorBlocks'][0]['name'] );
103+
$this->assertEquals( 'CoreColumns', $node['editorBlocks'][0]['type'] );
100104
$this->assertNull( $node['editorBlocks'][0]['parentClientId'] );
101105

102106
$this->assertEquals( 'core/column', $node['editorBlocks'][1]['name'] );
107+
$this->assertEquals( 'CoreColumn', $node['editorBlocks'][1]['type'] );
103108
$this->assertNotNull( $node['editorBlocks'][1]['parentClientId'] );
104109

105110
$this->assertEquals( 'core/paragraph', $node['editorBlocks'][2]['name'] );
111+
$this->assertEquals( 'CoreParagraph', $node['editorBlocks'][2]['type'] );
106112
$this->assertNotNull( $node['editorBlocks'][2]['parentClientId'] );
107113

108114
$this->assertEquals( 'core/column', $node['editorBlocks'][3]['name'] );
115+
$this->assertEquals( 'CoreColumn', $node['editorBlocks'][3]['type'] );
109116
$this->assertNotNull( $node['editorBlocks'][3]['parentClientId'] );
110117

111118
$this->assertEquals( 'core/paragraph', $node['editorBlocks'][4]['name'] );
119+
$this->assertEquals( 'CoreParagraph', $node['editorBlocks'][4]['type'] );
112120
$this->assertNotNull( $node['editorBlocks'][4]['parentClientId'] );
113121
}
114122
}

tests/unit/BlockSupportsAnchorTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public function test_register_anchor_query_field() {
112112
nodes {
113113
editorBlocks {
114114
name
115+
type
115116
... on BlockWithSupportsAnchor {
116117
anchor
117118
}
@@ -124,15 +125,19 @@ public function test_register_anchor_query_field() {
124125

125126
$this->assertEquals( 4, count( $node['editorBlocks'] ) );
126127
$this->assertEquals( 'core/paragraph', $node['editorBlocks'][0]['name'] );
128+
$this->assertEquals( 'CoreParagraph', $node['editorBlocks'][0]['type'] );
127129
$this->assertEquals( 'example', $node['editorBlocks'][0]['anchor'] );
128130

129131
$this->assertEquals( 'core/paragraph', $node['editorBlocks'][1]['name'] );
132+
$this->assertEquals( 'CoreParagraph', $node['editorBlocks'][1]['type'] );
130133
$this->assertNull( $node['editorBlocks'][1]['anchor'] );
131134

132135
$this->assertEquals( 'core/group', $node['editorBlocks'][2]['name'] );
136+
$this->assertEquals( 'CoreGroup', $node['editorBlocks'][2]['type'] );
133137
$this->assertNull( $node['editorBlocks'][2]['anchor'] );
134138

135139
$this->assertEquals( 'core/paragraph', $node['editorBlocks'][3]['name'] );
140+
$this->assertEquals( 'CoreParagraph', $node['editorBlocks'][3]['type'] );
136141
$this->assertEquals( 'example-inner', $node['editorBlocks'][3]['anchor'] );
137142
}
138143
}

tests/unit/CoreCodeTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ className
8080
... on BlockWithSupportsAnchor {
8181
anchor
8282
}
83+
type
8384
...CoreCodeBlockFragment
8485
}
8586
}
@@ -140,6 +141,7 @@ public function test_retrieve_core_code_attributes() {
140141
$this->assertEmpty( $block['innerBlocks'], 'There should be no inner blocks' );
141142
$this->assertEquals( 'core/code', $block['name'], 'The block name should be core/code' );
142143
$this->assertEmpty( $block['parentClientId'], 'There should be no parentClientId' );
144+
$this->assertEquals( 'CoreCode', $block['type'], 'The block type should be CoreCode' );
143145
$this->assertNotEmpty( $block['renderedHtml'], 'The renderedHtml should be present' );
144146

145147
$attributes = $block['attributes'];
@@ -204,6 +206,7 @@ public function test_retrieve_core_code_with_custom_styles() {
204206
$block = $actual['data']['post']['editorBlocks'][0];
205207

206208
$this->assertEquals( 'core/code', $block['name'], 'The block name should be core/code' );
209+
$this->assertEquals( 'CoreCode', $block['type'], 'The block type should be CoreCode' );
207210

208211
$attributes = $block['attributes'];
209212
$this->assertEquals(
@@ -281,6 +284,7 @@ public function test_retrieve_core_code_with_gradient_and_additional_attributes(
281284
$block = $actual['data']['post']['editorBlocks'][0];
282285

283286
$this->assertEquals( 'core/code', $block['name'], 'The block name should be core/code' );
287+
$this->assertEquals( 'CoreCode', $block['type'], 'The block type should be CoreCode' );
284288

285289
$attributes = $block['attributes'];
286290
$this->assertEquals(

tests/unit/CoreHeadingTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ className
8080
name
8181
parentClientId
8282
renderedHtml
83+
type
8384
... on BlockWithSupportsAnchor {
8485
anchor
8586
}
@@ -141,6 +142,7 @@ public function test_retrieve_core_heading_attributes() {
141142
$this->assertEmpty( $block['innerBlocks'], 'There should be no inner blocks' );
142143
$this->assertEquals( 'core/heading', $block['name'], 'The block name should be core/heading' );
143144
$this->assertEmpty( $block['parentClientId'], 'There should be no parentClientId' );
145+
$this->assertEquals( 'CoreHeading', $block['type'], 'The block type should be CoreHeading' );
144146
$this->assertNotEmpty( $block['renderedHtml'], 'The renderedHtml should be present' );
145147

146148
$attributes = $block['attributes'];

tests/unit/CoreImageTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,10 @@ className
8686
innerBlocks {
8787
name
8888
}
89+
name
8990
parentClientId
9091
renderedHtml
91-
name
92+
type
9293
...CoreImageBlockFragment
9394
}
9495
}
@@ -140,6 +141,7 @@ public function test_retrieve_core_image_fields_attributes(): void {
140141
$this->assertEquals( $this->post_id, $node['databaseId'] );
141142
$this->assertEquals( 1, count( $node['editorBlocks'] ) );
142143
$this->assertEquals( 'core/image', $node['editorBlocks'][0]['name'] );
144+
$this->assertEquals( 'CoreImage', $node['editorBlocks'][0]['type'] );
143145

144146
$this->assertArrayNotHasKey( 'errors', $actual, 'There should not be any errors' );
145147
$this->assertArrayHasKey( 'data', $actual, 'The data key should be present' );
@@ -157,6 +159,7 @@ public function test_retrieve_core_image_fields_attributes(): void {
157159
$this->assertNotEmpty( $block['cssClassNames'], 'The cssClassNames should be present' );
158160
$this->assertEmpty( $block['innerBlocks'], 'There should be no inner blocks' );
159161
$this->assertEquals( 'core/image', $block['name'], 'The block name should be core/image' );
162+
$this->assertEquals( 'CoreImage', $block['type'], 'The block type should be CoreImage' );
160163
$this->assertEmpty( $block['parentClientId'], 'There should be no parentClientId' );
161164
$this->assertNotEmpty( $block['renderedHtml'], 'The renderedHtml should be present' );
162165
$this->assertEquals(

tests/unit/CoreListTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ className
8585
name
8686
parentClientId
8787
renderedHtml
88+
type
8889
... on CoreListItem {
8990
...CoreListItemBlockFragment
9091
}
@@ -93,6 +94,7 @@ className
9394
name
9495
parentClientId
9596
renderedHtml
97+
type
9698
...CoreListBlockFragment
9799
}
98100
}
@@ -149,6 +151,7 @@ public function test_retrieve_core_list_fields_and_attributes(): void {
149151
$this->assertNotEmpty( $block['cssClassNames'], 'The cssClassNames should be present' );
150152

151153
$this->assertEquals( 'core/list', $block['name'], 'The block name should be core/list' );
154+
$this->assertEquals( 'CoreList', $block['type'], 'The block type should be CoreList' );
152155
$this->assertEmpty( $block['parentClientId'], 'There should be no parentClientId' );
153156
$this->assertNotEmpty( $block['renderedHtml'], 'The renderedHtml should be present' );
154157

@@ -184,6 +187,7 @@ public function test_retrieve_core_list_fields_and_attributes(): void {
184187
$this->assertEmpty( $block['innerBlocks'][0]['cssClassNames'], 'The cssClassNames should be present' );
185188
$this->assertNotEmpty( $block['innerBlocks'][0]['clientId'], 'The clientId should be present' );
186189
$this->assertEquals( 'core/list-item', $block['innerBlocks'][0]['name'], 'The block name should be core/list-item' );
190+
$this->assertEquals( 'CoreListItem', $block['innerBlocks'][0]['type'], 'The block type should be CoreListItem' );
187191
$this->assertNotEmpty( $block['innerBlocks'][0]['renderedHtml'], 'The renderedHtml should be present' );
188192

189193
$this->assertEquals(
@@ -250,6 +254,7 @@ public function test_retrieve_core_list_attributes_typography_and_lock(): void {
250254
$block = $actual['data']['post']['editorBlocks'][0];
251255

252256
$this->assertEquals( 'core/list', $block['name'], 'The block name should be core/list' );
257+
$this->assertEquals( 'CoreList', $block['type'], 'The block type should be CoreList' );
253258

254259
$this->assertEquals(
255260
[
@@ -318,6 +323,7 @@ public function test_retrieve_core_list_attributes_ordered_and_reversed(): void
318323
$block = $actual['data']['post']['editorBlocks'][0];
319324

320325
$this->assertEquals( 'core/list', $block['name'], 'The block name should be core/list' );
326+
$this->assertEquals( 'CoreList', $block['type'], 'The block type should be CoreList' );
321327

322328
$this->assertEquals(
323329
[
@@ -383,6 +389,7 @@ public function test_retrieve_core_list_attributes_start_and_styles(): void {
383389
$block = $actual['data']['post']['editorBlocks'][0];
384390

385391
$this->assertEquals( 'core/list', $block['name'], 'The block name should be core/list' );
392+
$this->assertEquals( 'CoreList', $block['type'], 'The block type should be CoreList' );
386393

387394
$this->assertEquals(
388395
[
@@ -653,6 +660,7 @@ className
653660
editorBlocks( flat: false ) {
654661
clientId
655662
name
663+
type
656664
parentClientId
657665
innerBlocks {
658666
... on CoreListItem {

tests/unit/CoreParagraphTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ className
8080
name
8181
parentClientId
8282
renderedHtml
83+
type
8384
... on BlockWithSupportsAnchor {
8485
anchor
8586
}
@@ -141,6 +142,7 @@ public function test_retrieve_core_paragraph_attributes() {
141142

142143
$this->assertEmpty( $block['innerBlocks'], 'There should be no inner blocks' );
143144
$this->assertEquals( 'core/paragraph', $block['name'], 'The block name should be core/paragraph' );
145+
$this->assertEquals( 'CoreParagraph', $block['type'], 'The block type should be CoreParagraph' );
144146
$this->assertEmpty( $block['parentClientId'], 'There should be no parentClientId' );
145147
$this->assertNotEmpty( $block['renderedHtml'], 'The renderedHtml should be present' );
146148

@@ -210,6 +212,7 @@ public function test_retrieve_core_paragraph_with_drop_cap_and_custom_styles() {
210212
$block = $actual['data']['post']['editorBlocks'][0];
211213

212214
$this->assertEquals( 'core/paragraph', $block['name'], 'The block name should be core/paragraph' );
215+
$this->assertEquals( 'CoreParagraph', $block['type'], 'The block type should be CoreParagraph' );
213216

214217
$attributes = $block['attributes'];
215218
$this->assertEquals(
@@ -293,6 +296,7 @@ public function test_retrieve_core_paragraph_with_direction_and_gradient() {
293296
$block = $actual['data']['post']['editorBlocks'][0];
294297

295298
$this->assertEquals( 'core/paragraph', $block['name'], 'The block name should be core/paragraph' );
299+
$this->assertEquals( 'CoreParagraph', $block['type'], 'The block type should be CoreParagraph' );
296300

297301
$attributes = $block['attributes'];
298302
$this->assertEquals(
@@ -360,6 +364,7 @@ public function test_retrieve_core_paragraph_with_additional_attributes() {
360364
$block = $actual['data']['post']['editorBlocks'][0];
361365

362366
$this->assertEquals( 'core/paragraph', $block['name'], 'The block name should be core/paragraph' );
367+
$this->assertEquals( 'CoreParagraph', $block['type'], 'The block type should be CoreParagraph' );
363368

364369
$attributes = $block['attributes'];
365370
$this->assertEquals(

tests/unit/CorePreformattedTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ className
7575
name
7676
parentClientId
7777
renderedHtml
78+
type
7879
... on BlockWithSupportsAnchor {
7980
anchor
8081
}
@@ -138,6 +139,7 @@ public function test_retrieve_core_preformatted_attributes() {
138139

139140
$this->assertEmpty( $block['innerBlocks'], 'There should be no inner blocks' );
140141
$this->assertEquals( 'core/preformatted', $block['name'], 'The block name should be core/preformatted' );
142+
$this->assertEquals( 'CorePreformatted', $block['type'], 'The block type should be CorePreformatted' );
141143
$this->assertEmpty( $block['parentClientId'], 'There should be no parentClientId' );
142144
$this->assertNotEmpty( $block['renderedHtml'], 'The renderedHtml should be present' );
143145

@@ -203,6 +205,7 @@ public function test_retrieve_core_preformatted_with_custom_styles() {
203205
$block = $actual['data']['post']['editorBlocks'][0];
204206

205207
$this->assertEquals( 'core/preformatted', $block['name'], 'The block name should be core/preformatted' );
208+
$this->assertEquals( 'CorePreformatted', $block['type'], 'The block type should be CorePreformatted' );
206209

207210
$attributes = $block['attributes'];
208211
$this->assertEquals(
@@ -278,6 +281,7 @@ public function test_retrieve_core_preformatted_with_lock() {
278281
$block = $actual['data']['post']['editorBlocks'][0];
279282

280283
$this->assertEquals( 'core/preformatted', $block['name'], 'The block name should be core/preformatted' );
284+
$this->assertEquals( 'CorePreformatted', $block['type'], 'The block type should be CorePreformatted' );
281285

282286
$attributes = $block['attributes'];
283287
$this->assertEquals(

0 commit comments

Comments
 (0)