Skip to content

Test query batching with vars, ops, and extensions #3958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

DoctorJohn
Copy link
Member

@DoctorJohn DoctorJohn commented Jul 23, 2025

Description

This PR adds extra query batching tests, making sure supplying variables, selecting operations, using operation extensions, and context sharing work as expected.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Documentation

Summary by Sourcery

Add comprehensive tests for HTTP GraphQL query batching covering single/multiple queries, variables, operation selection, extensions, and shared context, and extend the test schema to support dynamic context key access and context updates.

Enhancements:

  • Allow value_from_context field to accept a dynamic key parameter
  • Add update_context mutation to enable modifying context during tests

Tests:

  • Add tests to verify batching works with multiple and single queries
  • Add tests to verify per-query variable injection
  • Add tests to verify operationName selection in batched queries
  • Add tests to verify per-query extensions handling
  • Add test to verify shared context across batched operations

Copy link
Contributor

sourcery-ai bot commented Jul 23, 2025

Reviewer's Guide

This PR enhances GraphQL query batching tests by introducing a reusable batching client fixture, adding new test cases for various batching scenarios (single/multiple queries, variables, operation selection, extensions, and shared context), and extending the test schema with dynamic context retrieval and a mutation to update context.

File-Level Changes

Change Details Files
Introduce batching_http_client fixture for enabling query batching in tests
  • Import pytest and skip_if_gql_32
  • Define batching_http_client fixture
  • Refactor existing test to use the new fixture
tests/http/test_query_batching.py
Add tests covering various GraphQL query batching scenarios
  • Batching with multiple and single queries
  • Per-query variable injection
  • OperationName selection
  • Per-query extensions handling with skip_if_gql_32
  • Shared context between operations
tests/http/test_query_batching.py
Extend test schema to support dynamic context operations
  • Allow value_from_context to accept a dynamic key
  • Add update_context mutation to modify context during batching
tests/views/schema.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @DoctorJohn - I've reviewed your changes - here's some feedback:

  • Consider parameterizing the batch payload tests for variables, operationName, and extensions to reduce duplication and improve maintainability.
  • Extract a small helper or fixture for sending batch requests with default headers to avoid repeating the same post call in every test.
  • Rename the batching_http_client fixture to a more conventional name like client to align with other tests and reduce verbosity.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider parameterizing the batch payload tests for variables, operationName, and extensions to reduce duplication and improve maintainability.
- Extract a small helper or fixture for sending batch requests with default headers to avoid repeating the same post call in every test.
- Rename the batching_http_client fixture to a more conventional name like `client` to align with other tests and reduce verbosity.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR enhances the test coverage for GraphQL query batching functionality by adding comprehensive tests that validate variables, operation selection, extensions, and context sharing between batched operations.

The changes consist of two main modifications:

  1. Test Schema Enhancement (tests/views/schema.py): The existing test schema is updated to support more flexible testing scenarios. The value_from_context method now accepts an optional key parameter (defaulting to 'custom_value') allowing tests to access different context keys. A new update_context mutation is added that enables modifying the context during execution, which is essential for testing context sharing between operations in a batch.

  2. Comprehensive Test Suite (tests/http/test_query_batching.py): The testing approach is refactored from a single test function to a fixture-based system with multiple focused test cases. The new tests validate:

    • Basic single and multiple query batching
    • Variables being correctly supplied to individual queries in a batch
    • Operation selection working independently for each query
    • Extensions being handled per-query within batches
    • Context sharing between operations (mutations can modify context that subsequent queries access)

These changes integrate well with Strawberry's existing GraphQL implementation by leveraging the standard strawberry.Info context pattern and following established testing conventions. The modifications are focused on test infrastructure and don't affect production code behavior, making them safe additions to validate the robustness of the query batching feature.

Confidence score: 4/5

• This PR is very safe to merge as it only adds test coverage without changing production code
• Score reduced by 1 due to one test being conditionally skipped for GraphQL 3.2 due to formatting differences, which suggests potential edge cases that might need attention
• No files require additional attention - the changes are well-structured test enhancements

2 files reviewed, no comments

Edit Code Review Bot Settings | Greptile

Copy link

codecov bot commented Jul 23, 2025

Codecov Report

Attention: Patch coverage is 91.17647% with 3 lines in your changes missing coverage. Please review.

Project coverage is 94.40%. Comparing base (d79dd55) to head (08ed89a).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3958      +/-   ##
==========================================
- Coverage   94.41%   94.40%   -0.01%     
==========================================
  Files         528      528              
  Lines       34342    34371      +29     
  Branches     1803     1803              
==========================================
+ Hits        32423    32449      +26     
- Misses       1627     1630       +3     
  Partials      292      292              
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@DoctorJohn DoctorJohn requested a review from patrick91 July 23, 2025 15:48
Copy link

codspeed-hq bot commented Jul 23, 2025

CodSpeed Performance Report

Merging #3958 will not alter performance

Comparing DoctorJohn:test-query-batching-with-variables-operations-and-extensions (08ed89a) with main (d79dd55)

Summary

✅ 26 untouched benchmarks

@patrick91 patrick91 merged commit 1994b0c into strawberry-graphql:main Jul 23, 2025
95 of 96 checks passed
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.

2 participants