Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b93a7a2
POC. Can you log data with monolog for WPGraphQL. Not production ready.
colinmurphy Jul 10, 2025
c9ba020
Merge branch 'main' into poc-wpgraphql-logging-monolog
colinmurphy Jul 21, 2025
1ac8b5a
Created branch off POC. Tidied up. Added QA and unit tests setup to t…
colinmurphy Jul 22, 2025
4ea7bdc
Added .env.ci for tests.
colinmurphy Jul 22, 2025
b604a64
Added missing test directory.
colinmurphy Jul 22, 2025
1ccb8af
Added Database entity and plugin hook class to add/drop table on acti…
colinmurphy Jul 23, 2025
d9e9edf
Fixed QA errors.
colinmurphy Jul 23, 2025
2b24ee4
Updated Database entity with CRUD operations. Added tests.
colinmurphy Jul 24, 2025
1ac0bfa
Added WordPress Database Handler with unit tests.
colinmurphy Jul 24, 2025
915c25e
Created POC (not complete) with database handler, graphql query proce…
colinmurphy Jul 28, 2025
5dc17d6
Fixing issue for new plugins that do not exist when creating a plugin…
colinmurphy Jul 28, 2025
60c6dd7
Fix plugin slug script to use correct PR head SHA
colinmurphy Jul 28, 2025
f37f125
Added fixes for other workflows.
colinmurphy Jul 28, 2025
486539c
Updated code quality to check min PHP version from the composer.json …
colinmurphy Jul 28, 2025
198a415
Updated wording.
colinmurphy Jul 28, 2025
6c7b52f
Fixes for logger service and query processor.
colinmurphy Jul 28, 2025
9e26179
Improved tests for writing data to be more accurate.
colinmurphy Jul 28, 2025
2590baa
Added tests for WPGRaphQLQueryProcessor
colinmurphy Jul 28, 2025
8127de1
Update logger service instance to get singleton instance by channel n…
colinmurphy Jul 29, 2025
a17b273
Updated README
colinmurphy Jul 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/scripts/get_plugin_slug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ UNIQUE_PLUGINS=($(printf '%s\n' "${PLUGINS[@]}" | sort -u))
# Find the first plugin that actually exists
PLUGIN_SLUG=""
for plugin in "${UNIQUE_PLUGINS[@]}"; do
if [ -d "plugins/$plugin" ]; then
if [ -d "plugins/$plugin" ] || [[ " ${CHANGED_FILES[@]} " =~ "plugins/$plugin/" ]]; then
PLUGIN_SLUG="$plugin"
echo "Found existing plugin directory: $PLUGIN_SLUG"
echo "Found plugin in changes or directory: $PLUGIN_SLUG"
break
fi
done
Expand All @@ -45,3 +45,6 @@ if [ -z "$PLUGIN_SLUG" ]; then
fi

echo "slug=$PLUGIN_SLUG" >> "$GITHUB_OUTPUT"

echo "Changed files: $CHANGED_FILES"
echo "Detected plugin(s): ${UNIQUE_PLUGINS[*]}"
26 changes: 24 additions & 2 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
outputs:
plugins: ${{ steps.detect.outputs.plugins }}
has-plugins: ${{ steps.detect.outputs.has-plugins }}
php-version: ${{ steps.detect-php-version.outputs.php-version }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -34,11 +35,13 @@ jobs:
if [ "${{ github.event_name }}" = "push" ]; then
bash .github/scripts/get_plugin_slug.sh main
else
bash .github/scripts/get_plugin_slug.sh ${{ github.event.pull_request.base.sha }} ${{ github.sha }}
bash .github/scripts/get_plugin_slug.sh \
${{ github.event.pull_request.base.sha }} \
${{ github.event.pull_request.head.sha }}
fi

- name: Detect changed plugins with quality config
id: detect
id: detect-plugin-slug
run: |
if [ -z "${{ steps.plugin.outputs.slug }}" ]; then
echo "No plugin slug detected"
Expand All @@ -58,6 +61,23 @@ jobs:
echo "has-plugins=false" >> $GITHUB_OUTPUT
echo "ℹ️ No phpcs.xml found for plugin: $PLUGIN, skipping quality checks"
fi
- name: Detect PHP version from composer.json
id: detect-php-version
run: |
PLUGIN="${{ steps.plugin.outputs.slug }}"
PHP_VERSION="7.4"
if [ -f "plugins/$PLUGIN/composer.json" ]; then
DETECTED_VERSION=$(jq -r '.require["php"] // empty' plugins/$PLUGIN/composer.json | grep -oE '[0-9]+\.[0-9]+' | head -1)
if [ -n "$DETECTED_VERSION" ]; then
PHP_VERSION="$DETECTED_VERSION"
echo "Detected PHP version $PHP_VERSION from composer.json"
else
echo "No PHP version found in composer.json, using default $PHP_VERSION"
fi
else
echo "No composer.json found, using default PHP version $PHP_VERSION"
fi
echo "php-version=$PHP_VERSION" >> $GITHUB_OUTPUT
quality-checks:
needs: detect-plugins
if: needs.detect-plugins.outputs.has-plugins == 'true'
Expand All @@ -75,3 +95,5 @@ jobs:
uses: ./.github/actions/code-quality
with:
working-directory: plugins/${{ matrix.plugin }}
php-version: ${{ needs.detect-plugins.outputs.php-version }}
composer-options: '--no-progress --no-suggest'
4 changes: 3 additions & 1 deletion .github/workflows/codeception.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ jobs:
if [ "${{ github.event_name }}" = "push" ]; then
bash .github/scripts/get_plugin_slug.sh main
else
bash .github/scripts/get_plugin_slug.sh ${{ github.event.pull_request.base.sha }} ${{ github.sha }}
bash .github/scripts/get_plugin_slug.sh \
${{ github.event.pull_request.base.sha }} \
${{ github.event.pull_request.head.sha }}
fi

- name: Detect changed plugins with quality config
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ jobs:
if [ "${{ github.event_name }}" = "push" ]; then
bash .github/scripts/get_plugin_slug.sh main
else
bash .github/scripts/get_plugin_slug.sh ${{ github.event.pull_request.base.sha }} ${{ github.sha }}
bash .github/scripts/get_plugin_slug.sh \
${{ github.event.pull_request.base.sha }} \
${{ github.event.pull_request.head.sha }}
fi

- name: Detect changed plugin with E2E config
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/plugin-artifact-for-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ jobs:
- name: Get changed plugin directory
id: plugin
run: |
bash .github/scripts/get_plugin_slug.sh ${{ github.event.pull_request.base.sha }} ${{ github.sha }}
bash .github/scripts/get_plugin_slug.sh \
${{ github.event.pull_request.base.sha }} \
${{ github.event.pull_request.head.sha }}

- name: Create plugin artifact
uses: ./.github/actions/create-plugin-artifact
Expand Down
36 changes: 36 additions & 0 deletions plugins/wpgraphql-logging/.distignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/.devcontainer
/.git
/.github
/.idea
/.log
/.vscode
/.wordpress-org
/bin
/docker
/docker-output
/docs
/img
/phpstan
/plugin-build
/tests

.coveralls.yml
.distignore
.dockerignore
.DS_Store
.env
.env.dist
.gitattributes
.gitignore
.phpcs.xml
.phpcs.xml.dist
.travis.yml
CHANGELOG.md
codeception.dist.yml
codeception.yml
composer.json
composer.lock
docker-compose.yml
phpstan.neon.dist
README.md
schema.graphql
59 changes: 59 additions & 0 deletions plugins/wpgraphql-logging/.docker/.env.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
PLUGIN_SLUG=wpgraphql-logging

# Configure these to match your existing testing environment or the one you want to create with Docker.
## Usually, these values should match the ones in the `wp-config.php` file.
## If using Local by Flywheel, you can `open AdminerEvo` and find the values in the URL: `http://localhost:{DB_PORT}/?username={DB_USER}&db={DB_NAME}`
## NOTE: Codeception may modify or the database during testing. If you want to preserve your local data, create a new database and use that for the `DB_NAME`.
DB_NAME=wordpress
DB_HOST=mysql
DB_USER=root
DB_PASSWORD=password
DB_PORT=3306

# The local path to the WordPress root directory, the one containing the wp-load.php file.
## This can be a relative path from the directory that contains the codeception.yml file, or an absolute path.
## If you are using Local by Flywheel, you can find the path in the Local by Flywheel app under the site's settings.
WORDPRESS_ROOT_DIR="/var/www/html"

# This table prefix used by the WordPress site, and in Acceptance tests.
WORDPRESS_TABLE_PREFIX=wp_

# The URL and domain of the WordPress site, and in Acceptance tests.
## If the port is in use, you can change it to a different port.
WORDPRESS_URL=http://localhost
WORDPRESS_DOMAIN=localhost
WORDPRESS_ADMIN_PATH=/wp-admin

# The username and password of the administrator user of the WordPress site, and in Acceptance tests.
WORDPRESS_ADMIN_USER=admin
WORDPRESS_ADMIN_PASSWORD=password
WORDPRESS_ADMIN_EMAIL=admin@example.com

# Tests will require a MySQL database to run.
# Do not use a database that contains important data!
WORDPRESS_DB_HOST=${DB_HOST}
WORDPRESS_DB_USER=${DB_USER}
WORDPRESS_DB_PASSWORD=${DB_PASSWORD}
WORDPRESS_DB_NAME=${DB_NAME}
WORDPRESS_DB_PORT=${DB_PORT}

# WPUnit tests will use these variables instead.
# By default this is the same as WordPress
TEST_DB_HOST=${WORDPRESS_DB_HOST}
TEST_DB_USER=${WORDPRESS_DB_USER}
TEST_DB_PASSWORD=${WORDPRESS_DB_PASSWORD}
TEST_DB_NAME=${WORDPRESS_DB_NAME}
TEST_DB_PORT=${WORDPRESS_DB_PORT}
# The Integration suite will use this table prefix for the WordPress tables.
TEST_TABLE_PREFIX=test_

# The DSN used by Acceptance tests.
TEST_DB_DSN="mysql:host=${TEST_DB_HOST};port=${TEST_DB_PORT};dbname=${TEST_DB_NAME}"

# The following variables are used to determine test behavior.

# Include 3rd party plugins (e.g. WooCommerce) in the tests.
# Skips recreating the database before running the tests.
SKIP_DB_CREATE=false
# Skips configuring the WordPress installation
SKIP_WP_SETUP=false
83 changes: 83 additions & 0 deletions plugins/wpgraphql-logging/.docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
###############################################################################
# Pre-configured WordPress Installation w/ WPGraphQL Logging Plugin
# For testing only, use in production not recommended. #
###############################################################################

# Use build args to get the right wordpress + php image
ARG WP_VERSION
ARG PHP_VERSION

FROM wordpress:${WP_VERSION:-6.8}-php${PHP_VERSION:-8.2}

# Needed to specify the build args again after the FROM command.
ARG WP_VERSION
ARG PHP_VERSION

# Save the build args for use by the runtime environment
ENV WP_VERSION=${WP_VERSION}
ENV PHP_VERSION=${PHP_VERSION}

SHELL [ "/bin/bash", "-c" ]

# Install required packages
RUN apt-get update && \
apt-get -y install \
git \
ssh \
tar \
gzip \
mariadb-client \
net-tools

# Needed for Codeception WPDB test integration.
RUN docker-php-ext-install pdo pdo_mysql

# Install XDebug 3
RUN if [[ $PHP_VERSION == 7* ]]; then pecl install xdebug-3.1.5; else pecl install xdebug; fi \
&& mkdir -p /usr/local/etc/php/conf.d/disabled \
&& echo "zend_extension=xdebug" > /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini \
&& echo "xdebug.mode=develop,debug,coverage" >> /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini \
&& echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini \
&& echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini \
&& echo "xdebug.client_port=9003" >> /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini \
&& echo "xdebug.max_nesting_level=512" >> /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini \
;

# Set xdebug configuration off by default. Set USING_XDEBUG=1 in the runtime environment to enable it.
ENV USING_XDEBUG=0

# Install PCOV
# This is needed for Codeception / PHPUnit to track code coverage
RUN apt-get install zip unzip -y \
&& pecl install pcov

# Install Dockerize
ENV DOCKERIZE_VERSION=v0.7.0
RUN curl -L -O https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz

# Install composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
RUN chmod +x /usr/local/bin/composer

# Install WP-CLI
RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar \
&& chmod +x wp-cli.phar \
&& mv wp-cli.phar /usr/local/bin/wp

# Install nvm, Node.js, and npm
ENV NVM_DIR=/usr/local/nvm
ENV NODE_VERSION=20

RUN mkdir -p $NVM_DIR
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash \
&& . $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm use $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& npm install -g npm

# Setup the container for testing
COPY init-docker.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/init-docker.sh
26 changes: 26 additions & 0 deletions plugins/wpgraphql-logging/.docker/init-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Exit if any command fails.
set -e

# Wait for the database
dockerize -wait tcp://"${WORDPRESS_DB_HOST}":3306 -timeout 1m

# Get the current user

cd "$WORDPRESS_ROOT_DIR/wp-content/plugins/$PLUGIN_SLUG"

# Load NVM
source $NVM_DIR/nvm.sh
nvm use $NODE_VERSION

# Setup the test environment
chmod +x ./bin/install-test-env.sh

bash -c "./bin/install-test-env.sh"

echo "Setting permissions"
chmod -R 777 "$WORDPRESS_ROOT_DIR/wp-content/plugins/$PLUGIN_SLUG"

# Go back to the root directory
cd "$WORDPRESS_ROOT_DIR"
18 changes: 18 additions & 0 deletions plugins/wpgraphql-logging/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab


[*.md]
trim_trailing_whitespace = false
65 changes: 65 additions & 0 deletions plugins/wpgraphql-logging/.env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
PLUGIN_SLUG=wpgraphql-logging

# Configure these to match your existing testing environment or the one you want to create with Docker.
## Usually, these values should match the ones in the `wp-config.php` file.
## If using Local by Flywheel, you can `open AdminerEvo` and find the values in the URL: `http://localhost:{DB_PORT}/?username={DB_USER}&db={DB_NAME}`
## NOTE: Codeception may modify or the database during testing. If you want to preserve your local data, create a new database and use that for the `DB_NAME`.
DB_NAME=wordpress
# localhost creates issues with wp config create command
DB_HOST=127.0.0.1
DB_USER=root
DB_PASSWORD=password
DB_PORT=3306

# The local path to the WordPress root directory, the one containing the wp-load.php file.
## This can be a relative path from the directory that contains the codeception.yml file, or an absolute path.
## If you are using Local by Flywheel, you can find the path in the Local by Flywheel app under the site's settings.
WORDPRESS_ROOT_DIR="/tmp/wordpress"

# This table prefix used by the WordPress site, and in Acceptance tests.
WORDPRESS_TABLE_PREFIX=wp_

# The URL and domain of the WordPress site, and in Acceptance tests.
## If the port is in use, you can change it to a different port.
WORDPRESS_URL=http://localhost
WORDPRESS_DOMAIN=localhost
WORDPRESS_ADMIN_PATH=/wp-admin

# The username and password of the administrator user of the WordPress site, and in Acceptance tests.
WORDPRESS_ADMIN_USER=admin
WORDPRESS_ADMIN_PASSWORD=password
WORDPRESS_ADMIN_EMAIL=admin@example.com

# Tests will require a MySQL database to run.
# Do not use a database that contains important data!
WORDPRESS_DB_HOST=${DB_HOST}
WORDPRESS_DB_USER=${DB_USER}
WORDPRESS_DB_PASSWORD=${DB_PASSWORD}
WORDPRESS_DB_NAME=${DB_NAME}
WORDPRESS_DB_PORT=${DB_PORT}

# WPUnit tests will use these variables instead.
# By default this is the same as WordPress
TEST_DB_HOST=${WORDPRESS_DB_HOST}
TEST_DB_USER=${WORDPRESS_DB_USER}
TEST_DB_PASSWORD=${WORDPRESS_DB_PASSWORD}
TEST_DB_NAME=${WORDPRESS_DB_NAME}
TEST_DB_PORT=${WORDPRESS_DB_PORT}
# The Integration suite will use this table prefix for the WordPress tables.
TEST_TABLE_PREFIX=test_

# The DSN used by Acceptance tests.
TEST_DB_DSN="mysql:host=${TEST_DB_HOST};port=${TEST_DB_PORT};dbname=${TEST_DB_NAME}"

# The following variables are used to determine test behavior.

# Include 3rd party plugins (e.g. WooCommerce) in the tests.
INCLUDE_EXTENSIONS=true
# Skips recreating the database before running the tests.
SKIP_DB_CREATE=false
# Skips configuring the WordPress installation
SKIP_WP_SETUP=false
# Skips cleanup after the test suite run.
SKIP_TESTS_CLEANUP=true
# The default Codeception suite to run.
SUITES=wpunit
Loading