File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -44,12 +44,63 @@ strawberry_sqlalchemy_mapper = StrawberrySQLAlchemyMapper()
44
44
@strawberry_sqlalchemy_mapper.type (models.Employee)
45
45
class Employee :
46
46
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
47
94
```
48
95
49
96
Several examples to help you get started are provided in the ` examples ` directory.
50
97
51
98
## Limitations
52
99
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
+
53
104
Natively supports the following SQLAlchemy types:
54
105
55
106
``` python
You can’t perform that action at this time.
0 commit comments