Skip to content

Commit a7745e7

Browse files
committed
fix tests and precommit
1 parent bffc905 commit a7745e7

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ This will automatically add fields for the model's columns, relationships, assoc
3939
and hybrid properties. For example:
4040

4141
```python
42-
# in another file
42+
# elsewhere
4343
strawberry_sqlalchemy_mapper = StrawberrySQLAlchemyMapper()
4444
@strawberry_sqlalchemy_mapper.type(models.Employee)
4545
class Employee:
4646
pass
4747
```
4848

49+
Several examples to help you get started are provided in the `examples` directory.
50+
4951
## Limitations
5052

5153
Natively supports the following SQLAlchemy types:
@@ -76,7 +78,6 @@ although support for `TypeDecorator` types is untested.
7678
Association proxies are expected to be of the form `association_proxy('relationship1', 'relationship2')`,
7779
i.e., both properties are expected to be relationships.
7880

79-
8081
## Contributing
8182

8283
We encourage you to contribute to strawberry-sqlalchemy-mapper! Any contributions you make are greatly appreciated.

examples/flask/app.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Small self-contained Flask app to demonstrate basic strawberry-sqlalchemy-mapper use
2+
import strawberry
3+
from flask import Flask
4+
from sqlalchemy import Column, Integer, String
5+
from sqlalchemy.ext.declarative import declarative_base
6+
from strawberry.flask.views import GraphQLView
7+
8+
from strawberry_sqlalchemy_mapper import StrawberrySQLAlchemyMapper
9+
10+
Base = declarative_base()
11+
12+
13+
class Employee(Base):
14+
__tablename__ = "employee"
15+
id = Column(Integer, autoincrement=True, primary_key=True)
16+
name = Column(String, nullable=False)
17+
18+
19+
strawberry_sqlalchemy_mapper = StrawberrySQLAlchemyMapper()
20+
21+
22+
@strawberry_sqlalchemy_mapper.type(Employee)
23+
class Employee:
24+
pass
25+
26+
27+
@strawberry.type
28+
class EmployeeQuery:
29+
@strawberry.field
30+
def employee(self, id: str):
31+
return Employee(id=id, name="John Doe")
32+
33+
34+
app = Flask(__name__)
35+
36+
schema = strawberry.Schema(
37+
query=EmployeeQuery,
38+
)
39+
40+
app.add_url_rule(
41+
"/graphql",
42+
view_func=GraphQLView.as_view("graphql_view", schema=schema),
43+
)

0 commit comments

Comments
 (0)