1
1
use super :: StarWars ;
2
- use async_graphql:: { Connection , Context , DataSource , EmptyEdgeFields , FieldResult } ;
2
+ use async_graphql:: { Connection , Context , Cursor , DataSource , EmptyEdgeFields , FieldResult } ;
3
3
4
- #[ async_graphql:: Enum ( desc = "One of the films in the Star Wars Trilogy" ) ]
4
+ /// One of the films in the Star Wars Trilogy
5
+ #[ async_graphql:: Enum ]
5
6
pub enum Episode {
6
- # [ item ( desc = " Released in 1977." ) ]
7
+ /// Released in 1977.
7
8
NewHope ,
8
9
9
- # [ item ( desc = " Released in 1980." ) ]
10
+ /// Released in 1980.
10
11
Empire ,
11
12
12
- # [ item ( desc = " Released in 1983." ) ]
13
+ /// Released in 1983.
13
14
Jedi ,
14
15
}
15
16
16
17
pub struct Human ( usize ) ;
17
18
18
- #[ async_graphql:: Object ( desc = "A humanoid creature in the Star Wars universe." ) ]
19
+ /// A humanoid creature in the Star Wars universe.
20
+ #[ async_graphql:: Object ]
19
21
impl Human {
20
- # [ field ( desc = " The id of the human." ) ]
22
+ /// The id of the human.
21
23
async fn id ( & self , ctx : & Context < ' _ > ) -> & str {
22
24
ctx. data :: < StarWars > ( ) . chars [ self . 0 ] . id
23
25
}
24
26
25
- # [ field ( desc = " The name of the human." ) ]
27
+ /// The name of the human.
26
28
async fn name ( & self , ctx : & Context < ' _ > ) -> & str {
27
29
ctx. data :: < StarWars > ( ) . chars [ self . 0 ] . name
28
30
}
29
31
30
- # [ field ( desc = " The friends of the human, or an empty list if they have none." ) ]
32
+ /// The friends of the human, or an empty list if they have none.
31
33
async fn friends ( & self , ctx : & Context < ' _ > ) -> Vec < Character > {
32
34
ctx. data :: < StarWars > ( ) . chars [ self . 0 ]
33
35
. friends
@@ -36,32 +38,33 @@ impl Human {
36
38
. collect ( )
37
39
}
38
40
39
- # [ field ( desc = " Which movies they appear in." ) ]
41
+ /// Which movies they appear in.
40
42
async fn appears_in < ' a > ( & self , ctx : & ' a Context < ' _ > ) -> & ' a [ Episode ] {
41
43
& ctx. data :: < StarWars > ( ) . chars [ self . 0 ] . appears_in
42
44
}
43
45
44
- # [ field ( desc = " The home planet of the human, or null if unknown." ) ]
46
+ /// The home planet of the human, or null if unknown.
45
47
async fn home_planet < ' a > ( & self , ctx : & ' a Context < ' _ > ) -> & ' a Option < & ' a str > {
46
48
& ctx. data :: < StarWars > ( ) . chars [ self . 0 ] . home_planet
47
49
}
48
50
}
49
51
50
52
pub struct Droid ( usize ) ;
51
53
52
- #[ async_graphql:: Object ( desc = "A mechanical creature in the Star Wars universe." ) ]
54
+ /// A mechanical creature in the Star Wars universe.
55
+ #[ async_graphql:: Object ]
53
56
impl Droid {
54
- # [ field ( desc = " The id of the droid." ) ]
57
+ /// The id of the droid.
55
58
async fn id ( & self , ctx : & Context < ' _ > ) -> & str {
56
59
ctx. data :: < StarWars > ( ) . chars [ self . 0 ] . id
57
60
}
58
61
59
- # [ field ( desc = " The name of the droid." ) ]
62
+ /// The name of the droid.
60
63
async fn name ( & self , ctx : & Context < ' _ > ) -> & str {
61
64
ctx. data :: < StarWars > ( ) . chars [ self . 0 ] . name
62
65
}
63
66
64
- # [ field ( desc = " The friends of the droid, or an empty list if they have none." ) ]
67
+ /// The friends of the droid, or an empty list if they have none.
65
68
async fn friends ( & self , ctx : & Context < ' _ > ) -> Vec < Character > {
66
69
ctx. data :: < StarWars > ( ) . chars [ self . 0 ]
67
70
. friends
@@ -70,12 +73,12 @@ impl Droid {
70
73
. collect ( )
71
74
}
72
75
73
- # [ field ( desc = " Which movies they appear in." ) ]
76
+ /// Which movies they appear in.
74
77
async fn appears_in < ' a > ( & self , ctx : & ' a Context < ' _ > ) -> & ' a [ Episode ] {
75
78
& ctx. data :: < StarWars > ( ) . chars [ self . 0 ] . appears_in
76
79
}
77
80
78
- # [ field ( desc = " The primary function of the droid." ) ]
81
+ /// The primary function of the droid.
79
82
async fn primary_function < ' a > ( & self , ctx : & ' a Context < ' _ > ) -> & ' a Option < & ' a str > {
80
83
& ctx. data :: < StarWars > ( ) . chars [ self . 0 ] . primary_function
81
84
}
@@ -111,8 +114,8 @@ impl QueryRoot {
111
114
async fn humans (
112
115
& self ,
113
116
ctx : & Context < ' _ > ,
114
- after : Option < String > ,
115
- before : Option < String > ,
117
+ after : Option < Cursor > ,
118
+ before : Option < Cursor > ,
116
119
first : Option < i32 > ,
117
120
last : Option < i32 > ,
118
121
) -> FieldResult < Connection < Human , EmptyEdgeFields > > {
@@ -140,8 +143,8 @@ impl QueryRoot {
140
143
async fn droids (
141
144
& self ,
142
145
ctx : & Context < ' _ > ,
143
- after : Option < String > ,
144
- before : Option < String > ,
146
+ after : Option < Cursor > ,
147
+ before : Option < Cursor > ,
145
148
first : Option < i32 > ,
146
149
last : Option < i32 > ,
147
150
) -> FieldResult < Connection < Droid , EmptyEdgeFields > > {
0 commit comments