Skip to content

Commit

Permalink
🔀 Merge branch 'develop' into release/v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonbahl committed Apr 6, 2019
2 parents 2f91581 + 8aaaa3a commit 86a7d9f
Show file tree
Hide file tree
Showing 130 changed files with 8,789 additions and 3,871 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
.idea
.vscode
!vendor/
Expand Down
46 changes: 38 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ sudo: required
services:
- docker

language: php

notifications:
email:
on_success: never
Expand All @@ -16,26 +18,54 @@ branches:
cache:
apt: true


# Set the global environment variables
env:
matrix:
# These apply to the latest WP version that is available as a Docker image: https://hub.docker.com/_/wordpress/
- WP_VERSION=5.0.2 PHP_VERSION=5.6
- WP_VERSION=5.0.3 PHP_VERSION=7.1
- WP_VERSION=5.0.3 PHP_VERSION=7.2
- WP_VERSION=5.0.3 PHP_VERSION=7.3 COVERAGE=true LINT_SCHEMA=true
- WP_VERSION=5.1.1 PHP_VERSION=7.1
- WP_VERSION=5.1.1 PHP_VERSION=7.2
- WP_VERSION=5.1.1 PHP_VERSION=7.3 COVERAGE=true LINT_SCHEMA=true
- PHPCS=true

matrix:
allow_failures:
- env: PHPCS=true

before_install:
- sudo rm /usr/local/bin/docker-compose
- curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin
- sudo rm /usr/local/bin/docker-compose
- curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin
- |
# Remove Xdebug for a huge performance increase:
if [ -f ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini ]; then
phpenv config-rm xdebug.ini
else
echo "xdebug.ini does not exist"
fi
before_script:
# Install PHP CodeSniffer and WPCS.
- |
if [[ "$PHPCS" == "true" ]]; then
composer require dealerdirect/phpcodesniffer-composer-installer
composer require squizlabs/php_codesniffer
composer require phpcompatibility/phpcompatibility-wp
composer require wp-coding-standards/wpcs
composer install
phpenv rehash
./vendor/bin/phpcs --config-set installed_paths '../../wimg/php-compatibility/,../../wp-coding-standards/wpcs/'
./vendor/bin/phpcs --config-set default_standard WordPress
fi
script:
- ./run-docker-tests.sh 'wpunit'
- ./run-docker-tests.sh 'functional'
- ./run-docker-tests.sh 'acceptance'
- if [[ "$PHPCS" == "true" ]]; then ./vendor/bin/phpcs; fi

after_success:
# Upload coverage to codecov
Expand Down
7 changes: 2 additions & 5 deletions Dockerfile.test-base
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# Updating Software used in this Dockerfile:
# PHP Composer: https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md
# XDebug: https://pecl.php.net/package/xdebug

# Using the 'DESIRED_' prefix to avoid confusion with environment variables of the same name.
ARG DESIRED_WP_VERSION
Expand All @@ -21,11 +22,7 @@ RUN echo 'date.timezone = "UTC"' > /usr/local/etc/php/conf.d/timezone.ini \
&& apt-get install --no-install-recommends -y mysql-client subversion \
&& rm -rf /var/lib/apt/lists/* \
&& if echo "${PHP_VERSION}" | grep '^7'; then \
if echo "${PHP_VERSION}" | grep '^7.3'; then \
pecl install 'xdebug-2.7.0RC2'; \
else \
pecl install xdebug; \
fi; \
pecl install xdebug; \
docker-php-ext-enable xdebug; \
fi \
&& docker-php-ext-install pdo_mysql \
Expand Down
4 changes: 2 additions & 2 deletions docker/docker-compose.local-app-xdebug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ services:
context: '../'
dockerfile: 'Dockerfile.xdebug'
args:
DESIRED_WP_VERSION: "${WP_VERSION:-5.0.2}"
DESIRED_PHP_VERSION: "${PHP_VERSION:-7.2}"
DESIRED_WP_VERSION: "${WP_VERSION:-5.1.1}"
DESIRED_PHP_VERSION: "${PHP_VERSION:-7.3}"
image: 'wordpress-utc-xdebug-cache'
environment:
# XDebug remote debugging: https://xdebug.org/docs/remote
Expand Down
4 changes: 2 additions & 2 deletions docker/docker-compose.local-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.4"

services:
wpgraphql.test:
image: "wordpress:${WP_VERSION:-5.0.2}-php${PHP_VERSION:-7.2}-apache"
image: "wordpress:${WP_VERSION:-5.1.1}-php${PHP_VERSION:-7.3}-apache"
ports:
- '8000:80'
environment:
Expand All @@ -19,7 +19,7 @@ services:
- './uploads.txt:/usr/local/etc/php/conf.d/uploads.ini:ro'

mysql_test:
image: 'mariadb:10.2.22-bionic'
image: 'mariadb:10.2.23-bionic'
environment:
MYSQL_DATABASE: 'wpgraphql_test'
MYSQL_ROOT_PASSWORD: 'testing'
10 changes: 5 additions & 5 deletions docker/docker-compose.tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ services:
context: '../'
dockerfile: 'Dockerfile.test-base'
args:
DESIRED_WP_VERSION: "${WP_VERSION:-5.0.2}"
DESIRED_PHP_VERSION: "${PHP_VERSION:-7.2}"
DESIRED_WP_VERSION: "${WP_VERSION:-5.1.1}"
DESIRED_PHP_VERSION: "${PHP_VERSION:-7.3}"
image: 'wordpress-wp-graphql-test-base'
container_name: 'wpgraphql-tester'
environment:
Expand All @@ -28,8 +28,8 @@ services:
context: '../'
dockerfile: 'Dockerfile.test-base'
args:
DESIRED_WP_VERSION: "${WP_VERSION:-5.0.2}"
DESIRED_PHP_VERSION: "${PHP_VERSION:-7.2}"
DESIRED_WP_VERSION: "${WP_VERSION:-5.1.1}"
DESIRED_PHP_VERSION: "${PHP_VERSION:-7.3}"
image: 'wordpress-wp-graphql-test-base'
environment:
WORDPRESS_DB_HOST: 'mysql_test'
Expand All @@ -43,7 +43,7 @@ services:
entrypoint: [ "docker-entrypoint.sut.sh" ]

mysql_test:
image: 'mariadb:10.2.22-bionic'
image: 'mariadb:10.2.23-bionic'
environment:
MYSQL_DATABASE: 'wpgraphql_test'
MYSQL_ROOT_PASSWORD: 'testing'
Expand Down
10 changes: 0 additions & 10 deletions phpcs.ruleset.xml

This file was deleted.

23 changes: 23 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards for Plugins">

<!-- Set a description for this ruleset. -->
<description>A custom set of code standard rules to check for WordPress plugins.</description>

<rule ref="WordPress" />

<!-- What to scan -->
<file>src</file>

<!-- What to exclude -->
<exclude-pattern>*/node_modules/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>

<!-- Remove the class naming error temporarily -->
<rule ref="WordPress.Files.FileName">
<properties>
<property name="strict_class_file_names" value="false"/>
</properties>
</rule>

</ruleset>
93 changes: 92 additions & 1 deletion src/AppContext.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
<?php

namespace WPGraphQL;

use GraphQL\Error\UserError;
use WPGraphQL\Data\Loader\CommentLoader;
use WPGraphQL\Data\Loader\MenuItemLoader;
use WPGraphQL\Data\Loader\PostObjectLoader;
use WPGraphQL\Data\Loader\TermObjectLoader;
use WPGraphQL\Data\Loader\UserLoader;

/**
* Class AppContext
* Creates an object that contains all of the context for the GraphQL query
* This class gets instantiated and populated in the main WPGraphQL class.
*
* The context is passed to each resolver during execution.
*
*
* Resolvers have the ability to read and write to context to pass info to nested resolvers.
*
* @package WPGraphQL
Expand Down Expand Up @@ -40,32 +48,114 @@ class AppContext {

/**
* Stores additional $config properties
*
* @var \mixed $config
* @access public
*/
public $config;

/**
* Passes context about the current connection being resolved
*
* @var mixed| String | null
*/
public $currentConnection = null;

/**
* Passes context about the current connection
*
* @var array
*/
public $connectionArgs = [];

/**
* Stores the loaders for the class
*
* @var array
*/
public $loaders = [];

/**
* @var CommentLoader
*/
public $CommentLoader;

/**
* @var MenuItemLoader
*/
public $MenuItemLoader;

/**
* @var PostObjectLoader
*/
public $PostObjectLoader;

/**
* @var TermObjectLoader
*/
public $TermObjectLoader;

/**
* @var UserLoader
*/
public $UserLoader;

/**
* AppContext constructor.
*/
public function __construct() {

/**
* Create a list of loaders to be available in AppContext
*/
$loaders = [
'comment' => new CommentLoader( $this ),
'menu_item' => new MenuItemLoader( $this ),
'post_object' => new PostObjectLoader( $this ),
'term_object' => new TermObjectLoader( $this ),
'user' => new UserLoader( $this ),
];

/**
* This filters the data loaders, allowing for additional loaders to be
* added to the AppContext or for existing loaders to be replaced if
* needed.
*
* @params array $loaders The loaders accessible in the AppContext
* @params AppContext $this The AppContext
*/
$this->loaders = apply_filters( 'graphql_data_loaders', $loaders, $this );


/**
* This filters the config for the AppContext.
*
* This can be used to store additional context config, which is available to resolvers
* throughout the resolution of a GraphQL request.
*
* @params array $config The config array of the AppContext object
*/
$this->config = apply_filters( 'graphql_app_context_config', $this->config );
}

/**
* Retrieves loader assigned to $key
*
* @param string $key The name of the loader to get
*
* @return mixed
*/
public function getLoader( $key ) {
if ( ! array_key_exists( $key, $this->loaders ) ) {
throw new UserError( sprintf( __( 'No loader assigned to the key %s', 'wp-graphql' ), $key ) );
}

return $this->loaders[ $key ];
}

/**
* Returns the $args for the connection the field is a part of
*
* @return array|mixed
*/
public function getConnectionArgs() {
Expand All @@ -74,6 +164,7 @@ public function getConnectionArgs() {

/**
* Returns the current connection
*
* @return mixed|null|String
*/
public function getCurrentConnection() {
Expand Down
20 changes: 10 additions & 10 deletions src/Connection/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,11 @@ public static function register_connections() {
foreach ( $allowed_post_types as $post_type ) {
$post_type_object = get_post_type_object( $post_type );
if ( post_type_supports( $post_type_object->name, 'comments' ) ) {
register_graphql_connection( [
'fromType' => $post_type_object->graphql_single_name,
'toType' => 'Comment',
'fromFieldName' => 'comments',
'connectionArgs' => self::get_connection_args(),
'resolve' => function ( $root, $args, $context, $info ) {
return DataSource::resolve_comments_connection( $root, $args, $context, $info );
},
] );
register_graphql_connection( self::get_connection_config( [
'fromType' => $post_type_object->graphql_single_name,
'toType' => 'Comment',
'fromFieldName' => 'comments',
] ) );
}
}
}
Expand All @@ -65,6 +61,7 @@ public static function register_connections() {
* with the defaults
*
* @access public
*
* @param array $args
*
* @return array
Expand All @@ -75,6 +72,9 @@ public static function get_connection_config( $args = [] ) {
'toType' => 'Comment',
'fromFieldName' => 'comments',
'connectionArgs' => self::get_connection_args(),
'resolveNode' => function ( $id, $args, $context, $info ) {
return DataSource::resolve_comment( $id, $context );
},
'resolve' => function ( $root, $args, $context, $info ) {
return DataSource::resolve_comments_connection( $root, $args, $context, $info );
},
Expand Down Expand Up @@ -128,7 +128,7 @@ public static function get_connection_args() {
'type' => [
'list_of' => 'ID',
],
'description' => __( 'Array of author IDs to include comments for.', 'wp-graphql' ),
'description' => __( 'Array of IDs or email addresses of users whose unapproved comments will be returned by the query regardless of $status. Default empty', 'wp-graphql' ),
],
'karma' => [
'type' => 'Int',
Expand Down

0 comments on commit 86a7d9f

Please sign in to comment.