File tree Expand file tree Collapse file tree 1 file changed +55
-3
lines changed Expand file tree Collapse file tree 1 file changed +55
-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,58 @@ 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
+ class PetNode (SQLAlchemyObjectType ):
48
+ class Meta :
49
+ model = Pet
50
+
51
+ class PetConnection (Connection ):
52
+ class Meta :
53
+ node = PetNone
54
+
55
+ class Query (ObjectType ):
56
+ allPets = SQLAlchemyConnectionField(PetConnection)
57
+
58
+ some of the allowed queries are
59
+
60
+ - Sort in ascending order over the `name ` column
61
+
62
+ .. code ::
63
+
64
+ allPets(sort: name_asc){
65
+ edges {
66
+ node {
67
+ name
68
+ }
69
+ }
70
+ }
71
+
72
+ - Sort in descending order over the `per_kind ` column and in ascending order over the `name ` column
73
+
74
+ .. code ::
75
+
76
+ allPets(sort: [pet_kind_desc, name_asc]) {
77
+ edges {
78
+ node {
79
+ name
80
+ petKind
81
+ }
82
+ }
83
+ }
84
+
You can’t perform that action at this time.
0 commit comments