Skip to content

Commit ac5690b

Browse files
committed
Update starwars model
1 parent 83103db commit ac5690b

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

models/starwars/src/model.rs

+24-21
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
11
use super::StarWars;
2-
use async_graphql::{Connection, Context, DataSource, EmptyEdgeFields, FieldResult};
2+
use async_graphql::{Connection, Context, Cursor, DataSource, EmptyEdgeFields, FieldResult};
33

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]
56
pub enum Episode {
6-
#[item(desc = "Released in 1977.")]
7+
/// Released in 1977.
78
NewHope,
89

9-
#[item(desc = "Released in 1980.")]
10+
/// Released in 1980.
1011
Empire,
1112

12-
#[item(desc = "Released in 1983.")]
13+
/// Released in 1983.
1314
Jedi,
1415
}
1516

1617
pub struct Human(usize);
1718

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]
1921
impl Human {
20-
#[field(desc = "The id of the human.")]
22+
/// The id of the human.
2123
async fn id(&self, ctx: &Context<'_>) -> &str {
2224
ctx.data::<StarWars>().chars[self.0].id
2325
}
2426

25-
#[field(desc = "The name of the human.")]
27+
/// The name of the human.
2628
async fn name(&self, ctx: &Context<'_>) -> &str {
2729
ctx.data::<StarWars>().chars[self.0].name
2830
}
2931

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.
3133
async fn friends(&self, ctx: &Context<'_>) -> Vec<Character> {
3234
ctx.data::<StarWars>().chars[self.0]
3335
.friends
@@ -36,32 +38,33 @@ impl Human {
3638
.collect()
3739
}
3840

39-
#[field(desc = "Which movies they appear in.")]
41+
/// Which movies they appear in.
4042
async fn appears_in<'a>(&self, ctx: &'a Context<'_>) -> &'a [Episode] {
4143
&ctx.data::<StarWars>().chars[self.0].appears_in
4244
}
4345

44-
#[field(desc = "The home planet of the human, or null if unknown.")]
46+
/// The home planet of the human, or null if unknown.
4547
async fn home_planet<'a>(&self, ctx: &'a Context<'_>) -> &'a Option<&'a str> {
4648
&ctx.data::<StarWars>().chars[self.0].home_planet
4749
}
4850
}
4951

5052
pub struct Droid(usize);
5153

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]
5356
impl Droid {
54-
#[field(desc = "The id of the droid.")]
57+
/// The id of the droid.
5558
async fn id(&self, ctx: &Context<'_>) -> &str {
5659
ctx.data::<StarWars>().chars[self.0].id
5760
}
5861

59-
#[field(desc = "The name of the droid.")]
62+
/// The name of the droid.
6063
async fn name(&self, ctx: &Context<'_>) -> &str {
6164
ctx.data::<StarWars>().chars[self.0].name
6265
}
6366

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.
6568
async fn friends(&self, ctx: &Context<'_>) -> Vec<Character> {
6669
ctx.data::<StarWars>().chars[self.0]
6770
.friends
@@ -70,12 +73,12 @@ impl Droid {
7073
.collect()
7174
}
7275

73-
#[field(desc = "Which movies they appear in.")]
76+
/// Which movies they appear in.
7477
async fn appears_in<'a>(&self, ctx: &'a Context<'_>) -> &'a [Episode] {
7578
&ctx.data::<StarWars>().chars[self.0].appears_in
7679
}
7780

78-
#[field(desc = "The primary function of the droid.")]
81+
/// The primary function of the droid.
7982
async fn primary_function<'a>(&self, ctx: &'a Context<'_>) -> &'a Option<&'a str> {
8083
&ctx.data::<StarWars>().chars[self.0].primary_function
8184
}
@@ -111,8 +114,8 @@ impl QueryRoot {
111114
async fn humans(
112115
&self,
113116
ctx: &Context<'_>,
114-
after: Option<String>,
115-
before: Option<String>,
117+
after: Option<Cursor>,
118+
before: Option<Cursor>,
116119
first: Option<i32>,
117120
last: Option<i32>,
118121
) -> FieldResult<Connection<Human, EmptyEdgeFields>> {
@@ -140,8 +143,8 @@ impl QueryRoot {
140143
async fn droids(
141144
&self,
142145
ctx: &Context<'_>,
143-
after: Option<String>,
144-
before: Option<String>,
146+
after: Option<Cursor>,
147+
before: Option<Cursor>,
145148
first: Option<i32>,
146149
last: Option<i32>,
147150
) -> FieldResult<Connection<Droid, EmptyEdgeFields>> {

0 commit comments

Comments
 (0)