Skip to content
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

Add default values to Context and RootValue type vars #3732

Merged
merged 13 commits into from
Dec 20, 2024

Conversation

patrick91
Copy link
Member

@patrick91 patrick91 commented Dec 20, 2024

Closes #2711

Summary by Sourcery

Set default values for the Context and RootValue type variables to None.

New Features:

  • Add default values to Context and RootValue type variables.

Enhancements:

  • Remove unnecessary type parameters from GraphQLRouter instantiation.

Copy link
Contributor

sourcery-ai bot commented Dec 20, 2024

Reviewer's Guide by Sourcery

This pull request adds default values to the Context and RootValue type variables in strawberry.http.typevars.py. This addresses a typing issue and makes the code more robust by providing default values for these type variables. The changes were made by modifying the TypeVar declarations for Context and RootValue to include default=None.

Class diagram showing updated TypeVar definitions

classDiagram
    class TypeVars {
        +Request: TypeVar[contravariant=True]
        +Response: TypeVar
        +SubResponse: TypeVar
        +WebSocketRequest: TypeVar
        +WebSocketResponse: TypeVar
        +Context: TypeVar[default=None]
        +RootValue: TypeVar[default=None]
    }
    note for TypeVars "Context and RootValue now have default=None"
Loading

File-Level Changes

Change Details Files
Added default values to the typevars
  • Added default=None to the TypeVar declarations for Context and RootValue.
  • Imported TypeVar from typing_extensions instead of typing.
  • Reordered the __all__ list to maintain alphabetical order.
strawberry/http/typevars.py
Updated usages of typevars
  • Removed explicit type variable declarations from GraphQLRouter instances, allowing the default values to be used.
tests/fastapi/test_context.py

Assessment against linked issues

Issue Objective Addressed Explanation
#2711 Fix mypy type annotation error for 'graphql_app' variable when using strawberry-graphql>=0.169.0

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.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a 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. You can also use
    this command to specify where the summary should be inserted.

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 @patrick91 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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.

@botberry
Copy link
Member

botberry commented Dec 20, 2024

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


This release updates the Context and RootValue vars to have
a default value of None, this makes it easier to use the views
without having to pass in a value for these vars.

Here's the tweet text:

🆕 Release (next) is out! Thanks to @patrick91 for the PR 👏

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

Copy link

codecov bot commented Dec 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.97%. Comparing base (633c9bc) to head (8f09415).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3732   +/-   ##
=======================================
  Coverage   96.97%   96.97%           
=======================================
  Files         503      503           
  Lines       33702    33708    +6     
  Branches     5627     5627           
=======================================
+ Hits        32683    32689    +6     
  Misses        809      809           
  Partials      210      210           

Copy link

codspeed-hq bot commented Dec 20, 2024

CodSpeed Performance Report

Merging #3732 will not alter performance

Comparing feature/default-vars (8f09415) with main (633c9bc)

Summary

✅ 21 untouched benchmarks

@patrick91 patrick91 force-pushed the feature/default-vars branch from c4c74b8 to c2a9e45 Compare December 20, 2024 09:40
@patrick91 patrick91 force-pushed the feature/default-vars branch from c2a9e45 to 27f00f3 Compare December 20, 2024 09:43
@patrick91 patrick91 force-pushed the feature/default-vars branch 9 times, most recently from f3cde26 to e25d421 Compare December 20, 2024 10:31
@patrick91 patrick91 force-pushed the feature/default-vars branch from e25d421 to 016515e Compare December 20, 2024 10:50
@botberry
Copy link
Member

botberry commented Dec 20, 2024

Apollo Federation Subgraph Compatibility Results

Federation 1 Support Federation 2 Support
_service🟢
@key (single)🟢
@key (multi)🟢
@key (composite)🟢
repeatable @key🟢
@requires🟢
@provides🟢
federated tracing🔲
@link🟢
@shareable🟢
@tag🟢
@override🟢
@inaccessible🟢
@composeDirective🟢
@interfaceObject🟢

Learn more:

@patrick91 patrick91 force-pushed the feature/default-vars branch from 265f442 to 4911b3a Compare December 20, 2024 12:22
@patrick91 patrick91 force-pushed the feature/default-vars branch from 6539b0e to bb11f8f Compare December 20, 2024 12:34
@patrick91 patrick91 force-pushed the feature/default-vars branch from 424f4a4 to e6b93ad Compare December 20, 2024 12:38
@patrick91 patrick91 force-pushed the feature/default-vars branch from e6b93ad to c028798 Compare December 20, 2024 12:40
@patrick91 patrick91 force-pushed the feature/default-vars branch from ce17110 to eb45704 Compare December 20, 2024 12:46
@patrick91 patrick91 enabled auto-merge (squash) December 20, 2024 12:57
@patrick91 patrick91 disabled auto-merge December 20, 2024 13:03
@patrick91 patrick91 merged commit 71ac2d6 into main Dec 20, 2024
108 checks passed
@patrick91 patrick91 deleted the feature/default-vars branch December 20, 2024 13:03
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.

mypy: Need type annotation for "graphql_app" [var-annotated]
2 participants