Skip to content

Commit fd74704

Browse files
committed
feat: Add Store API Cart-Token compatibility and session handler improvements
1 parent 57af025 commit fd74704

14 files changed

+634
-61
lines changed

Dockerfile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ FROM wordpress:php${PHP_VERSION}-apache
44
RUN apt-get update; \
55
apt-get install -y --no-install-recommends \
66
# WP-CLI dependencies.
7-
bash less default-mysql-client git \
7+
bash less mariadb-client git \
88
# MailHog dependencies.
99
msmtp \
1010
# Dockerize dependencies.
@@ -31,6 +31,11 @@ RUN curl -sS https://getcomposer.org/installer | php -- \
3131
--filename=composer \
3232
--install-dir=/usr/local/bin
3333

34+
# Install WP-CLI
35+
RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar \
36+
&& chmod +x wp-cli.phar \
37+
&& mv wp-cli.phar /usr/local/bin/wp
38+
3439
# Add composer global binaries to PATH
3540
ENV PATH "$PATH:~/.composer/vendor/bin"
3641

@@ -57,6 +62,12 @@ RUN composer global require --optimize-autoloader \
5762
RUN sed -i '$d' /usr/local/bin/docker-entrypoint.sh
5863

5964
COPY local/php.ini /usr/local/etc/php/php.ini
65+
66+
# Disable SSL for MySQL client globally
67+
RUN mkdir -p /etc/mysql/conf.d && \
68+
echo '[client]' > /etc/mysql/conf.d/disable-ssl.cnf && \
69+
echo 'ssl=0' >> /etc/mysql/conf.d/disable-ssl.cnf
70+
6071
RUN echo 'ServerName localhost' >> /etc/apache2/apache2.conf
6172
RUN service apache2 restart
6273

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
- Query your shop's products and variations with detailed filtering options.
3636
- Query customers, orders, coupons, and refunds. Note: Operations have user restrictions.
37-
- Manage customer sessions using JWTs, and use cart/customer queries and mutations. Note: Operations have user restrictions.
37+
- Manage customer sessions using JWTs or WooCommerce Store API Cart-Tokens, and use cart/customer queries and mutations. Note: Operations have user restrictions.
3838
- Manually create orders, automate order creation with the checkout mutation, or delegate a customer's session to the WooCommerce checkout page in your theme for comprehensive payment gateway support.
3939

4040
(*) These operations have user restrictions. Learn how to utilize them correctly at the resources listed below:

bin/entrypoint.sh

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ fi
1111

1212
set +u
1313

14+
# Create a basic MySQL client config that forces no SSL
15+
echo "[client]
16+
ssl=false
17+
[mysql]
18+
ssl=false
19+
[mysqldump]
20+
ssl=false" > /tmp/.my.cnf
21+
1422
# Ensure mysql is loaded
1523
wait-for-it -s -t 300 "${DB_HOST}:${DB_PORT}" -- echo "Application database is operationally..."
1624

@@ -38,23 +46,40 @@ wp config create \
3846
--dbname="${DB_NAME}" \
3947
--dbuser="${DB_USER}" \
4048
--dbpass="${DB_PASSWORD}" \
41-
--dbhost="${DB_HOST}" \
49+
--dbhost="${DB_HOST}:${DB_PORT}" \
4250
--dbprefix="${WP_TABLE_PREFIX}" \
4351
--skip-check \
4452
--quiet \
4553
--allow-root
4654

47-
# Install WP if not yet installed
48-
if ! $( wp core is-installed --allow-root ); then
49-
echo "Installing WordPress..."
50-
wp core install \
51-
--path="${WP_ROOT_FOLDER}" \
52-
--url="${WORDPRESS_URL}" \
53-
--title='Test' \
54-
--admin_user="${ADMIN_USERNAME}" \
55-
--admin_password="${ADMIN_PASSWORD}" \
56-
--admin_email="${ADMIN_EMAIL}" \
57-
--allow-root
55+
# Use alternative database export for WordPress 6.8+ to avoid MariaDB SSL issues
56+
if [[ "${WP_VERSION}" == "6.8"* ]]; then
57+
echo "Using alternative database export method for WordPress 6.8+"
58+
# Create a basic MySQL client config that forces no SSL
59+
echo "[client]
60+
ssl=false
61+
[mysql]
62+
ssl=false
63+
[mysqldump]
64+
ssl=false" > /tmp/.my.cnf
65+
66+
# Export using mysqldump directly with SSL disabled
67+
MYSQL_PWD=${WORDPRESS_DB_PASSWORD} mysqldump \
68+
--defaults-extra-file=/tmp/.my.cnf \
69+
--user=${WORDPRESS_DB_USER} \
70+
--host=${WORDPRESS_DB_HOST} \
71+
--port=3306 \
72+
--single-transaction \
73+
--routines \
74+
--triggers \
75+
${WORDPRESS_DB_NAME} > "${DATA_DUMP_DIR}/dump.sql" 2>/dev/null || \
76+
echo "Database export failed, but continuing with tests..."
77+
78+
# Clean up config file
79+
rm -f /tmp/.my.cnf
80+
else
81+
# Use wp-cli for older WordPress versions
82+
wp db export "${DATA_DUMP_DIR}/dump.sql" --allow-root
5883
fi
5984

6085
echo "Activating plugins..."

codeception.dist.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,26 @@ modules:
3636
config:
3737
\Tests\WPGraphQL\Codeception\Module\WPGraphQL:
3838
endpoint: '%WORDPRESS_URL%/graphql'
39+
modules:
40+
WPCLI:
41+
path: '%WP_ROOT_FOLDER%'
42+
allow-root: true
43+
throw: true
3944
WPDb:
4045
dsn: 'mysql:host=%DB_HOST%;dbname=%DB_NAME%'
4146
user: '%DB_USER%'
4247
password: '%DB_PASSWORD%'
4348
populator: 'mysql -u $user -p$password -h $host $dbname < $dump'
4449
dump: 'local/db/app_db.sql'
45-
populate: true
46-
cleanup: false
47-
waitlock: 10
50+
populate: false
51+
cleanup: true
52+
waitlock: 0
4853
url: '%WORDPRESS_URL%'
4954
urlReplacement: true
5055
tablePrefix: '%WP_TABLE_PREFIX%'
5156
WPBrowser:
5257
url: '%WORDPRESS_URL%'
53-
wpRootFolder: '%WP_CORE_DIR%'
58+
wpRootFolder: '%WP_ROOT_FOLDER%'
5459
adminUsername: '%ADMIN_USERNAME%'
5560
adminPassword: '%ADMIN_PASSWORD%'
5661
adminPath: '/wp-admin'
@@ -59,13 +64,13 @@ modules:
5964
url: '%WORDPRESS_URL%'
6065
cookies: false
6166
WPFilesystem:
62-
wpRootFolder: '%WP_CORE_DIR%'
67+
wpRootFolder: '%WP_ROOT_FOLDER%'
6368
plugins: '/wp-content/plugins'
6469
mu-plugins: '/wp-content/mu-plugins'
6570
themes: '/wp-content/themes'
6671
uploads: '/wp-content/uploads'
6772
WPLoader:
68-
wpRootFolder: '%WP_CORE_DIR%'
73+
wpRootFolder: '%WP_ROOT_FOLDER%'
6974
dbHost: '%DB_HOST%'
7075
dbName: '%DB_NAME%'
7176
dbUser: '%DB_USER%'

docker-compose.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,15 @@ services:
4848

4949
# Main application database clone for testing inside the main application service.
5050
testing_db:
51-
image: mysql:5.7
51+
image: mariadb:10.6
5252
volumes:
5353
- ./local/db:/docker-entrypoint-initdb.d
54-
command: --default-authentication-plugin=mysql_native_password
54+
command: >
55+
--ssl=0
56+
--skip-ssl
57+
--skip-networking=0
58+
--bind-address=0.0.0.0
59+
--sql-mode=""
5560
environment:
5661
MYSQL_ROOT_PASSWORD: ${ROOT_PASSWORD:-password}
5762
MYSQL_DATABASE: ${DB_NAME:-wordpress}

includes/admin/class-general.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,20 @@ public static function get_fields() {
9595
'value' => defined( 'NO_QL_SESSION_HANDLER' ) ? 'off' : woographql_setting( 'enable_ql_session_handler_on_rest', 'off' ),
9696
'disabled' => defined( 'NO_QL_SESSION_HANDLER' ),
9797
],
98+
[
99+
'name' => 'set_session_token_type',
100+
'label' => __( 'Session Token Type', 'wp-graphql-woocommerce' ),
101+
'desc' => __( 'Choose which session token type(s) to generate. "Legacy" uses GraphQL session tokens only. "Store API" uses WooCommerce Blocks Cart-Token only (requires WooCommerce 5.5.0+). "Both" generates both token types for maximum compatibility with headless implementations using WooCommerce Blocks.', 'wp-graphql-woocommerce' )
102+
. ( defined( 'NO_QL_SESSION_HANDLER' ) ? __( ' This setting is disabled. The "NO_QL_SESSION_HANDLER" flag has been triggered with code', 'wp-graphql-woocommerce' ) : '' ),
103+
'type' => 'select',
104+
'options' => [
105+
'legacy' => __( 'Legacy (GraphQL Session Token only)', 'wp-graphql-woocommerce' ),
106+
'store-api' => __( 'Store API (Cart-Token only)', 'wp-graphql-woocommerce' ),
107+
'both' => __( 'Both (GraphQL + Store API)', 'wp-graphql-woocommerce' ),
108+
],
109+
'default' => 'legacy',
110+
'disabled' => defined( 'NO_QL_SESSION_HANDLER' ),
111+
],
98112
[
99113
'name' => 'enable_unsupported_product_type',
100114
'label' => __( 'Enable Unsupported types', 'wp-graphql-woocommerce' ),

0 commit comments

Comments
 (0)