File tree Expand file tree Collapse file tree 1 file changed +58
-3
lines changed Expand file tree Collapse file tree 1 file changed +58
-3
lines changed Original file line number Diff line number Diff line change 2
2
Tips
3
3
====
4
4
5
- Tips
6
- ====
7
-
8
5
Querying
9
6
--------
10
7
@@ -30,3 +27,61 @@ For make querying to the database work, there are two alternatives:
30
27
If you don't specify any, the following error will be displayed:
31
28
32
29
``A query in the model Base or a session in the schema is required for querying. ``
30
+
31
+ Sorting
32
+ -------
33
+
34
+ By default the SQLAlchemyConnectionField sorts the result elements over the primary key(s).
35
+ The query has a `sort ` argument which allows to sort over a different column(s)
36
+
37
+ Given the model
38
+
39
+ .. code :: python
40
+
41
+ class Pet (Base ):
42
+ __tablename__ = ' pets'
43
+ id = Column(Integer(), primary_key = True )
44
+ name = Column(String(30 ))
45
+ pet_kind = Column(Enum(' cat' , ' dog' , name = ' pet_kind' ), nullable = False )
46
+
47
+
48
+ class PetNode (SQLAlchemyObjectType ):
49
+ class Meta :
50
+ model = Pet
51
+
52
+
53
+ class PetConnection (Connection ):
54
+ class Meta :
55
+ node = PetNone
56
+
57
+
58
+ class Query (ObjectType ):
59
+ allPets = SQLAlchemyConnectionField(PetConnection)
60
+
61
+ some of the allowed queries are
62
+
63
+ - Sort in ascending order over the `name ` column
64
+
65
+ .. code ::
66
+
67
+ allPets(sort: name_asc){
68
+ edges {
69
+ node {
70
+ name
71
+ }
72
+ }
73
+ }
74
+
75
+ - Sort in descending order over the `per_kind ` column and in ascending order over the `name ` column
76
+
77
+ .. code ::
78
+
79
+ allPets(sort: [pet_kind_desc, name_asc]) {
80
+ edges {
81
+ node {
82
+ name
83
+ petKind
84
+ }
85
+ }
86
+ }
87
+
You can’t perform that action at this time.
0 commit comments