The Experimental WooCommerce Dual API is now a plugin

WooCommerce 10.9 introduced an experimental WooCommerce Dual API: a code-first architecture that generates GraphQL endpoints from PHP classes. In WooCommerce 11.2 we are removing this experimental dual API engine from WooCommerce core and instead offering it as a dedicated plugin.

Moving the dual API engine to a separate plugin allows us to iterate in a more flexible way on its development, since we’ll be able to offer updates without being tied to specific WooCommerce core releases. This feature was always gated behind a feature flag, so this change only affects developers who opted into it and extended it.

Removing the proof-of-concept API

The built-in proof-of-concept API for products and coupons, available in WooCommerce 10.9 through 11.1, is removed in WooCommerce 11.2. If you were using those proof-of-concept endpoints, you will need to stop using them or build an equivalent API in your own extension. The WooCommerce Dual API plugin does not restore those endpoints.

The dual API engine is still useful for WooCommerce extension developers willing to develop their own dual APIs. If that’s your case, this is what changes:

  • The feature flag that enabled the engine is no longer available. Instead, installing and activating the dual API plugin makes the engine available. The plugin requires WooCommerce 11.2 or newer and PHP 8.1 or newer. If your extension depends on the engine, declare both dependencies in its plugin header: Requires Plugins: woocommerce, woocommerce-dual-api.
  • The API builder script is now in the WooCommerce Dual API plugin. To use it, install the plugin or clone its repository locally.
  • The documentation is now in the dual API plugin repository (also available as a GitHub pages site).
  • The WooCommerce Dual API plugin must be installed and active on the same site as your extension. It provides the engine; your extension registers its own dedicated GraphQL endpoint. Here’s a snippet that shows how to do it, taken from the WooCommerce simple events example plugin:
use AutomatticWooCommerceApiInfrastructureMain as DualApiMain;

add_action(
	'plugins_loaded',
	static function () {
		if ( method_exists( DualApiMain::class, 'register_graphql_endpoint' ) ) {
			DualApiMain::register_graphql_endpoint(
				__DIR__,
				'wc',
				'/graphql/simple-events'
			);
		}
	}
);

The Dual API remains experimental

The WooCommerce Dual API remains experimental. Everything under the Automattic\WooCommerce\Api namespace can change in backwards-incompatible ways, or be removed, in any release. Do not use it in production extensions.

We want to hear from you. Are you finding this dual API engine useful? Would you like to see it as part of WooCommerce in non-experimental state? Any changes to suggest? Share feedback in the the dedicated GitHub discussion.


Leave a Reply

Your email address will not be published. Required fields are marked *