Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .changeset/brave-dragons-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
"@wpengine/wp-graphql-content-blocks": minor
---

Adds support for specifying typed and queryable properties for object attributes in block.json.

Example: Defining a Typed Object in `block.json`:

```json
"attributes": {
"film": {
"type": "object",
"default": {
"id": 0,
"title": "Film Title",
"director": "Director Name",
"__typed": {
"id": "integer",
"title": "string",
"director": "string",
"year": "string"
}
}
}
}
```

In this example, the `film` attribute is an object with defined types for each property (`id`, `title`, `director`, and optionally `year`).

Querying Object Properties in GraphQL:


```graphql
fragment Film on MyPluginFilmBlock {
attributes {
film {
id,
title,
director,
year
}
},
}

query GetAllPostsWhichSupportBlockEditor {
posts {
edges {
node {
editorBlocks {
__typename
name
...Film
}
}
}
}
}
```
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,64 @@ If the resolved block has values for those fields, it will return them, otherwis
}
```

## Querying Object Types with Typed Properties

You can now query object-type block attributes with each property, provided the `__typed` structure is defined in the block's JSON configuration.
This allows you to query individual properties of the object for finer control and enhanced usability.

Example: Defining a Typed Object in `block.json`:

```json
"attributes": {
"film": {
"type": "object",
"default": {
"id": 0,
"title": "Film Title",
"director": "Director Name",
"__typed": {
"id": "integer",
"title": "string",
"director": "string",
"year": "string"
}
}
}
}
```

In this example, the `film` attribute is an object with defined types for each property (`id`, `title`, `director`, and optionally `year`).

Querying Object Properties in GraphQL:


```graphql
fragment Film on MyPluginFilmBlock {
attributes {
film {
id,
title,
director,
year
}
},
}

query GetAllPostsWhichSupportBlockEditor {
posts {
edges {
node {
editorBlocks {
__typename
name
...Film
}
}
}
}
}
```

## What about innerBlocks?

In order to facilitate querying `innerBlocks` fields more efficiently you want to use `editorBlocks(flat: true)` instead of `editorBlocks`.
Expand Down
Loading
Loading