Skip to content

Commit 3823b9c

Browse files
committed
Add support for dictionary config and deprecate StrawberryConfig class
1 parent abbe4c2 commit 3823b9c

File tree

18 files changed

+282
-83
lines changed

18 files changed

+282
-83
lines changed

docs/breaking-changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ title: List of breaking changes and deprecations
44

55
# List of breaking changes and deprecations
66

7+
- [Version 0.285.0 - Deprecate StrawberryConfig Class - 30 October 2025](./breaking-changes/0.285.0.md)
78
- [Version 0.279.0 - 19 August 2025](./breaking-changes/0.279.0.md)
89
- [Version 0.278.1 - 5 August 2025](./breaking-changes/0.278.1.md)
910
- [Version 0.268.0 - 10 May 2025](./breaking-changes/0.268.0.md)

docs/breaking-changes/0.285.0.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
title: 0.285.0 Deprecations
3+
slug: breaking-changes/0.285.0
4+
---
5+
6+
# v0.285.0 Deprecations
7+
8+
In this release, we've simplified the schema configuration API by migrating from
9+
a class-based approach to a dictionary-based approach.
10+
11+
## What Changed
12+
13+
The `StrawberryConfig` class syntax is now **deprecated** and will show a
14+
`DeprecationWarning`. The class will be removed in a future release.
15+
16+
Instead of instantiating a config class, you should now pass a plain Python
17+
dictionary to the `config` parameter when creating a schema.
18+
19+
## Migration
20+
21+
Convert the class instantiation to a dictionary:
22+
23+
**Before (deprecated):**
24+
25+
```python
26+
from strawberry.schema.config import StrawberryConfig
27+
28+
schema = strawberry.Schema(
29+
query=Query,
30+
config=StrawberryConfig(
31+
auto_camel_case=True,
32+
relay_max_results=50,
33+
),
34+
)
35+
```
36+
37+
**After (recommended):**
38+
39+
```python
40+
schema = strawberry.Schema(
41+
query=Query,
42+
config={
43+
"auto_camel_case": True,
44+
"relay_max_results": 50,
45+
},
46+
)
47+
```
48+
49+
The old syntax will continue to work but will show this warning:
50+
51+
```
52+
DeprecationWarning: Using StrawberryConfig as a class is deprecated as of v0.285.0.
53+
Use dictionary syntax instead: config={'auto_camel_case': True}.
54+
```
55+
56+
For more information, see the
57+
[Schema Configurations](../types/schema-configurations.md) documentation.

docs/guides/query-batching.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,14 @@ and how to integrate it into your application with an example using FastAPI.
1616

1717
## Enabling Query Batching
1818

19-
To enable query batching in Strawberry, you need to configure the
20-
`StrawberryConfig` when defining your GraphQL schema. The batching configuration
21-
is provided as a typed dictionary. Batching is disabled by default, if no
22-
configuration is provided.
19+
To enable query batching in Strawberry, you need to configure the schema config
20+
when defining your GraphQL schema. The batching configuration is provided as a
21+
dictionary. Batching is disabled by default, if no configuration is provided.
2322

2423
### Basic Configuration
2524

2625
```python
27-
from strawberry.schema.config import StrawberryConfig
28-
29-
config = StrawberryConfig(batching_config={"max_operations": 10})
26+
config = {"batching_config": {"max_operations": 10}}
3027
```
3128

3229
### Configuring Maximum Operations
@@ -35,9 +32,7 @@ To set a limit on the number of operations in a batch request, use the
3532
`max_operations` key:
3633

3734
```python
38-
from strawberry.schema.config import StrawberryConfig
39-
40-
config = StrawberryConfig(batching_config={"max_operations": 5})
35+
config = {"batching_config": {"max_operations": 5}}
4136
```
4237

4338
When batching is enabled, the server can handle a list of operations
@@ -52,7 +47,6 @@ Below is an example of how to enable query batching in a FastAPI application:
5247
import strawberry
5348
from fastapi import FastAPI
5449
from strawberry.fastapi import GraphQLRouter
55-
from strawberry.schema.config import StrawberryConfig
5650

5751

5852
@strawberry.type
@@ -64,7 +58,7 @@ class Query:
6458

6559
schema = strawberry.Schema(
6660
Query,
67-
config=StrawberryConfig(batching_config={"max_operations": 5}),
61+
config={"batching_config": {"max_operations": 5}},
6862
)
6963

7064
graphql_app = GraphQLRouter(schema)

docs/types/defer-and-stream.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ incremental execution in your schema configuration:
3131

3232
```python
3333
import strawberry
34-
from strawberry.schema.config import StrawberryConfig
3534

3635

3736
@strawberry.type
@@ -41,7 +40,7 @@ class Query:
4140

4241

4342
schema = strawberry.Schema(
44-
query=Query, config=StrawberryConfig(enable_experimental_incremental_execution=True)
43+
query=Query, config={"enable_experimental_incremental_execution": True}
4544
)
4645
```
4746

docs/types/schema-configurations.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,22 @@ title: Schema Configurations
44

55
# Schema Configurations
66

7-
Strawberry allows to customise how the schema is generated by passing
8-
configurations.
7+
Strawberry allows you to customise how the schema is generated by passing
8+
configuration options as a dictionary.
99

10-
To customise the schema you can create an instance of `StrawberryConfig`, as
11-
shown in the example below:
10+
To customise the schema, you can pass a configuration dictionary to the `config`
11+
parameter, as shown in the example below:
1212

1313
```python
1414
import strawberry
1515

16-
from strawberry.schema.config import StrawberryConfig
17-
1816

1917
@strawberry.type
2018
class Query:
2119
example_field: str
2220

2321

24-
schema = strawberry.Schema(query=Query, config=StrawberryConfig(auto_camel_case=False))
22+
schema = strawberry.Schema(query=Query, config={"auto_camel_case": False})
2523
```
2624

2725
In this case we are disabling the auto camel casing feature, so your output
@@ -33,6 +31,14 @@ type Query {
3331
}
3432
```
3533

34+
<Note>
35+
36+
**Upgrading from v0.284.0 or earlier?** See the
37+
[v0.285.0 breaking changes](../breaking-changes/0.285.0.md) for migration
38+
instructions if you were using the old `StrawberryConfig` class syntax.
39+
40+
</Note>
41+
3642
## Available configurations
3743

3844
Here's a list of the available configurations:
@@ -44,7 +50,7 @@ like `example_field` will be converted to `exampleField`. You can disable this
4450
feature by setting `auto_camel_case` to `False`.
4551

4652
```python
47-
schema = strawberry.Schema(query=Query, config=StrawberryConfig(auto_camel_case=False))
53+
schema = strawberry.Schema(query=Query, config={"auto_camel_case": False})
4854
```
4955

5056
### default_resolver
@@ -58,8 +64,6 @@ resolver.
5864
```python
5965
import strawberry
6066

61-
from strawberry.schema.config import StrawberryConfig
62-
6367

6468
def custom_resolver(obj, field):
6569
try:
@@ -80,9 +84,7 @@ class Query:
8084
return {"name": "Patrick"}
8185

8286

83-
schema = strawberry.Schema(
84-
query=Query, config=StrawberryConfig(default_resolver=custom_resolver)
85-
)
87+
schema = strawberry.Schema(query=Query, config={"default_resolver": custom_resolver})
8688
```
8789

8890
### relay_max_results
@@ -91,7 +93,7 @@ By default Strawberry's max limit for relay connections is 100. You can
9193
customise this by setting the `relay_max_results` configuration.
9294

9395
```python
94-
schema = strawberry.Schema(query=Query, config=StrawberryConfig(relay_max_results=50))
96+
schema = strawberry.Schema(query=Query, config={"relay_max_results": 50})
9597
```
9698

9799
### disable_field_suggestions
@@ -101,9 +103,7 @@ schema. You can disable this feature by setting `disable_field_suggestions` to
101103
`True`.
102104

103105
```python
104-
schema = strawberry.Schema(
105-
query=Query, config=StrawberryConfig(disable_field_suggestions=True)
106-
)
106+
schema = strawberry.Schema(query=Query, config={"disable_field_suggestions": True})
107107
```
108108

109109
### info_class
@@ -123,7 +123,7 @@ class CustomInfo(Info):
123123
return self.context["response"].headers
124124

125125

126-
schema = strawberry.Schema(query=Query, config=StrawberryConfig(info_class=CustomInfo))
126+
schema = strawberry.Schema(query=Query, config={"info_class": CustomInfo})
127127
```
128128

129129
### enable_experimental_incremental_execution
@@ -142,7 +142,7 @@ response to be delivered incrementally.
142142

143143
```python
144144
schema = strawberry.Schema(
145-
query=Query, config=StrawberryConfig(enable_experimental_incremental_execution=True)
145+
query=Query, config={"enable_experimental_incremental_execution": True}
146146
)
147147
```
148148

strawberry/extensions/directives.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def process_directive(
8686
field_name=info.field_name,
8787
type_name=info.parent_type.name,
8888
)
89-
arguments[info_parameter.name] = schema.config.info_class(
89+
arguments[info_parameter.name] = schema.config["info_class"](
9090
_raw_info=info, _field=field
9191
)
9292
if value_parameter:

strawberry/federation/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def _add_link_for_composed_directive(
238238
return
239239

240240
import_url = directive.compose_options.import_url
241-
name = self.config.name_converter.from_directive(directive)
241+
name = self.config["name_converter"].from_directive(directive)
242242

243243
# import url is required by Apollo Federation, this might change in
244244
# future to be optional, so for now, when it is not passed we
@@ -290,7 +290,7 @@ def _add_compose_directives(self) -> list["ComposeDirective"]:
290290
)
291291

292292
if is_federation_schema_directive and definition.compose_options:
293-
name = self.config.name_converter.from_directive(definition)
293+
name = self.config["name_converter"].from_directive(definition)
294294

295295
compose_directives.append(
296296
ComposeDirective(

strawberry/http/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ def _is_multipart_subscriptions(
8888
def _validate_batch_request(
8989
self, request_data: list[GraphQLRequestData], protocol: str
9090
) -> None:
91-
if self.schema.config.batching_config is None:
91+
if self.schema.config["batching_config"] is None:
9292
raise HTTPException(400, "Batching is not enabled")
9393

9494
if protocol == "multipart-subscription":
9595
raise HTTPException(
9696
400, "Batching is not supported for multipart subscriptions"
9797
)
9898

99-
if len(request_data) > self.schema.config.batching_config["max_operations"]:
99+
if len(request_data) > self.schema.config["batching_config"]["max_operations"]:
100100
raise HTTPException(400, "Too many operations")
101101

102102

strawberry/printer/printer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def print_schema_directive_params(
131131
ast = ast_from_value(
132132
_serialize_dataclasses(
133133
value,
134-
name_converter=schema.config.name_converter.apply_naming_config,
134+
name_converter=schema.config["name_converter"].apply_naming_config,
135135
),
136136
arg.type,
137137
)
@@ -157,7 +157,7 @@ def print_schema_directive(
157157
params = print_schema_directive_params(
158158
gql_directive,
159159
{
160-
schema.config.name_converter.get_graphql_name(f): getattr(
160+
schema.config["name_converter"].get_graphql_name(f): getattr(
161161
directive, f.python_name or f.name, UNSET
162162
)
163163
for f in strawberry_directive.fields
@@ -616,7 +616,7 @@ def print_schema(schema: BaseSchema) -> str:
616616
if (printed_directive := print_directive(directive, schema=schema)) is not None
617617
]
618618

619-
if schema.config.enable_experimental_incremental_execution:
619+
if schema.config["enable_experimental_incremental_execution"]:
620620
directives.append(
621621
"directive @defer(if: Boolean, label: String) on FRAGMENT_SPREAD | INLINE_FRAGMENT"
622622
)

strawberry/relay/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def from_arguments(
131131
max_results = (
132132
max_results
133133
if max_results is not None
134-
else info.schema.config.relay_max_results
134+
else info.schema.config["relay_max_results"]
135135
)
136136
start = 0
137137
end: int | None = None

0 commit comments

Comments
 (0)