Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into features/wp-grap…
Browse files Browse the repository at this point in the history
…hql#156-optionsQueries
  • Loading branch information
hughdevore committed Oct 18, 2017
2 parents 849b995 + 5f949f2 commit 67b02ea
Show file tree
Hide file tree
Showing 154 changed files with 6,516 additions and 2,092 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}
],
"require": {
"webonyx/graphql-php": "^0.9.14",
"webonyx/graphql-php": "^0.11.2",
"ivome/graphql-relay-php": "^0.3.1"
},
"require-dev": {
Expand Down
23 changes: 12 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions src/Data/ConnectionResolver.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace WPGraphQL\Data;

use GraphQL\Error\UserError;
use GraphQL\Type\Definition\ResolveInfo;
use GraphQLRelay\Connection\ArrayConnection;
use WPGraphQL\AppContext;
Expand Down Expand Up @@ -143,7 +144,7 @@ public static function get_amount_requested( array $args ) {
* work properly
*/
if ( ! empty( $args['first'] ) && ! empty( $args['last'] ) ) {
throw new \Exception( esc_html__( 'first and last cannot be used together. For forward pagination, use first & after. For backward pagination, use last & before.', 'wp-graphql' ) );
throw new UserError( esc_html__( 'first and last cannot be used together. For forward pagination, use first & after. For backward pagination, use last & before.', 'wp-graphql' ) );
}

/**
Expand All @@ -152,7 +153,7 @@ public static function get_amount_requested( array $args ) {
*/
if ( ! empty( $args['first'] ) && is_int( $args['first'] ) ) {
if ( 0 > $args['first'] ) {
throw new \Exception( esc_html__( 'first must be a positive integer.', 'wp-graphql' ) );
throw new UserError( esc_html__( 'first must be a positive integer.', 'wp-graphql' ) );
} else {
$amount_requested = $args['first'];
}
Expand All @@ -164,7 +165,7 @@ public static function get_amount_requested( array $args ) {
*/
if ( ! empty( $args['last'] ) && is_int( $args['last'] ) ) {
if ( 0 > $args['last'] ) {
throw new \Exception( esc_html__( 'last must be a positive integer.', 'wp-graphql' ) );
throw new UserError( esc_html__( 'last must be a positive integer.', 'wp-graphql' ) );
} else {
$amount_requested = $args['last'];
}
Expand Down
25 changes: 13 additions & 12 deletions src/Data/DataSource.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace WPGraphQL\Data;

use GraphQL\Error\UserError;
use GraphQL\Type\Definition\ResolveInfo;
use GraphQLRelay\Relay;

Expand Down Expand Up @@ -62,7 +63,7 @@ public static function resolve_comment( $id ) {

$comment = \WP_Comment::get_instance( $id );
if ( empty( $comment ) ) {
throw new \Exception( sprintf( __( 'No comment was found with ID %s', 'wp-graphql' ), absint( $id ) ) );
throw new UserError( sprintf( __( 'No comment was found with ID %d', 'wp-graphql' ), absint( $id ) ) );
}

return $comment;
Expand Down Expand Up @@ -130,7 +131,7 @@ public static function resolve_plugin( $name ) {
if ( ! empty( $plugin ) ) {
return $plugin;
} else {
throw new \Exception( sprintf( __( 'No plugin was found with the name %s', 'wp-graphql' ), $name ) );
throw new UserError( sprintf( __( 'No plugin was found with the name %s', 'wp-graphql' ), $name ) );
}
}

Expand Down Expand Up @@ -165,7 +166,7 @@ public static function resolve_post_object( $id, $post_type ) {

$post_object = \WP_Post::get_instance( $id );
if ( empty( $post_object ) ) {
throw new \Exception( sprintf( __( 'No %1$s was found with the ID: %2$s', 'wp-graphql' ), $id, $post_type ) );
throw new UserError( sprintf( __( 'No %1$s was found with the ID: %2$s', 'wp-graphql' ), $id, $post_type ) );
}

/**
Expand Down Expand Up @@ -224,7 +225,7 @@ public static function resolve_post_type( $post_type ) {
if ( in_array( $post_type, $allowed_post_types, true ) ) {
return get_post_type_object( $post_type );
} else {
throw new \Exception( sprintf( __( 'No post_type was found with the name %s', 'wp-graphql' ), $post_type ) );
throw new UserError( sprintf( __( 'No post_type was found with the name %s', 'wp-graphql' ), $post_type ) );
}

}
Expand Down Expand Up @@ -280,7 +281,7 @@ public static function resolve_taxonomy( $taxonomy ) {
if ( in_array( $taxonomy, $allowed_taxonomies, true ) ) {
return get_taxonomy( $taxonomy );
} else {
throw new \Exception( sprintf( __( 'No taxonomy was found with the name %s', 'wp-graphql' ), $taxonomy ) );
throw new UserError( sprintf( __( 'No taxonomy was found with the name %s', 'wp-graphql' ), $taxonomy ) );
}

}
Expand All @@ -300,7 +301,7 @@ public static function resolve_term_object( $id, $taxonomy ) {

$term_object = \WP_Term::get_instance( $id, $taxonomy );
if ( empty( $term_object ) ) {
throw new \Exception( sprintf( __( 'No %1$s was found with the ID: %2$s', 'wp-graphql' ), $taxonomy, $id ) );
throw new UserError( sprintf( __( 'No %1$s was found with the ID: %2$s', 'wp-graphql' ), $taxonomy, $id ) );
}

return $term_object;
Expand Down Expand Up @@ -341,7 +342,7 @@ public static function resolve_theme( $stylesheet ) {
if ( $theme->exists() ) {
return $theme;
} else {
throw new \Exception( sprintf( __( 'No theme was found with the stylesheet: %s', 'wp-graphql' ), $stylesheet ) );
throw new UserError( sprintf( __( 'No theme was found with the stylesheet: %s', 'wp-graphql' ), $stylesheet ) );
}
}

Expand Down Expand Up @@ -374,7 +375,7 @@ public static function resolve_themes_connection( $source, array $args, $context
public static function resolve_user( $id ) {
$user = new \WP_User( $id );
if ( ! $user->exists() ) {
throw new \Exception( sprintf( __( 'No user was found with ID %s', 'wp-graphql' ), $id ) );
throw new UserError( sprintf( __( 'No user was found with ID %s', 'wp-graphql' ), $id ) );
}

return $user;
Expand Down Expand Up @@ -491,7 +492,7 @@ public static function get_node_definition() {
function( $global_id ) {

if ( empty( $global_id ) ) {
throw new \Exception( __( 'An ID needs to be provided to resolve a node.', 'wp-graphql' ) );
throw new UserError( __( 'An ID needs to be provided to resolve a node.', 'wp-graphql' ) );
}

/**
Expand Down Expand Up @@ -563,7 +564,7 @@ function( $global_id ) {
* @since 0.0.6
*/
if ( null === $node ) {
throw new \Exception( sprintf( __( 'No node could be found with global ID: %s', 'wp-graphql' ), $global_id ) );
throw new UserError( sprintf( __( 'No node could be found with global ID: %s', 'wp-graphql' ), $global_id ) );
}

/**
Expand All @@ -574,7 +575,7 @@ function( $global_id ) {
return $node;

} else {
throw new \Exception( sprintf( __( 'The global ID isn\'t recognized ID: %s', 'wp-graphql' ), $global_id ) );
throw new UserError( sprintf( __( 'The global ID isn\'t recognized ID: %s', 'wp-graphql' ), $global_id ) );
}
},

Expand Down Expand Up @@ -632,7 +633,7 @@ function( $node ) {
* @since 0.0.6
*/
if ( null === $type ) {
throw new \Exception( __( 'No type was found matching the node', 'wp-graphql' ) );
throw new UserError( __( 'No type was found matching the node', 'wp-graphql' ) );
}

/**
Expand Down
18 changes: 5 additions & 13 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace WPGraphQL;

use GraphQL\Error\FormattedError;
use GraphQL\Error\UserError;

/**
* Class Router
Expand Down Expand Up @@ -306,8 +307,7 @@ public static function process_http_request() {
/**
* If the variables are already formatted as an array use them.
*
* Ex:
*
* Example:
* ?query=query getPosts($first:Int){posts(first:$first){edges{node{id}}}}&variables[first]=1
*/
if ( is_array( $data['variables'] ) ) {
Expand All @@ -334,7 +334,7 @@ public static function process_http_request() {
}

if ( ! isset( $_SERVER['CONTENT_TYPE'] ) || false === strpos( $_SERVER['CONTENT_TYPE'], 'application/json' ) ) {
$response['errors'] = __( 'WPGraphQL requires POST requests', 'wp-graphql' );
$response['errors'] = __( 'The Content-Type for the request must be set to "application/json"', 'wp-graphql' );
}

/**
Expand All @@ -349,7 +349,7 @@ public static function process_http_request() {
* If the $data is empty, catch an error.
*/
if ( empty( $data ) || ( empty( $data['query'] ) ) ) {
throw new \Exception( __( 'GraphQL Queries must be a POST Request with a valid query', 'wp-graphql' ), 10 );
throw new UserError( __( 'GraphQL requests must be a POST or GET Request with a valid query', 'wp-graphql' ), 10 );
}

/**
Expand Down Expand Up @@ -401,15 +401,7 @@ public static function process_http_request() {
* @since 0.0.4
*/
self::$http_status_code = 500;
if ( defined( 'GRAPHQL_DEBUG' ) && true === GRAPHQL_DEBUG ) {
$response['extensions']['exception'] = FormattedError::createFromException( $error );
} else {
if ( 10 === $error->getCode() ) {
$response['errors'] = [ FormattedError::create( $error->getMessage() ) ];
} else {
$response['errors'] = [ FormattedError::create( 'Unexpected error' ) ];
}
}
$response['errors'] = [ FormattedError::createFromException( $error ) ];
} // End try().

/**
Expand Down
54 changes: 18 additions & 36 deletions src/Type/Comment/Connection/CommentConnectionArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,10 @@ private static function fields() {
'type' => new WPEnumType([
'name' => 'commentsOrder',
'values' => [
[
'name' => 'ASC',
'ASC' => [
'value' => 'ASC',
],
[
'name' => 'DESC',
'DESC' => [
'value' => 'DESC',
],
],
Expand Down Expand Up @@ -210,68 +208,52 @@ private static function comments_orderby_enum() {
self::$comments_orderby_enum = new WPEnumType([
'name' => 'commentsOrderby',
'values' => [
[
'name' => 'COMMENT_AGENT',
'COMMENT_AGENT' => [
'value' => 'comment_agent',
],
[
'name' => 'COMMENT_APPROVED',
'COMMENT_APPROVED' => [
'value' => 'comment_approved',
],
[
'name' => 'COMMENT_AUTHOR',
'COMMENT_AUTHOR' => [
'value' => 'comment_author',
],
[
'name' => 'COMMENT_AUTHOR_EMAIL',
'COMMENT_AUTHOR_EMAIL' => [
'value' => 'comment_author_email',
],
[
'name' => 'COMMENT_AUTHOR_IP',
'COMMENT_AUTHOR_IP' => [
'value' => 'comment_author_IP',
],
[
'name' => 'COMMENT_AUTHOR_URL',
'COMMENT_AUTHOR_URL' => [
'value' => 'comment_author_url',
],
[
'name' => 'COMMENT_CONTENT',
'COMMENT_CONTENT' => [
'value' => 'comment_content',
],
[
'name' => 'COMMENT_DATE',
'COMMENT_DATE' => [
'value' => 'comment_date',
],
[
'name' => 'COMMENT_DATE_GMT',
'COMMENT_DATE_GMT' => [
'value' => 'comment_date_gmt',
],
[
'name' => 'COMMENT_ID',
'COMMENT_ID' => [
'value' => 'comment_ID',
],
[
'name' => 'COMMENT_KARMA',
'COMMENT_KARMA' => [
'value' => 'comment_karma',
],
[
'name' => 'COMMENT_PARENT',
'COMMENT_PARENT' => [
'value' => 'comment_parent',
],
[
'name' => 'COMMENT_POST_ID',
'COMMENT_POST_ID' => [
'value' => 'comment_post_ID',
],
[
'name' => 'COMMENT_TYPE',
'COMMENT_TYPE' => [
'value' => 'comment_type',
],
[
'name' => 'USER_ID',
'USER_ID' => [
'value' => 'user_id',
],
[
'name' => 'COMMENT_IN',
'COMMENT_IN' => [
'value' => 'comment__in',
],
],
Expand Down
3 changes: 2 additions & 1 deletion src/Type/Comment/Connection/CommentConnectionResolver.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace WPGraphQL\Type\Comment\Connection;

use GraphQL\Error\UserError;
use GraphQL\Type\Definition\ResolveInfo;
use GraphQLRelay\Connection\ArrayConnection;
use WPGraphQL\AppContext;
Expand Down Expand Up @@ -85,7 +86,7 @@ public static function get_query_args( $source, array $args, AppContext $context
* Throw an exception if the query is attempted to be queried by
*/
if ( 'comment__in' === $query_args['orderby'] && empty( $query_args['comment__in'] ) ) {
throw new \Exception( __( 'In order to sort by comment__in, an array of IDs must be passed as the commentIn argument', 'wp-graphql' ) );
throw new UserError( __( 'In order to sort by comment__in, an array of IDs must be passed as the commentIn argument', 'wp-graphql' ) );
}

/**
Expand Down
Loading

0 comments on commit 67b02ea

Please sign in to comment.