Schema tutorialLesson 9: Inserting/Removing a (Gutenberg) block in bulk
Lesson 9: Inserting/Removing a (Gutenberg) block in bulk
We can update posts by modifying their (Gutenberg) block's HTML content.
Among other use cases, this is useful for promoting campaigns (such as when offering a discount during Black Friday):
Before the campaign, we create a custom block mycompany:black-friday-campaign-video with our Call To Action, and execute a bulk operation to add it to all posts in the website
After the campaign, we execute a bulk operation to remove the block from all posts
For the GraphQL queries in this tutorial lesson to work, the Schema Configuration applied to the endpoint needs to have Nested Mutations enabled
This GraphQL query identifies the 3rd paragraph block in a post (by searching for <!-- /wp:paragraph -->) and places the custom block's HTML content right after it:
This GraphQL query, similar to the previous one, generates the regex dynamically, allowing us to input the block type to search for, and after how many such blocks to place the custom block:
We provide the variables dictionary like this:
During development/testing of the GraphQL query, print the regex patterns in the response by placing # before the @remove directives (as to comment them out):