Recipes
🔥 Subscribe to our newsletter to be notified when a new recipe becomes available.
Recipes
Recipes - Intro
Gato GraphQL is a productivity tool for interacting with data in your WordPress site. You can think of it as a Swiss Army knife for dealing with data in a WordPress site, as it allows to retrieve, manipulate and store again any piece of data, in any desired way.
Searching WordPress data
Examples on using Gato GraphQL to search for posts (and also users, comments, and taxonomies) by meta key and value.
Querying dynamic data
Gato GraphQL allows us to dynamically compute data, input it back into the query, and affect the response with granular control. Here is how.
Exposing public and private endpoints
Gato GraphQL expands enables exposing multiple custom endpoints, each of them tailored to some specific need, and these can be made private and public. When should we use each?
Complementing WP-CLI
Recipe on how to use Gato GraphQL to find the data we need, and then inject it into WP-CLI.
Injecting multiple resources into WP-CLI
Recipe on retrieving multiple user IDs while executing a single GraphQL query, and injecting these into WP-CLI.
Feeding data to blocks in the editor
Content in the the WordPress editor is created via (Gutenberg) blocks, which fetch their data from the server via an API. WordPress core uses the WP REST API, but we can also use Gato GraphQL to power our own blocks.
DRY code for blocks in Javascript and PHP
Recipe showing how to use Gato GraphQL to have a single source of truth to fetch data for both the client and server-sides when rendering Gutenberg blocks.
Mapping JS components to (Gutenberg) blocks
Recipe presenting an example Preact app that queries for block data and maps it into customized JavaScript components.
Duplicating a blog post
Duplicating a post is an example of Gato GraphQL's ability to retrieve, manipulate and store again data in the site.
Duplicating multiple blog posts at once
Recipe on duplicating multiple posts with a single GraphQL request.
Customizing content for different users
Recipe on retrieving a different response in a field depending on some piece of queried data, such as the roles of the logged-in user.
Search, replace, and store again
Examples of content adaptations involving search and replace, and then storing the resource back to the DB.
Adapting content in bulk
Recipe on adapting content in bulk, updating the title and excerpt for multiple posts with a single GraphQL request.
Site migrations
We can execute a batch of GraphQL queries to adapt the content in the site when migrating it to a new domain, moving pages to a different URL, or others.
Inserting/Removing a (Gutenberg) block in bulk
Recipe on updating posts by modifying their (Gutenberg) block's HTML content, useful for adding a block to all posts in the site before a campaign, and removing it right afterwards.
Retrieving structured data from blocks
Recipe on iterating the (Gutenberg) blocks in the post and extracting the attributes from deep within the block structure, as to unlock these attributes to be fed into any functionality in our site.
Translating block content in a post to a different language
Recipe on translating a post to the desired language, with full support for (Gutenberg) blocks.
Bulk translating block content in multiple posts to a different language
Recipe for translating multiple posts at once (in bulk), while executing a single call to the Google Translate API containing all text to translate from all the posts.
Modifying (and storing again) the image URLs from all Image blocks in a post
Recipe on iterating the inner structure of (Gutenberg) blocks, extracting desired items, modifying them, and storing them again in the DB.
Sending emails with pleasure
Recipes demonstrating several capabilities by Gato GraphQL to send emails.
Sending a daily summary of activity
Integrating Gato GraphQL with WP-Cron, as to automate the execution GraphQL queries that perform admin tasks, with some time interval.
Sending a notification when there is a new post
Examples on automating tasks in the application, such as sending a notification email to the admin when there is a new post.
Automatically adding a mandatory block
Whenever a new post is created, we can use the automation features to validate and modify the content of the post. This recipe checks if a certain mandatory block is present in the post and, whenever missing, it adds it.
Interacting with external services via webhooks
Recipe on creating Persisted Queries that act as webhooks.
Retrieving data from an external API
Recipe on fetching data from an external API using the HTTP Client fields.
Not leaking credentials when connecting to services
Recipe on retrieving credentials from an environment value, as to avoid them getting printed in the response or logs, thus avoiding security risks.
Combining user data from different sources
Recipe on combining the data from two or more sources, and then executing some operation with the combined data.
Handling errors when connecting to services
How to skip executing the rest of the GraphQL query after an error occurs.
Creating an API gateway
Recipe on creating an API gateway that retrieves the latest artifacts from the GitHub Actions API, and extracts their URL to be downloaded, avoiding the need for the client to be signed in to GitHub.
Translating content from URL
Combining HTTP requests with calling the Google Translate API, we can translate the content from any URL.
Transforming data from an external API
Examples on adapting the response from an external API to anything we need it to be.
Filtering data from an external API
If the external API does not allow filtering by a certain property that we need, we can use Gato GraphQL to iterate over the entries in the API response, and remove those ones that do not satifsy our condition.
Pinging external services
Recipe on pinging external services about new resources added to our website, passing along data both stored in the website and/or provided via parameters or headers.
Updating large sets of data
How to update thousands of resources in a single action.
Importing a post from another WordPress site
Recipe on how we can keep WordPress sites in sync, by importing a post from some WordPress site into our local WordPress site.
Distributing content from an upstream to multiple downstream sites
Recipe on implementing a distributed server architecture using Gato GraphQL extensions on the upstream WordPress site only.
Automatically sending newsletter subscribers from InstaWP to Mailchimp
Using InstaWP + Gato GraphQL to forward webhook data into an API.