Skip to content

Commit 7c0b15d

Browse files
committed
Add more usage/limitations docs
1 parent a7745e7 commit 7c0b15d

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,63 @@ strawberry_sqlalchemy_mapper = StrawberrySQLAlchemyMapper()
4444
@strawberry_sqlalchemy_mapper.type(models.Employee)
4545
class Employee:
4646
pass
47+
48+
49+
# call finalize() before using the schema:
50+
strawberry_sqlalchemy_mapper.finalize()
51+
# only needed if you have polymorphic types
52+
additional_types = list(strawberry_sqlalchemy_mapper.mapped_types.values())
53+
schema = strawberry.Schema(
54+
query=Query,
55+
mutation=Mutation,
56+
extensions=extensions,
57+
types=additional_types,
58+
)
59+
```
60+
61+
Roots of polymorphic hierarchies are also expected to be registered via
62+
`strawberry_sqlalchemy_mapper.interface()`, and its concrete type and
63+
its descendants are expected to inherit from the interface:
64+
65+
```
66+
class Book(Model):
67+
id = Column(UUID, primary_key=True)
68+
69+
class Novel(Book):
70+
pass
71+
72+
class ShortStory(Book):
73+
pass
74+
75+
76+
# in another file
77+
strawberry_sqlalchemy_mapper = StrawberrySQLAlchemyMapper()
78+
79+
@strawberry_sqlalchemy_mapper.interface(models.Book)
80+
class BookInterface:
81+
pass
82+
83+
@strawberry_sqlalchemy_mapper.type(models.Book)
84+
class Book:
85+
pass
86+
87+
@strawberry_sqlalchemy_mapper.type(models.Novel)
88+
class Novel:
89+
pass
90+
91+
@strawberry_sqlalchemy_mapper.type(models.ShortStory)
92+
class ShortStory:
93+
pass
4794
```
4895

4996
Several examples to help you get started are provided in the `examples` directory.
5097

5198
## Limitations
5299

100+
SQLAlchemy Models -> Strawberry Types and Interfaces are expected to have a consistent
101+
(customizable) naming convention. These can be configured by passing `model_to_type_name`
102+
and `model_to_interface_name` when constructing the mapper.
103+
53104
Natively supports the following SQLAlchemy types:
54105

55106
```python

0 commit comments

Comments
 (0)