Skip to content

Conversation

@patrick91
Copy link
Member

@patrick91 patrick91 commented Oct 30, 2025

I wanted to make it backwards compatibile, but not fully sure it is worth it, since the user changes should be pretty small

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 30, 2025

Reviewer's Guide

Transition schema configuration to a dictionary-based API by introducing a TypedDict, deprecating the StrawberryConfig class, adding normalization logic, refactoring internal accesses, and updating documentation.

File-Level Changes

Change Details Files
Introduce TypedDict-based config and deprecate class-based StrawberryConfig
  • Added StrawberryConfig TypedDict with optional fields
  • Renamed dataclass to _StrawberryConfigClass and emit deprecation warning
  • Implemented _complete_config to normalize, default, and validate configs
  • Updated all to export TypedDict and normalization function
strawberry/schema/config.py
Normalize and apply defaults in Schema constructor
  • Changed Schema.init to accept dict or deprecated class instance
  • Replaced instantiation of config dataclass with call to _complete_config
  • Updated imports to reference _complete_config and _StrawberryConfigClass
strawberry/schema/schema.py
Migrate internal config access to dictionary lookups
  • Replaced attribute-style config.field with config["field"] lookups
  • Updated name_converter, default_resolver, relay options, and directive naming in converters and printers
  • Adjusted HTTP batching and locate_definition to use dict-based config
strawberry/schema/schema_converter.py
strawberry/printer/printer.py
strawberry/federation/schema.py
strawberry/http/base.py
strawberry/relay/utils.py
strawberry/schema/base.py
strawberry/utils/locate_definition.py
Update documentation to reflect dict-based config and add breaking change entry
  • Rewrote examples in various docs to use dict syntax
  • Added breaking-changes/0.285.0.md with deprecation and migration instructions
  • Updated breaking-changes.md to include new version
docs/types/schema-configurations.md
docs/guides/query-batching.md
docs/types/defer-and-stream.md
docs/breaking-changes.md
docs/breaking-changes/0.285.0.md

Possibly linked issues

  • #issue: The PR changes StrawberryConfig to a TypedDict and deprecates the class, as suggested by the issue.

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

@botberry
Copy link
Member

botberry commented Oct 30, 2025

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/strawberry-config-dict branch from 035c8a9 to 3823b9c Compare October 30, 2025 14:34
@codecov
Copy link

codecov bot commented Oct 30, 2025

Codecov Report

❌ Patch coverage is 77.11864% with 27 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.29%. Comparing base (846b3c4) to head (aba9676).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4039      +/-   ##
==========================================
- Coverage   94.39%   94.29%   -0.10%     
==========================================
  Files         534      535       +1     
  Lines       34834    34878      +44     
  Branches     1831     1839       +8     
==========================================
+ Hits        32881    32889       +8     
- Misses       1657     1691      +34     
- Partials      296      298       +2     
🚀 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.

@patrick91 patrick91 force-pushed the feature/strawberry-config-dict branch 2 times, most recently from f22d944 to a0a908b Compare October 30, 2025 14:49
@codspeed-hq
Copy link

codspeed-hq bot commented Oct 30, 2025

CodSpeed Performance Report

Merging #4039 will not alter performance

Comparing feature/strawberry-config-dict (aba9676) with main (846b3c4)

Summary

✅ 28 untouched

@patrick91 patrick91 force-pushed the feature/strawberry-config-dict branch from a0a908b to aba9676 Compare October 30, 2025 15:31
@patrick91 patrick91 changed the title Add support for dictionary config and deprecate StrawberryConfig class Change StrawberryConfig to be a dictionary instead of a class Oct 30, 2025
)

if len(request_data) > self.schema.config.batching_config["max_operations"]:
if len(request_data) > self.schema.config["batching_config"]["max_operations"]:
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about the visual noise we're adding here 😬
But I love that the config is now a dict for the user, so I guess we've got to live with it internally :D

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, it's not fun 😅

Comment on lines +70 to +81
if TYPE_CHECKING:
# For type checkers, show these as instance attributes
auto_camel_case: bool | None
name_converter: NameConverter
default_resolver: Callable[[Any, str], object]
relay_max_results: int
relay_use_legacy_global_id: bool
disable_field_suggestions: bool
info_class: type[Info]
enable_experimental_incremental_execution: bool
_unsafe_disable_same_type_validation: bool
batching_config: BatchingConfig | None
Copy link
Member

Choose a reason for hiding this comment

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

on the other hand, how would we make clear the default values in an accessible way? For the dataclass they were immediately visiblei n the type overlay. looking into _complete_config seems more complicated and less direct

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess we need to make a custom language server? :P

but probably better docs?

Copy link
Member

Choose a reason for hiding this comment

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

yea let's make sure everything is documented in here, maybe in a short table: https://strawberry.rocks/docs/types/schema-configurations#available-configurations

we could auto generate that from the code as well with minor adjustments :P

Copilot finished reviewing on behalf of patrick91 November 18, 2025 17:43
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR migrates the schema configuration API from a class-based approach (StrawberryConfig dataclass) to a dictionary-based approach. The migration includes updating all internal usages from attribute access (config.field) to dictionary access (config["field"]), updating tests and documentation, and providing a codemod tool for user migration.

Key Changes

  • StrawberryConfig changed from a dataclass to a dict subclass (StrawberryConfigDict) with backwards-compatible attribute access
  • All config access patterns updated to dictionary-style throughout the codebase
  • Tests updated to use dictionary syntax for configuration
  • Documentation and migration guide added

Reviewed Changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
strawberry/schema/config.py Core config implementation changed from dataclass to TypedDict/dict-based system
strawberry/schema/schema.py Updated to use _complete_config() function and dictionary access patterns
strawberry/schema/schema_converter.py All config accesses changed to dictionary-style (config["key"])
strawberry/schema/base.py Type annotations and config access updated
strawberry/utils/locate_definition.py Config access changed to dictionary-style
strawberry/types/arguments.py Config access changed to dictionary-style
strawberry/relay/utils.py Config access changed to dictionary-style
strawberry/printer/printer.py Config access changed to dictionary-style
strawberry/http/base.py Config access changed to dictionary-style with nested access
strawberry/federation/schema.py Config access changed to dictionary-style
strawberry/extensions/directives.py Config access changed to dictionary-style
strawberry/codemods/config_to_dict.py New codemod tool for automated migration
strawberry/codemods/init.py Export new codemod
tests/schema/test_config.py Tests updated but still use class instantiation syntax
tests/schema/test_camel_casing.py Tests updated to dictionary syntax
tests/test_printer/*.py Tests updated to dictionary syntax
tests/federation/printer/*.py Tests updated to dictionary syntax
tests/objects/generics/test_names.py Refactored to use NameConverter directly instead of via config
docs/types/schema-configurations.md Documentation updated with dictionary examples
docs/types/defer-and-stream.md Documentation updated with dictionary examples
docs/guides/query-batching.md Documentation updated with dictionary examples
docs/breaking-changes/0.285.0.md New migration guide added
docs/breaking-changes.md Added link to new migration guide

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +35 to +45
class StrawberryConfigDict(dict[str, Any]):
"""Configuration for Strawberry Schema.
This is a dictionary-like class that defines the configuration options for a
Strawberry schema. All fields are optional - missing fields will be filled with
sensible defaults.
This class supports both dictionary-style access (config["name_converter"]) and
attribute-style access (config.name_converter) for backwards compatibility.
Example:
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

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

StrawberryConfigDict is missing a custom __init__ method to handle initialization with keyword arguments. When users call StrawberryConfig(auto_camel_case=True) (as shown in test_config.py), the built-in dict __init__ creates {'auto_camel_case': True} without applying defaults or the auto_camel_case → name_converter conversion. This breaks backwards compatibility. Add an __init__ method that calls _complete_config to ensure proper initialization.

Copilot uses AI. Check for mistakes.
Comment on lines +157 to +160
# Backwards compatibility: StrawberryConfig is StrawberryConfigDict
# This works at runtime and for type checking because StrawberryConfigDict
# has TYPE_CHECKING annotations that make attributes visible to type checkers
StrawberryConfig = StrawberryConfigDict
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

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

The breaking changes documentation (docs/breaking-changes/0.285.0.md) states that using StrawberryConfig as a class will show a DeprecationWarning, but no such warning is emitted in the code. Either add a deprecation warning mechanism or update the documentation to reflect that the old syntax is simply not recommended rather than deprecated with a warning.

Copilot uses AI. Check for mistakes.

# List of breaking changes and deprecations

- [Version 0.285.0 - Deprecate StrawberryConfig Class - 30 October 2025](./breaking-changes/0.285.0.md)
Copy link
Member

Choose a reason for hiding this comment

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

polish: this is not following the pattern of the ones below

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.

5 participants