Created
July 29, 2021 15:18
-
-
Save jasonbahl/b729874ffff9e9f7f933136ffa403246 to your computer and use it in GitHub Desktop.
Allow WPGraphQL for WooCommerce resolveNode callbacks to work with WPGraphQL v1.15+
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_filter( 'graphql_pre_resolve_field', function( $nil, $source, $args, \WPGraphQL\AppContext $context, \GraphQL\Type\Definition\ResolveInfo $info, $type_name, $field_key, $field, $field_resolver ) { | |
| if ( 'RootQueryToShippingMethodConnection' === $type_name ) { | |
| if ( 'nodes' === $field_key ) { | |
| if ( ! empty( $source['nodes'] ) && is_array( $source['nodes'] ) ) { | |
| $nodes = []; | |
| foreach ( $source['nodes'] as $node ) { | |
| $nodes[] = \WPGraphQL\WooCommerce\Data\Factory\Factory::resolve_shipping_method( $node ); | |
| } | |
| } | |
| if ( ! empty( $nodes ) ) { | |
| return $nodes; | |
| } | |
| } | |
| if ( 'node' === $field_key && ! empty( $source['node'] ) ) { | |
| return \WPGraphQL\WooCommerce\Data\Factory\Factory::resolve_shipping_method_connection( $source['node'], $args, $context, $info ); | |
| } | |
| } | |
| if ( 'OrderToLineItemConnection' === $type_name ) { | |
| if ( 'nodes' === $field_key ) { | |
| if ( ! empty( $source['nodes'] ) && is_array( $source['nodes'] ) ) { | |
| $nodes = []; | |
| foreach ( $source['nodes'] as $node ) { | |
| $nodes[] = \WPGraphQL\WooCommerce\Data\Factory\Factory::resolve_order_item( $node ); | |
| } | |
| } | |
| if ( ! empty( $nodes ) ) { | |
| return $nodes; | |
| } | |
| } | |
| if ( 'node' === $field_key && ! empty( $source['node'] ) ) { | |
| return \WPGraphQL\WooCommerce\Data\Factory\Factory::resolve_order_item_connection( $source['node'], $args, $context, $info ); | |
| } | |
| } | |
| return $nil; | |
| }, 10, 9 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment