|
1 | 1 | CHANGELOG
|
2 | 2 | =========
|
3 | 3 |
|
| 4 | +0.6.4 - 2025-07-08 |
| 5 | +------------------ |
| 6 | + |
| 7 | +This release improves how types inherit fields from other mapped types using `@mapper.type(...)`. |
| 8 | +You can now safely inherit from another mapped type, and the resulting GraphQL type will include all expected fields with predictable conflict resolution. |
| 9 | + |
| 10 | +Some examples: |
| 11 | + |
| 12 | +- Basic Inheritance: |
| 13 | + |
| 14 | +```python |
| 15 | +@mapper.type(ModelA) |
| 16 | +class ApiA: |
| 17 | + pass |
| 18 | + |
| 19 | + |
| 20 | +@mapper.type(ModelB) |
| 21 | +class ApiB(ApiA): |
| 22 | + # ApiB inherits all fields declared in ApiA |
| 23 | + pass |
| 24 | +``` |
| 25 | + |
| 26 | + |
| 27 | +- The `__exclude__` option continues working: |
| 28 | + |
| 29 | +```python |
| 30 | +@mapper.type(ModelA) |
| 31 | +class ApiA: |
| 32 | + __exclude__ = ["relationshipB_id"] |
| 33 | + |
| 34 | + |
| 35 | +@mapper.type(ModelB) |
| 36 | +class ApiB(ApiA): |
| 37 | + # ApiB will have all fields declared in ApiA, except "relationshipB_id" |
| 38 | + pass |
| 39 | +``` |
| 40 | + |
| 41 | +- If two SQLAlchemy models define fields with the same name, the field from the model inside `.type(...)` takes precedence: |
| 42 | + |
| 43 | +```python |
| 44 | +class ModelA(base): |
| 45 | + __tablename__ = "a" |
| 46 | + |
| 47 | + id = Column(String, primary_key=True) |
| 48 | + example_field = Column(String(50)) |
| 49 | + |
| 50 | + |
| 51 | +class ModelB(base): |
| 52 | + __tablename__ = "b" |
| 53 | + |
| 54 | + id = Column(String, primary_key=True) |
| 55 | + example_field = Column(Integer, autoincrement=True) |
| 56 | + |
| 57 | + |
| 58 | +@mapper.type(ModelA) |
| 59 | +class ApiA: |
| 60 | + # example_field will be a String |
| 61 | + pass |
| 62 | + |
| 63 | + |
| 64 | +@mapper.type(ModelB) |
| 65 | +class ApiB(ApiA): |
| 66 | + # example_field will be taken from ModelB and will be an Integer |
| 67 | + pass |
| 68 | +``` |
| 69 | + |
| 70 | + |
| 71 | +- If a field is explicitly declared in the mapped type, it will override any inherited or model-based definition: |
| 72 | + |
| 73 | +```python |
| 74 | +class ModelA(base): |
| 75 | + __tablename__ = "a" |
| 76 | + |
| 77 | + id = Column(String, primary_key=True) |
| 78 | + example_field = Column(String(50)) |
| 79 | + |
| 80 | + |
| 81 | +class ModelB(base): |
| 82 | + __tablename__ = "b" |
| 83 | + |
| 84 | + id = Column(String, primary_key=True) |
| 85 | + example_field = Column(Integer, autoincrement=True) |
| 86 | + |
| 87 | + |
| 88 | +@mapper.type(ModelA) |
| 89 | +class ApiA: |
| 90 | + pass |
| 91 | + |
| 92 | + |
| 93 | +@mapper.type(ModelB) |
| 94 | +class ApiB(ApiA): |
| 95 | + # example_field will be a Float |
| 96 | + example_field: float = strawberry.field(name="exampleField") |
| 97 | +``` |
| 98 | + |
| 99 | +Contributed by [Luis Gustavo](https://github.com/Ckk3) via [PR #253](https://github.com/strawberry-graphql/strawberry-sqlalchemy/pull/253/) |
| 100 | + |
| 101 | + |
4 | 102 | 0.6.3 - 2025-06-21
|
5 | 103 | ------------------
|
6 | 104 |
|
|
0 commit comments