Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
355 changes: 190 additions & 165 deletions access-functions.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bin/_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fi

DB_HOST=${DB_HOST-localhost}
DB_PASS=${DB_PASSWORD-""}
WP_VERSION=${WP_VERSION-5}
WP_VERSION=${WP_VERSION-6}
PROJECT_ROOT_DIR=$(pwd)
WP_CORE_DIR=${WP_CORE_DIR:-local/public}
PLUGINS_DIR=${PLUGINS_DIR:-"$WP_CORE_DIR/wp-content/plugins"}
Expand Down
9 changes: 5 additions & 4 deletions bin/_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ install_wordpress() {
# Install Wordpress + integrated plugins for testing/development.
composer install
composer require --dev -W \
composer/installers:~1.0 \
composer/installers \
johnpbloch/wordpress:~${WP_VERSION} \
wp-graphql/wp-graphql-jwt-authentication \
wpackagist-plugin/woocommerce \
Expand Down Expand Up @@ -52,13 +52,14 @@ remove_wordpress() {
install_local_test_library() {
# Install testing library dependencies.
composer install
composer require --dev \
composer require --dev --with-all-dependencies \
lucatume/wp-browser \
codeception/module-asserts:^1.0 \
codeception/module-rest:^1.0 \
codeception/module-rest:^2.0 \
codeception/util-universalframework:^1.0 \
wp-graphql/wp-graphql-testcase \
wp-graphql/wp-graphql-testcase:^2.3 \
stripe/stripe-php

}

remove_local_test_library() {
Expand Down
16 changes: 2 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,10 @@
"process-timeout": 0,
"sort-packages": true,
"allow-plugins": {
"composer/installers": true,
"johnpbloch/wordpress-core-installer": true
"johnpbloch/wordpress-core-installer": true,
"composer/installers": true
}
},
"autoload": {
"files": [
"includes/connection/wc-cpt-connection-args.php",
"includes/functions.php"
],
"psr-4": {
"WPGraphQL\\WooCommerce\\": "includes/"
},
"classmap": [
"includes/"
]
},
"autoload-dev": {
"files": [
"tests/_data/config.php"
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

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

4 changes: 2 additions & 2 deletions includes/class-acf-schema-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class ACF_Schema_Filters {
*/
public static function add_filters() {
// Registers WooCommerce CPTs && taxonomies.
add_filter( 'graphql_acf_get_root_id', array( __CLASS__, 'resolve_crud_root_id' ), 10, 2 );
add_filter( 'graphql_acf_post_object_source', array( __CLASS__, 'resolve_post_object_source' ), 10, 2 );
add_filter( 'graphql_acf_get_root_id', [ __CLASS__, 'resolve_crud_root_id' ], 10, 2 );
add_filter( 'graphql_acf_post_object_source', [ __CLASS__, 'resolve_post_object_source' ], 10, 2 );
}

/**
Expand Down
44 changes: 22 additions & 22 deletions includes/class-core-schema-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,96 +22,96 @@ class Core_Schema_Filters {
*/
public static function add_filters() {
// Registers WooCommerce CPTs.
add_filter( 'register_post_type_args', array( __CLASS__, 'register_post_types' ), 10, 2 );
add_filter( 'graphql_post_entities_allowed_post_types', array( __CLASS__, 'skip_type_registry' ), 10 );
add_filter( 'register_post_type_args', [ __CLASS__, 'register_post_types' ], 10, 2 );
add_filter( 'graphql_post_entities_allowed_post_types', [ __CLASS__, 'skip_type_registry' ], 10 );

// Registers WooCommerce taxonomies.
add_filter( 'register_taxonomy_args', array( __CLASS__, 'register_taxonomy_args' ), 10, 2 );
add_filter( 'register_taxonomy_args', [ __CLASS__, 'register_taxonomy_args' ], 10, 2 );

// Add data-loaders to AppContext.
add_filter( 'graphql_data_loaders', array( __CLASS__, 'graphql_data_loaders' ), 10, 2 );
add_filter( 'graphql_data_loaders', [ __CLASS__, 'graphql_data_loaders' ], 10, 2 );

// Add node resolvers.
add_filter(
'graphql_resolve_node',
array( '\WPGraphQL\WooCommerce\Data\Factory', 'resolve_node' ),
[ '\WPGraphQL\WooCommerce\Data\Factory', 'resolve_node' ],
10,
4
);
add_filter(
'graphql_resolve_node_type',
array( '\WPGraphQL\WooCommerce\Data\Factory', 'resolve_node_type' ),
[ '\WPGraphQL\WooCommerce\Data\Factory', 'resolve_node_type' ],
10,
2
);

// Filter Unions.
add_filter(
'graphql_wp_union_type_config',
array( __CLASS__, 'inject_union_types' ),
[ __CLASS__, 'inject_union_types' ],
10,
2
);

add_filter(
'graphql_union_resolve_type',
array( __CLASS__, 'inject_type_resolver' ),
[ __CLASS__, 'inject_type_resolver' ],
10,
3
);

add_filter(
'graphql_interface_resolve_type',
array( __CLASS__, 'inject_type_resolver' ),
[ __CLASS__, 'inject_type_resolver' ],
10,
3
);

add_filter(
'graphql_dataloader_pre_get_model',
array( '\WPGraphQL\WooCommerce\Data\Loader\WC_CPT_Loader', 'inject_post_loader_models' ),
[ '\WPGraphQL\WooCommerce\Data\Loader\WC_CPT_Loader', 'inject_post_loader_models' ],
10,
3
);

add_filter(
'graphql_dataloader_get_model',
array( '\WPGraphQL\WooCommerce\Data\Loader\WC_Customer_Loader', 'inject_user_loader_models' ),
[ '\WPGraphQL\WooCommerce\Data\Loader\WC_Customer_Loader', 'inject_user_loader_models' ],
10,
3
);

add_filter(
'graphql_post_object_connection_query_args',
array( '\WPGraphQL\WooCommerce\Connection\Orders', 'post_object_connection_query_args' ),
[ '\WPGraphQL\WooCommerce\Connection\Orders', 'post_object_connection_query_args' ],
10,
5
);

add_filter(
'graphql_map_input_fields_to_wp_query',
array( '\WPGraphQL\WooCommerce\Connection\Coupons', 'map_input_fields_to_wp_query' ),
[ '\WPGraphQL\WooCommerce\Connection\Coupons', 'map_input_fields_to_wp_query' ],
10,
7
);

add_filter(
'graphql_map_input_fields_to_wp_query',
array( '\WPGraphQL\WooCommerce\Connection\Products', 'map_input_fields_to_wp_query' ),
[ '\WPGraphQL\WooCommerce\Connection\Products', 'map_input_fields_to_wp_query' ],
10,
7
);

add_filter(
'graphql_map_input_fields_to_wp_query',
array( '\WPGraphQL\WooCommerce\Connection\Orders', 'map_input_fields_to_wp_query' ),
[ '\WPGraphQL\WooCommerce\Connection\Orders', 'map_input_fields_to_wp_query' ],
10,
7
);

add_filter(
'graphql_map_input_fields_to_wp_user_query',
array( '\WPGraphQL\WooCommerce\Connection\Customers', 'map_input_fields_to_wp_query' ),
[ '\WPGraphQL\WooCommerce\Connection\Customers', 'map_input_fields_to_wp_query' ],
10,
6
);
Expand Down Expand Up @@ -173,10 +173,10 @@ public static function skip_type_registry( $post_types ) {
return array_diff(
$post_types,
get_post_types(
array(
[
'show_in_graphql' => true,
'skip_graphql_type_registry' => true,
)
]
)
);
}
Expand Down Expand Up @@ -221,7 +221,7 @@ public static function register_taxonomy_args( $args, $taxonomy ) {
}

// Filter product attributes taxonomies.
$attributes = \WP_GraphQL_WooCommerce::get_product_attribute_taxonomies();
$attributes = WP_GraphQL_WooCommerce::get_product_attribute_taxonomies();
if ( in_array( $taxonomy, $attributes, true ) ) {
$singular_name = graphql_format_field_name( $taxonomy );
$args['show_in_graphql'] = true;
Expand Down Expand Up @@ -280,17 +280,17 @@ function( $type ) {
return 'Product' !== $type;
}
),
array_values( \WP_GraphQL_WooCommerce::get_enabled_product_types() )
array_values( WP_GraphQL_WooCommerce::get_enabled_product_types() )
);
$refresh_callback = true;
}

// Update 'types' callback.
if ( $refresh_callback ) {
$config['types'] = function () use ( $config, $wp_union ) {
$prepared_types = array();
$prepared_types = [];
if ( ! empty( $config['typeNames'] ) && is_array( $config['typeNames'] ) ) {
$prepared_types = array();
$prepared_types = [];
foreach ( $config['typeNames'] as $type_name ) {
$prepared_types[] = $wp_union->type_registry->get_type( $type_name );
}
Expand Down
36 changes: 18 additions & 18 deletions includes/class-jwt-auth-schema-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class JWT_Auth_Schema_Filters {
public static function add_filters() {
// Confirm WPGraphQL JWT Authentication is installed.
if ( \class_exists( '\WPGraphQL\JWT_Authentication\Auth' ) ) {
add_filter( 'graphql_jwt_user_types', array( __CLASS__, 'add_customer_to_jwt_user_types' ), 10 );
add_filter( 'graphql_registerCustomerPayload_fields', array( __CLASS__, 'add_jwt_output_fields' ), 10, 3 );
add_filter( 'graphql_updateCustomerPayload_fields', array( __CLASS__, 'add_jwt_output_fields' ), 10, 3 );
add_action( 'graphql_register_types', array( __CLASS__, 'add_customer_to_login_payload' ), 10 );
add_filter( 'graphql_jwt_user_types', [ __CLASS__, 'add_customer_to_jwt_user_types' ], 10 );
add_filter( 'graphql_registerCustomerPayload_fields', [ __CLASS__, 'add_jwt_output_fields' ], 10, 3 );
add_filter( 'graphql_updateCustomerPayload_fields', [ __CLASS__, 'add_jwt_output_fields' ], 10, 3 );
add_action( 'graphql_register_types', [ __CLASS__, 'add_customer_to_login_payload' ], 10 );
}
}

Expand All @@ -51,12 +51,12 @@ public static function add_customer_to_jwt_user_types( array $types ) {
public static function add_jwt_output_fields( $fields, $object, $type_registry ): array {
$fields = array_merge(
$fields,
array(
'authToken' => array(
[
'authToken' => [
'type' => $type_registry->get_type( 'String' ),
'description' => __( 'JWT Token that can be used in future requests for Authentication', 'wp-graphql-woocommerce' ),
'resolve' => function( $payload ) {
$user = get_user_by( 'ID', $payload['id'] );
$user = get_user_by( 'ID', $payload['id'] );
$token = \WPGraphQL\JWT_Authentication\Auth::get_token( $user );

if ( is_wp_error( $token ) ) {
Expand All @@ -65,12 +65,12 @@ public static function add_jwt_output_fields( $fields, $object, $type_registry )

return $token;
},
),
'refreshToken' => array(
],
'refreshToken' => [
'type' => $type_registry->get_type( 'String' ),
'description' => __( 'A JWT token that can be used in future requests to get a refreshed jwtAuthToken. If the refresh token used in a request is revoked or otherwise invalid, a valid Auth token will NOT be issued in the response headers.', 'wp-graphql-woocommerce' ),
'resolve' => function( $payload ) {
$user = get_user_by( 'ID', $payload['id'] );
$user = get_user_by( 'ID', $payload['id'] );
$refresh_token = \WPGraphQL\JWT_Authentication\Auth::get_refresh_token( $user );

if ( is_wp_error( $refresh_token ) ) {
Expand All @@ -79,8 +79,8 @@ public static function add_jwt_output_fields( $fields, $object, $type_registry )

return $refresh_token;
},
),
)
],
]
);

return $fields;
Expand All @@ -92,23 +92,23 @@ public static function add_jwt_output_fields( $fields, $object, $type_registry )
public static function add_customer_to_login_payload() {
register_graphql_fields(
'LoginPayload',
array(
'customer' => array(
[
'customer' => [
'type' => 'Customer',
'description' => __( 'Customer object of authenticated user.', 'wp-graphql-woocommerce' ),
'resolve' => function( $payload ) {
$id = $payload['id'];
return new Customer( $id );
},
),
'sessionToken' => array(
],
'sessionToken' => [
'type' => 'String',
'description' => __( 'A JWT token that can be used in future requests to for WooCommerce session identification', 'wp-graphql-woocommerce' ),
'resolve' => function( $payload ) {
return apply_filters( 'graphql_customer_session_token', \WC()->session->build_token() );
},
),
)
],
]
);
}
}
Loading