WPGraphQL WooCommerce
Quick Install
- Install & activate WooCommerce
- Install & activate WPGraphQL
- (Optional) Install & activate WPGraphQL-JWT-Authentication to add a
loginmutation that returns a JSON Web Token. - Clone or download the zip of this repository into your WordPress plugin directory & activate the WP GraphQL WooCommerce plugin
What does this plugin do?
It adds WooCommerce functionality to the WPGraphQL schema using WooCommerce's CRUD objects.
Working Features
- Query product, customers, coupons, order, refund, product variations.
Upcoming Features
- Adminstrator mutations. Eg. Creating and deleting products, coupons, and refunds.
Playground
Feel free to test out the extension using the playground. The playground allows you to execute queries and mutations, as well as view the schema.
Unit Tests
Until the documentation is in full effect, it's recommended that a GraphiQL-based tool like WPGraphiQL be used to view the GraphQL schema, an alternative to this is viewing the unit tests located in tests/wpunit directory. Which are constantly updated along with the project. If you're interested in contributing when I begin accepting contribution or simply want to run the tests. Follow the instruction below.
Prerequisties
Setup
-
Make sure all dependencies are install by running
composer installfrom the CMD/Terminal in the project directory. -
Next the copy 5 distributed files with the
.distin there filenames. For instance.env.distbecomes.envandwpunit.suite.dist.ymlbecomeswpunit.suite.yml. The distributed files and what their copied names should are as follows.tests/acceptance.suite.dist.yml=>tests/acceptance.suite.ymltests/functional.suite.dist.yml=>tests/functional.suite.ymltests/wpunit.suite.dist.yml=>tests/wpunit.suite.ymlcodeception.dist.yml=>codeception.yml.env.dist=>.env
-
Next open
.envand alter to make you usage.# Shared TEST_DB_NAME="wpgraphql_woocommerce_test" TEST_DB_HOST="127.0.0.1" TEST_DB_USER="root" TEST_DB_PASSWORD="" # Install script SKIP_DB_CREATE=false # Codeception TEST_SITE_WP_ADMIN_PATH="/wp-admin" TEST_SITE_DB_NAME="wpgraphql_woocommerce_test" TEST_SITE_DB_HOST="127.0.0.1" TEST_SITE_DB_USER="root" TEST_SITE_DB_PASSWORD="" TEST_SITE_TABLE_PREFIX="wp_" TEST_TABLE_PREFIX="wp_" TEST_SITE_WP_URL="http://localhost" TEST_SITE_WP_DOMAIN="localhost" TEST_SITE_ADMIN_EMAIL="admin@localhost" TEST_SITE_ADMIN_USERNAME="admin" TEST_SITE_ADMIN_PASSWORD="password"Sharedvariables are as the comment implies, variables shared in both theinstall-wp-testsscript and the Codeception configuration. The variable names should tell you what they mean.Install scriptvariables are specified to theinstall-wp-testsscript, and most likely won't changed. I've listed their meaning below.WP_VERSIONWordPress version used for testingSKIP_DB_CREATEShould database creation be skipped?
Codeceptionvariables are specified to the Codeception configuration. View the config files and Codeception's Docs for more info on them.
-
Once you have finish modifying the
.envfile. Runcomposer install-wp-testsfrom the project directory. -
Upon success you can begin running the tests.
Running tests
To run test use the command vendor/bin/codecept run [suite [test [:test-function]]].
If you use the command with at least a suite specified, Codeception will run all tests, however this is not recommended. Running a suite vendor/bin/codecept run wpunit or a test vendor/bin/codecept run CouponQueriesTest is recommended. Running a single test-function like vendor/bin/codecept run ProductQueriesTest:testProductsQueryAndWhereArgs is also possible.
To learn more about the usage of Codeception with WordPress view the Documentation
Functional and Acceptance Tests (Docker/Docker-Compose required)
It's possible to run functional and acceptance tests, but is very limited at the moment. The script docker entrypoint script runs all three suites (acceptance, functional, and wpunit) at once. This will change eventually, however as of right now, this is the limitation.
Running tests
Even though the two suite use a Docker environment to run, the docker environment relies on a few environmental variables defined in .env and a volume source provided by the test install script.
0. Ensure that you can copy .env.dist to .env.
- First you must run
composer install-wp-teststo ensure the required dependencies are available. - Next run
docker-compose buildfrom the terminal in the project root directory, to build the docker image for test environment. - And now you're ready to run the tests. Running
docker-compose run --rm wpbrowserdoes just that. You can rerun the tests by simply repeating step 3.
HTTP Error 500 🚧
If you get HTTP 500 error upon activation or accessing the endpoint and have CMD/Terminal access with Composer installed.
- Try deleting the
vendordirectoryrm -rf vendorand regenerating the autoloading filescomposer dumpautoload -oin thewp-graphql-woocommercedirectory in your WordPress installation'spluginsdirectory. - (Alternative) You can also try delete and cloning the repository again. The latest release should have fixed the issue.
Support this extension
WPGraphQL 👉 OpenCollective
GraphQL-PHP 👉 OpenCollective

