-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathreadme.txt
231 lines (185 loc) · 5.7 KB
/
readme.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
=== WPGraphQL Content Blocks ===
Contributors: blakewpe, chriswiegman, joefusco, matthewguywright, TeresaGobble, thdespou, wpengine
Tags: faustjs, faust, headless, decoupled, gutenberg
Requires at least: 5.7
Tested up to: 6.7.1
Stable tag: 4.8.1
Requires PHP: 7.4
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Requires Plugins: wp-graphql
Extends WPGraphQL to support querying (Gutenberg) Blocks as data.
== Description ==
Extends WPGraphQL to support querying (Gutenberg) Blocks as data.
== Installation ==
1. Search for the plugin in WordPress under "Plugins -> Add New".
2. Click the “Install Now” button, followed by "Activate".
== Frequently Asked Questions ==
== Screenshots ==
== Changelog ==
= 4.8.1 =
### Patch Changes
- 84a65bb: bug: Fixes fatal error when you de-activate WPGraphQL
= 4.8.0 =
### Minor Changes
- 742f18a: # Querying Object-Type Block Attributes in WPGraphQL
## Overview
With this update, you can now query object-type block attributes with each property individually, provided that the **typed structure** is defined in the class `typed_object_attributes` property or through a **WordPress filter**.
## How It Works
The `typed_object_attributes` is a **filterable** array that defines the expected **typed structure** for object-type block attributes.
- The **keys** in `typed_object_attributes` correspond to **object attribute names** in the block.
- Each value is an **associative array**, where:
- The key represents the **property name** inside the object.
- The value defines the **WPGraphQL type** (e.g., `string`, `integer`, `object`, etc.).
- If a block attribute has a specified **typed structure**, only the properties listed within it will be processed.
## Defining Typed Object Attributes
Typed object attributes can be **defined in two ways**:
### 1. In a Child Class (`typed_object_attributes` property)
Developers can extend the `Block` class and specify **typed properties** directly:
```php
class CustomMovieBlock extends Block {
/**
* {@inheritDoc}
*
* @var array<string, array<string, "array"|"boolean"|"number"|"integer"|"object"|"rich-text"|"string">>
*/
protected array $typed_object_attributes = [
'film' => [
'id' => 'integer',
'title' => 'string',
'director' => 'string',
'soundtrack' => 'object',
],
'soundtrack' => [
'title' => 'string',
'artist' => 'string'
],
];
}
```
### 2. Via WordPress Filter
You can also define **typed structures dynamically** using a WordPress filter.
```php
add_filter(
'wpgraphql_content_blocks_object_typing_my-custom-plugin_movie-block',
function () {
return [
'film' => [
'id' => 'integer',
'title' => 'string',
'director' => 'string',
'soundtrack' => 'object',
],
'soundtrack' => [
'title' => 'string',
'artist' => 'string'
],
];
}
);
```
## Filter Naming Convention
To apply custom typing via a filter, use the following format:
```
wpgraphql_content_blocks_object_typing_{block-name}
```
- Replace `/` in the block name with `-`.
- Example:
- **Block name**: `my-custom-plugin/movie-block`
- **Filter name**: `wpgraphql_content_blocks_object_typing_my-custom-plugin_movie-block`
## Example:
### Example `block.json` Definition
If the block has attributes defined as **objects**, like this:
```json
"attributes": {
"film": {
"type": "object",
"default": {
"id": 1,
"title": "The Matrix",
"director": "Director Name"
}
},
"soundtrack": {
"type": "object",
"default": {
"title": "The Matrix Revolutions...",
"artist": "Artist Name"
}
}
}
```
This means:
- The `film` attribute contains `id`, `title`, `director`.
- The `soundtrack` attribute contains `title` and `artist`.
## WPGraphQL Query Example
Once the typed object attributes are **defined**, you can query them **individually** in WPGraphQL.
```graphql
fragment Movie on MyCustomPluginMovieBlock {
attributes {
film {
id
title
director
soundtrack {
title
}
}
soundtrack {
title
artist
}
}
}
query GetAllPostsWhichSupportBlockEditor {
posts {
edges {
node {
editorBlocks {
__typename
name
...Movie
}
}
}
}
}
```
= 4.7.0 =
### Minor Changes
- 82c6080: Adds support for resolving and returning related term items as a `terms` connection for the CorePostTerms block along with `taxonomy` connection.
Adds support for resolving and returning the `prefix` and `suffix` items within the correspondent fields of the CorePostTerms block.
```graphql
query TestPostTerms($uri: String! = "test-terms") {
nodeByUri(uri: $uri) {
id
uri
... on NodeWithPostEditorBlocks {
editorBlocks {
__typename
... on CorePostTerms {
prefix
suffix
taxonomy {
__typename
node {
__typename
id
name
}
}
terms {
__typename
nodes {
__typename
id
name
}
}
}
}
}
}
}
```
[View the full changelog](https://github.com/wpengine/wp-graphql-content-blocks/blob/main/CHANGELOG.md)