Skip to content

Commit

Permalink
- Replacing MenuItemConnectionResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonbahl committed Mar 22, 2019
1 parent ba760aa commit de3dd63
Show file tree
Hide file tree
Showing 26 changed files with 1,403 additions and 354 deletions.
18 changes: 9 additions & 9 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
10 changes: 8 additions & 2 deletions src/Connection/MenuItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace WPGraphQL\Connection;

use WPGraphQL\Data\MenuItemConnectionResolver;
use WPGraphQL\Data\Connection\MenuItemConnectionResolver;
use WPGraphQL\Data\DataSource;

/**
* Class MenuItems
Expand Down Expand Up @@ -66,8 +67,13 @@ public static function get_connection_config( $args = [] ) {
'description' => __( 'The menu location for the menu being queried', 'wp-graphql' ),
],
],
'resolveNode' => function( $id, $args, $context, $info ) {
return DataSource::resolve_menu_item( $id, $context );
},
'resolve' => function ( $source, $args, $context, $info ) {
return MenuItemConnectionResolver::resolve( $source, $args, $context, $info );
$resolver = new MenuItemConnectionResolver( $source, $args, $context, $info );
$connection = $resolver->get_connection();
return $connection;
},
], $args );
}
Expand Down
11 changes: 9 additions & 2 deletions src/Connection/Menus.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace WPGraphQL\Connection;

use WPGraphQL\Data\MenuConnectionResolver;
use WPGraphQL\Data\Connection\MenuConnectionResolver;
use WPGraphQL\Data\DataSource;

/**
* Class Menus
Expand Down Expand Up @@ -52,8 +53,14 @@ public static function register_connections() {
},
],
],
'resolveNode' => function ( $id, $args, $context, $info ) {
return DataSource::resolve_term_object( $id, $context );
},
'resolve' => function ( $source, $args, $context, $info ) {
return MenuConnectionResolver::resolve( $source, $args, $context, $info );
$resolver = new MenuConnectionResolver( $source, $args, $context, $info, 'nav_menu' );
$connection = $resolver->get_connection();

return $connection;
},
] );
}
Expand Down
3 changes: 3 additions & 0 deletions src/Connection/TermObjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public static function get_connection_config( $tax_object, $args = [] ) {
},
],
],
'resolveNode' => function( $id, $args, $context, $info ) {
return DataSource::resolve_term_object( $id, $context );
},
'resolve' => function ( $root, $args, $context, $info ) use ( $tax_object ) {
return DataSource::resolve_term_objects_connection( $root, $args, $context, $info, $tax_object->name );
}
Expand Down

0 comments on commit de3dd63

Please sign in to comment.