Skip to content

fix: handle lazy connection type #3941

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

Merged

Conversation

rcybulski1122012
Copy link
Member

@rcybulski1122012 rcybulski1122012 commented Jul 10, 2025

Fixes ConnectionExtension, so if a lazy connection type is specified via graphql_type argument, it is resolved.

Types of Changes

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

Issues Fixed or Closed by This PR

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

Summary by Sourcery

Resolve lazy connection types in Strawberry Relay to correctly handle connections specified via lazy annotations.

Bug Fixes:

  • Add resolution for LazyType on field type and type origin in Relay field application to support lazy connection types.

Tests:

  • Add test for lazy optional connection to verify correct resolution of lazy connection types.

Copy link
Contributor

sourcery-ai bot commented Jul 10, 2025

Reviewer's Guide

This PR updates Relay field handling to resolve lazy connection types before type checks and adds a corresponding test to ensure optional lazy connections work as expected.

File-Level Changes

Change Details Files
Resolve lazy connection types in Relay field application
  • Check f_type for LazyType and call resolve_type
  • Resolve type_origin if it’s a LazyType before subclass check
strawberry/relay/fields.py
Add test for lazy optional connection support
  • Define a Query type using a lazy connection annotation
  • Execute the schema and assert null result with no errors
tests/relay/test_connection.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 @rcybulski1122012 - I've reviewed your changes and they look great!


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.

PR Summary

Fixes handling of lazy connection types in the ConnectionExtension class, ensuring proper resolution of types specified via graphql_type argument in Relay connections.

  • Added LazyType resolution handling in strawberry/relay/fields.py for ConnectionExtension class
  • Added test case test_lazy_optional_connection in tests/relay/test_connection.py to verify proper lazy type resolution
  • Important fix for scenarios involving circular imports where lazy loading is necessary

2 files reviewed, 1 comment
Edit PR Review Bot Settings | Greptile

@botberry
Copy link
Member

botberry commented Jul 10, 2025

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


This release adds support for lazy types in ConnectionExtension.

Here's the tweet text:

🆕 Release (next) is out! Thanks to Radosław Cybulski for the PR 👏

Get it here 👉 https://strawberry.rocks/release/(next)

Copy link

codecov bot commented Jul 10, 2025

Codecov Report

Attention: Patch coverage is 94.73684% with 2 lines in your changes missing coverage. Please review.

Project coverage is 94.75%. Comparing base (74c2cef) to head (f765ed1).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3941      +/-   ##
==========================================
- Coverage   94.75%   94.75%   -0.01%     
==========================================
  Files         520      520              
  Lines       33902    33934      +32     
  Branches     1754     1756       +2     
==========================================
+ Hits        32123    32153      +30     
- Misses       1497     1498       +1     
- Partials      282      283       +1     
🚀 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.

Copy link

codspeed-hq bot commented Jul 10, 2025

CodSpeed Performance Report

Merging #3941 will not alter performance

Comparing rcybulski1122012:fix-lazy-connection-type (f765ed1) with main (74c2cef)

Summary

✅ 26 untouched benchmarks

@DoctorJohn DoctorJohn requested a review from bellini666 July 12, 2025 12:13
Copy link
Member

@bellini666 bellini666 left a comment

Choose a reason for hiding this comment

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

Ty for this 😊

@bellini666 bellini666 merged commit fa1ddbe into strawberry-graphql:main Jul 14, 2025
101 of 102 checks passed
@botberry
Copy link
Member

Thanks for contributing to Strawberry! 🎉 You've been invited to join
the Strawberry GraphQL organisation 😊

You can also request a free sticker by filling this form: https://forms.gle/dmnfQUPoY5gZbVT67

And don't forget to join our discord server: https://strawberry.rocks/discord 🔥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants