Skip to content

Node IDs not being tracked by the Query Analyzer when using DataLoader's load_many() method #3113

@jasonbahl

Description

@jasonbahl

Description

When using the $context->get_loader( $loaderName )->load_many() method to resolve a field, the nodes are loaded as expected, but the Node IDs are not being tracked properly in the QueryAnalyzer.

Steps to reproduce

  1. Add the following code (adjusting as necessary to reflect your dataset)
add_action( 'graphql_register_types', function() { 
  register_graphql_field( 'RootQuery', 'testLoadmany', [
    'type' => [ 'list_of' => 'Post' ],
    'resolve' => function( $source, $args, $context, $info ) {
      $post_ids = [ 2641, 2644 ];
      return $context->get_loader( 'post' )->load_many( $post_ids );
    }
  ] );
} );
  1. With WPGraphQL Debug mode enabled, execute the following query:
query TestLoadMany {
  testLoadmany {
    id
    title
  }
}
  1. Examine the extensions.queryAnalyzer.keys output in the response

Expectation

The Node IDs for the resovled posts should be included in the extensions.queryAnalyzer.keys

Actual

The node IDs are NOT included 🥲

CleanShot 2024-04-30 at 21 37 59@2x

Additional context

The nodes are tracked properly when querying for a single Node:

CleanShot 2024-04-30 at 21 42 32@2x

The nodes are tracked properly when querying for a connection of nodes:

CleanShot 2024-04-30 at 21 43 23@2x

WPGraphQL Version

1.24.0

WordPress Version

6.5.2

PHP Version

8.2

Additional environment details

No response

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have disabled ALL plugins except for WPGraphQL.

  • Yes
  • My issue is with compatibility with a specific WordPress plugin, and I have listed all my installed plugins (and version info) above.

Metadata

Metadata

Assignees

Labels

type: bugIssue that causes incorrect or unexpected behavior

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions