Queries LibraryDistribute content from an upstream to multiple downstream WordPress sites
Distribute content from an upstream to multiple downstream WordPress sites
Let's say that a media company has a network of WordPress sites for different regions, with every news article being published on a site or not only if it's suitable for that region.
For this situation, it makes sense to implement an architecture where:
All content is published to (and edited in) a single upstream WordPress site, which acts as the single source of truth for content
Suitable content is distributed to (but not edited in) each of the regional downstream WordPress sites
This query satisfies this architecture, with the upstream WordPress site needing to have the relevant Gato GraphQL extensions active, while the downstream sites need only have the free Gato GraphQL plugin.
The query is executed on the upstream WordPress site, to synchronize the content of the updated post to the relevant downstream sites, using the post slug as the common identifier across sites.
It includes transactional logic, so that whenever the update fails on any downstream site, whether because the HTTP request failed (as when the server is down) or because the GraphQL query produced errors (as if there is no post with the provided slug), the mutation is then reverted on all downstream sites.
Notice that the downstream domains are provided via meta property "downstream_domains" from the post, which contains an array with the domains of the downstream sites that the post must be distributed to. If this meta property does not exist, it then retrieves option "downstream_domains" from the wp_options table, which contains the list of all the downstream domains.
It then logs the user into each of the downstream sites (using the same $username and $userPassword) and executes the mutation to update the post content. If any downstream site produces an error, the mutation is reverted on all downstream sites
This query requires the endpoint to have Nested Mutations enabled.