Skip to content

Commit 4c5b4d1

Browse files
authored
[documentation] Fix Connection patterns (#264)
1 parent 6dca279 commit 4c5b4d1

File tree

9 files changed

+27
-68
lines changed

9 files changed

+27
-68
lines changed

Diff for: docs/examples.rst

+2-12
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,12 @@ Search all Models with Union
1313
interfaces = (relay.Node,)
1414
1515
16-
class BookConnection(relay.Connection):
17-
class Meta:
18-
node = Book
19-
20-
2116
class Author(SQLAlchemyObjectType):
2217
class Meta:
2318
model = AuthorModel
2419
interfaces = (relay.Node,)
2520
2621
27-
class AuthorConnection(relay.Connection):
28-
class Meta:
29-
node = Author
30-
31-
3222
class SearchResult(graphene.Union):
3323
class Meta:
3424
types = (Book, Author)
@@ -39,8 +29,8 @@ Search all Models with Union
3929
search = graphene.List(SearchResult, q=graphene.String()) # List field for search results
4030
4131
# Normal Fields
42-
all_books = SQLAlchemyConnectionField(BookConnection)
43-
all_authors = SQLAlchemyConnectionField(AuthorConnection)
32+
all_books = SQLAlchemyConnectionField(Book.connection)
33+
all_authors = SQLAlchemyConnectionField(Author.connection)
4434
4535
def resolve_search(self, info, **args):
4636
q = args.get("q") # Search query

Diff for: docs/tips.rst

+1-6
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,8 @@ Given the model
5050
model = Pet
5151
5252
53-
class PetConnection(Connection):
54-
class Meta:
55-
node = PetNode
56-
57-
5853
class Query(ObjectType):
59-
allPets = SQLAlchemyConnectionField(PetConnection)
54+
allPets = SQLAlchemyConnectionField(PetNode.connection)
6055
6156
some of the allowed queries are
6257

Diff for: docs/tutorial.rst

+2-12
Original file line numberDiff line numberDiff line change
@@ -102,28 +102,18 @@ 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-
110105
class Employee(SQLAlchemyObjectType):
111106
class Meta:
112107
model = EmployeeModel
113108
interfaces = (relay.Node, )
114109
115110
116-
class EmployeeConnection(relay.Connection):
117-
class Meta:
118-
node = Employee
119-
120-
121111
class Query(graphene.ObjectType):
122112
node = relay.Node.Field()
123113
# Allows sorting over multiple columns, by default over the primary key
124-
all_employees = SQLAlchemyConnectionField(EmployeeConnection)
114+
all_employees = SQLAlchemyConnectionField(Employee.connection)
125115
# Disable sorting over this field
126-
all_departments = SQLAlchemyConnectionField(DepartmentConnection, sort=None)
116+
all_departments = SQLAlchemyConnectionField(Department.connection, sort=None)
127117
128118
schema = graphene.Schema(query=Query)
129119

Diff for: examples/flask_sqlalchemy/schema.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ class Query(graphene.ObjectType):
2929
node = relay.Node.Field()
3030
# Allow only single column sorting
3131
all_employees = SQLAlchemyConnectionField(
32-
Employee, sort=Employee.sort_argument())
32+
Employee.connection, sort=Employee.sort_argument())
3333
# Allows sorting over multiple columns, by default over the primary key
34-
all_roles = SQLAlchemyConnectionField(Role)
34+
all_roles = SQLAlchemyConnectionField(Role.connection)
3535
# Disable sorting over this field
36-
all_departments = SQLAlchemyConnectionField(Department, sort=None)
36+
all_departments = SQLAlchemyConnectionField(Department.connection, sort=None)
3737

3838

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

Diff for: examples/nameko_sqlalchemy/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ Now the following command will setup the database, and start the server:
4646

4747
```bash
4848
./run.sh
49-
5049
```
5150

5251
Now head on over to postman and send POST request to:

Diff for: examples/nameko_sqlalchemy/database.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def init_db():
1414
# import all modules here that might define models so that
1515
# they will be registered properly on the metadata. Otherwise
1616
# you will have to import them first before calling init_db()
17-
from .models import Department, Employee, Role
17+
from models import Department, Employee, Role
1818
Base.metadata.drop_all(bind=engine)
1919
Base.metadata.create_all(bind=engine)
2020

Diff for: examples/nameko_sqlalchemy/schema.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,28 @@
88

99

1010
class Department(SQLAlchemyObjectType):
11-
1211
class Meta:
1312
model = DepartmentModel
14-
interfaces = (relay.Node, )
13+
interfaces = (relay.Node,)
1514

1615

1716
class Employee(SQLAlchemyObjectType):
18-
1917
class Meta:
2018
model = EmployeeModel
21-
interfaces = (relay.Node, )
19+
interfaces = (relay.Node,)
2220

2321

2422
class Role(SQLAlchemyObjectType):
25-
2623
class Meta:
2724
model = RoleModel
28-
interfaces = (relay.Node, )
25+
interfaces = (relay.Node,)
2926

3027

3128
class Query(graphene.ObjectType):
3229
node = relay.Node.Field()
33-
all_employees = SQLAlchemyConnectionField(Employee)
34-
all_roles = SQLAlchemyConnectionField(Role)
30+
all_employees = SQLAlchemyConnectionField(Employee.connection)
31+
all_roles = SQLAlchemyConnectionField(Role.connection)
3532
role = graphene.Field(Role)
3633

3734

38-
schema = graphene.Schema(query=Query, types=[Department, Employee, Role])
35+
schema = graphene.Schema(query=Query)

Diff for: graphene_sqlalchemy/tests/test_query.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import graphene
2-
from graphene.relay import Connection, Node
2+
from graphene.relay import Node
33

44
from ..converter import convert_sqlalchemy_composite
55
from ..fields import SQLAlchemyConnectionField
@@ -96,14 +96,10 @@ class Meta:
9696
model = Article
9797
interfaces = (Node,)
9898

99-
class ArticleConnection(Connection):
100-
class Meta:
101-
node = ArticleNode
102-
10399
class Query(graphene.ObjectType):
104100
node = Node.Field()
105101
reporter = graphene.Field(ReporterNode)
106-
all_articles = SQLAlchemyConnectionField(ArticleConnection)
102+
all_articles = SQLAlchemyConnectionField(ArticleNode.connection)
107103

108104
def resolve_reporter(self, _info):
109105
return session.query(Reporter).first()
@@ -230,13 +226,9 @@ class Meta:
230226
model = Editor
231227
interfaces = (Node,)
232228

233-
class EditorConnection(Connection):
234-
class Meta:
235-
node = EditorNode
236-
237229
class Query(graphene.ObjectType):
238230
node = Node.Field()
239-
all_editors = SQLAlchemyConnectionField(EditorConnection)
231+
all_editors = SQLAlchemyConnectionField(EditorNode.connection)
240232

241233
query = """
242234
query {

Diff for: graphene_sqlalchemy/tests/test_sort_enums.py

+8-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sqlalchemy as sa
33

44
from graphene import Argument, Enum, List, ObjectType, Schema
5-
from graphene.relay import Connection, Node
5+
from graphene.relay import Node
66

77
from ..fields import SQLAlchemyConnectionField
88
from ..types import SQLAlchemyObjectType
@@ -249,22 +249,18 @@ class Meta:
249249
model = Pet
250250
interfaces = (Node,)
251251

252-
class PetConnection(Connection):
253-
class Meta:
254-
node = PetNode
255-
256252
class Query(ObjectType):
257-
defaultSort = SQLAlchemyConnectionField(PetConnection)
258-
nameSort = SQLAlchemyConnectionField(PetConnection)
259-
multipleSort = SQLAlchemyConnectionField(PetConnection)
260-
descSort = SQLAlchemyConnectionField(PetConnection)
253+
defaultSort = SQLAlchemyConnectionField(PetNode.connection)
254+
nameSort = SQLAlchemyConnectionField(PetNode.connection)
255+
multipleSort = SQLAlchemyConnectionField(PetNode.connection)
256+
descSort = SQLAlchemyConnectionField(PetNode.connection)
261257
singleColumnSort = SQLAlchemyConnectionField(
262-
PetConnection, sort=Argument(PetNode.sort_enum())
258+
PetNode.connection, sort=Argument(PetNode.sort_enum())
263259
)
264260
noDefaultSort = SQLAlchemyConnectionField(
265-
PetConnection, sort=PetNode.sort_argument(has_default=False)
261+
PetNode.connection, sort=PetNode.sort_argument(has_default=False)
266262
)
267-
noSort = SQLAlchemyConnectionField(PetConnection, sort=None)
263+
noSort = SQLAlchemyConnectionField(PetNode.connection, sort=None)
268264

269265
query = """
270266
query sortTest {

0 commit comments

Comments
 (0)