Skip to content

Commit 36ac0d1

Browse files
committed
Made other documentation compatible with v2
1 parent 8b7c124 commit 36ac0d1

File tree

3 files changed

+54
-17
lines changed

3 files changed

+54
-17
lines changed

docs/examples.rst

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,32 @@ Schema Examples
33

44

55
Search all Models with Union
6-
-----------------
6+
----------------------------
77

88
.. code:: python
99
1010
class Book(SQLAlchemyObjectType):
1111
class Meta:
1212
model = BookModel
1313
interfaces = (relay.Node,)
14-
15-
14+
15+
16+
class BookConnection(relay.Connection):
17+
class Meta:
18+
node = Book
19+
20+
1621
class Author(SQLAlchemyObjectType):
1722
class Meta:
1823
model = AuthorModel
1924
interfaces = (relay.Node,)
2025
2126
27+
class AuthorConnection(relay.Connection):
28+
class Meta:
29+
node = Author
30+
31+
2232
class SearchResult(graphene.Union):
2333
class Meta:
2434
types = (Book, Author)
@@ -29,8 +39,8 @@ Search all Models with Union
2939
search = graphene.List(SearchResult, q=graphene.String()) # List field for search results
3040
3141
# Normal Fields
32-
all_books = SQLAlchemyConnectionField(Book)
33-
all_authors = SQLAlchemyConnectionField(Author)
42+
all_books = SQLAlchemyConnectionField(BookConnection)
43+
all_authors = SQLAlchemyConnectionField(AuthorConnection)
3444
3545
def resolve_search(self, info, **args):
3646
q = args.get("q") # Search query
@@ -47,13 +57,13 @@ Search all Models with Union
4757
# Query Authors
4858
authors = author_query.filter(AuthorModel.name.contains(q)).all()
4959
50-
return authors + books # Combine lists
60+
return authors + books # Combine lists
5161
5262
schema = graphene.Schema(query=Query, types=[Book, Author, SearchResult])
5363
5464
Example GraphQL query
5565

56-
.. code:: GraphQL
66+
.. code::
5767
5868
book(id: "Qm9vazow") {
5969
id

docs/tutorial.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,28 @@ Create ``flask_sqlalchemy/schema.py`` and type the following:
102102
interfaces = (relay.Node, )
103103
104104
105+
class DepartmentConnection(relay.Connection):
106+
class Meta:
107+
node = Department
108+
109+
105110
class Employee(SQLAlchemyObjectType):
106111
class Meta:
107112
model = EmployeeModel
108113
interfaces = (relay.Node, )
109114
110115
116+
class EmployeeConnection(relay.Connection):
117+
class Meta:
118+
node = Employee
119+
120+
111121
class Query(graphene.ObjectType):
112122
node = relay.Node.Field()
113-
all_employees = SQLAlchemyConnectionField(Employee)
123+
# Allows sorting over multiple columns, by default over the primary key
124+
all_employees = SQLAlchemyConnectionField(EmployeeConnection)
125+
# Disable sorting over this field
126+
all_departments = SQLAlchemyConnectionField(DepartmentConnection, sort=None)
114127
115128
schema = graphene.Schema(query=Query)
116129

examples/flask_sqlalchemy/schema.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,54 @@
77

88

99
class Department(SQLAlchemyObjectType):
10-
1110
class Meta:
1211
model = DepartmentModel
1312
interfaces = (relay.Node, )
1413

1514

16-
class Employee(SQLAlchemyObjectType):
15+
class DepartmentConnection(relay.Connection):
16+
class Meta:
17+
node = Department
1718

19+
20+
class Employee(SQLAlchemyObjectType):
1821
class Meta:
1922
model = EmployeeModel
2023
interfaces = (relay.Node, )
2124

2225

23-
class Role(SQLAlchemyObjectType):
26+
class EmployeeConnection(relay.Connection):
27+
class Meta:
28+
node = Employee
29+
2430

31+
class Role(SQLAlchemyObjectType):
2532
class Meta:
2633
model = RoleModel
2734
interfaces = (relay.Node, )
2835

2936

30-
SortEnumEmployee = utils.sort_enum_for_model(
31-
EmployeeModel, 'SortEnumEmployee',
37+
class RoleConnection(relay.Connection):
38+
class Meta:
39+
node = Role
40+
41+
42+
SortEnumEmployee = utils.sort_enum_for_model(EmployeeModel, 'SortEnumEmployee',
3243
lambda c, d: c.upper() + ('_ASC' if d else '_DESC'))
3344

3445

3546
class Query(graphene.ObjectType):
3647
node = relay.Node.Field()
3748
# Allow only single column sorting
38-
all_employees = SQLAlchemyConnectionField(Employee, sort=graphene.Argument(SortEnumEmployee,
49+
all_employees = SQLAlchemyConnectionField(
50+
EmployeeConnection,
51+
sort=graphene.Argument(
52+
SortEnumEmployee,
3953
default_value=utils.EnumValue('id_asc', EmployeeModel.id.asc())))
40-
# Add sort over multiple columns, sorting by default over the primary key
41-
all_roles = SQLAlchemyConnectionField(Role)
54+
# Allows sorting over multiple columns, by default over the primary key
55+
all_roles = SQLAlchemyConnectionField(RoleConnection)
4256
# Disable sorting over this field
43-
all_departments = SQLAlchemyConnectionField(Department, sort=None)
57+
all_departments = SQLAlchemyConnectionField(DepartmentConnection, sort=None)
4458

4559

4660
schema = graphene.Schema(query=Query, types=[Department, Employee, Role])

0 commit comments

Comments
 (0)