Skip to content

Conversation

@theodesp
Copy link
Member

Description

This PR introduces a new query analysis rule, UnfilteredLists, to the wpgraphql-debug-extensions plugin. This rule helps developers identify GraphQL queries that request lists of items without explicitly providing pagination arguments such as first, last, after, before, offset, or limit.

Key enhancements in this rule include:

  • Targeting Connection Fields: The logic has been refined to accurately detect fields that are "connections" in the GraphQL schema
  • Schema vs. Query Argument Check: It compares the pagination capabilities defined in the schema for a given field against the actual arguments provided in the executed query.
  • Clear Debug Output: When an unfiltered list is detected, the debugExtensions output will include a clear message detailing which fields are affected and suggesting the pagination arguments to consider.

Related Issue

#349

Dependant PRs

None

Type of Change

  • ✅ Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactoring (no functional changes)
  • 📄 Example update (no functional changes)
  • 📝 Documentation update
  • 🔍 Performance improvement
  • 🧪 Test update

How Has This Been Tested?

This feature has been tested by executing various GraphQL queries against a local WordPress environment with WPGraphQL and wpgraphql-debug-extensions active, observing the debugExtensions.unfilteredLists output.

Test Cases and Steps:

  1. Ensure the wpgraphql-debug-extensions plugin is active.
  2. Ensure the UnfilteredLists rule is registered. (This is handled in Plugin.php where addAnalyzerItem( new UnfilteredLists() ) should be present).
  3. Open your GraphQL client (e.g., GraphiQL, Postman, Insomnia) and point it to your WPGraphQL endpoint (typically your-site.com/graphql).

Test Queries:

  • Test Case 1: Unfiltered posts connection (Should Trigger Warning)

    • Query:
      query {
        posts {
          nodes {
            id
            title
          }
        }
      }
    • Expected Output in debugExtensions.unfilteredLists:
      "unfilteredLists": {
        "triggered": true,
        "message": "Unfiltered list queries detected for: posts. Consider adding pagination (e.g., first, last, after, before, offset, limit) to these fields for performance.",
        "details": ["posts"],
        "paginationArgsChecked": ["first", "last", "after", "before", "offset", "limit"]
      }
  • Test Case 2: Unfiltered users connection (Should Trigger Warning)

    • Query:
      query {
        users {
          nodes {
            id
            nicename
          }
        }
      }
    • Expected Output in debugExtensions.unfilteredLists:
      "unfilteredLists": {
        "triggered": true,
        "message": "Unfiltered list queries detected for: users. Consider adding pagination (e.g., first, last, after, before, offset, limit) to these fields for performance.",
        "details": ["users"],
        "paginationArgsChecked": ["first", "last", "after", "before", "offset", "limit"]
      }
  • Test Case 3: Paginated posts connection (Should NOT Trigger Warning)

    • Query:
      query {
        posts(first: 5) {
          nodes {
            id
            title
          }
        }
      }
    • Expected Output in debugExtensions.unfilteredLists:
      "unfilteredLists": {
        "triggered": false,
        "message": "No unfiltered list queries detected.",
        "details": [],
        "paginationArgsChecked": ["first", "last", "after", "before", "offset", "limit"]
      }
  • Test Case 4: Query with multiple lists, one paginated, one unfiltered (Should Trigger for the unfiltered one)

    • Query:
      query {
        posts(last: 3) {
          nodes {
            id
          }
        }
        categories { # Unfiltered
          nodes {
            id
            name
          }
        }
      }
    • Expected Output in debugExtensions.unfilteredLists:
      "unfilteredLists": {
        "triggered": true,
        "message": "Unfiltered list queries detected for: categories. Consider adding pagination (e.g., first, last, after, before, offset, limit) to these fields for performance.",
        "details": ["categories"],
        "paginationArgsChecked": ["first", "last", "after", "before", "offset", "limit"]
      }
  • Test Case 5: Query with no list fields (Should NOT Trigger Warning)

    • Query:
      query {
        viewer {
          id
          email
        }
      }
    • Expected Output in debugExtensions.unfilteredLists:
      "unfilteredLists": {
        "triggered": false,
        "message": "No unfiltered list queries detected.",
        "details": [],
        "paginationArgsChecked": ["first", "last", "after", "before", "offset", "limit"]
      }

Checklist

  • I have read the CONTRIBUTING document
  • My code follows the project's coding standards
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (if applicable)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works (if applicable - note: these are manual tests described in "How Has This Been Tested?" section)
  • Any dependent changes have been highlighted, merged or published

@theodesp theodesp requested a review from a team as a code owner July 30, 2025 13:41
@changeset-bot
Copy link

changeset-bot bot commented Jul 30, 2025

⚠️ No Changeset found

Latest commit: dff45ba

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link

github-actions bot commented Jul 30, 2025

ℹ️ Download the latest wpgraphql-debug-extensions plugin zip from this PR
(See the 'Artifacts' section at the bottom)

Copy link
Member

@colinmurphy colinmurphy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀 🚀 🚀

@theodesp theodesp added this pull request to the merge queue Jul 31, 2025
Merged via the queue into main with commit fe3fe2f Jul 31, 2025
8 checks passed
@theodesp theodesp deleted the feature-debug-extensions-unfiltered-lists-rule branch July 31, 2025 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants