|
1 | 1 | CHANGELOG |
2 | 2 | ========= |
3 | 3 |
|
| 4 | +0.289.6 - 2026-01-26 |
| 5 | +-------------------- |
| 6 | + |
| 7 | +This release adds support for field extensions in experimental pydantic types. |
| 8 | + |
| 9 | +Previously, when using `@strawberry.experimental.pydantic.type()` decorator, field extensions defined with `strawberry.field(extensions=[...])` were not being propagated to the generated Strawberry fields. This meant extensions like authentication, caching, or result transformation couldn't be used with pydantic-based types. |
| 10 | + |
| 11 | +This fix ensures that extensions are properly preserved when converting pydantic fields to Strawberry fields, enabling the full power of field extensions across the pydantic integration. |
| 12 | + |
| 13 | +Examples: |
| 14 | + |
| 15 | +**Permission-based field masking:** |
| 16 | + |
| 17 | +```python |
| 18 | +from pydantic import BaseModel |
| 19 | +from typing import Optional |
| 20 | +import strawberry |
| 21 | +from strawberry.experimental.pydantic import type as pyd_type |
| 22 | +from strawberry.extensions.field_extension import FieldExtension |
| 23 | + |
| 24 | + |
| 25 | +class PermissionExtension(FieldExtension): |
| 26 | + def resolve(self, next_, source, info, **kwargs): |
| 27 | + # Check permission, return None if denied |
| 28 | + if not check_field_access(info.context.user, info.field_name, source.id): |
| 29 | + return None |
| 30 | + return next_(source, info, **kwargs) |
| 31 | + |
| 32 | + |
| 33 | +class UserModel(BaseModel): |
| 34 | + id: int |
| 35 | + fname: str |
| 36 | + email: str |
| 37 | + phone: str |
| 38 | + |
| 39 | + |
| 40 | +perm_ext = PermissionExtension() |
| 41 | + |
| 42 | + |
| 43 | +@pyd_type(model=UserModel) |
| 44 | +class UserGQL: |
| 45 | + # Public fields - just use auto |
| 46 | + id: strawberry.auto |
| 47 | + fname: strawberry.auto |
| 48 | + |
| 49 | + # Protected fields - attach extension |
| 50 | + email: Optional[str] = strawberry.field(extensions=[perm_ext]) |
| 51 | + phone: Optional[str] = strawberry.field(extensions=[perm_ext]) |
| 52 | +``` |
| 53 | + |
| 54 | +**Basic transformation extension:** |
| 55 | + |
| 56 | +```python |
| 57 | +class UpperCaseExtension(FieldExtension): |
| 58 | + def resolve(self, next_, source, info, **kwargs): |
| 59 | + result = next_(source, info, **kwargs) |
| 60 | + return str(result).upper() |
| 61 | + |
| 62 | + |
| 63 | +class ProductModel(BaseModel): |
| 64 | + name: str |
| 65 | + |
| 66 | + |
| 67 | +@pyd_type(model=ProductModel) |
| 68 | +class Product: |
| 69 | + name: str = strawberry.field(extensions=[UpperCaseExtension()]) |
| 70 | +``` |
| 71 | + |
| 72 | +Contributed by [Srikanth](https://github.com/XChikuX) via [PR #4171](https://github.com/strawberry-graphql/strawberry/pull/4171/) |
| 73 | + |
| 74 | + |
4 | 75 | 0.289.5 - 2026-01-25 |
5 | 76 | -------------------- |
6 | 77 |
|
|
0 commit comments