File tree Expand file tree Collapse file tree 1 file changed +4
-7
lines changed
docs/book/content/types/objects Expand file tree Collapse file tree 1 file changed +4
-7
lines changed Original file line number Diff line number Diff line change @@ -105,24 +105,21 @@ struct Database {
105
105
requested_count : HashMap <i32 , i32 >,
106
106
}
107
107
108
- impl juniper :: Context for Database {}
109
-
110
108
struct User {
111
109
id : i32 ,
112
- name : String ,
113
- times_requested : i32 ,
110
+ name : String
114
111
}
115
112
116
- #[graphql_object(context = RwLock <Database >)]
113
+ #[graphql_object(context= RwLock <Database >)]
117
114
impl User {
118
- async fn times_requested <'db >(& self , context : & 'db RwLock <Database >) -> Vec < & ' db User > {
115
+ async fn times_requested <'db >(& self , context : & 'db RwLock <Database >) -> i32 {
119
116
// Acquire a mutable reference and await if async RwLock is used,
120
117
// which is necessary if context consists async operations like
121
118
// querying remote databases.
122
119
// If context is immutable use .read() on RwLock.
123
120
let mut context = context . write (). await ;
124
121
// Preform a mutable operation.
125
- context . requested_count. entry (self . id). and_modify (| e | { * e += 1 }). or_insert (1 )
122
+ context . requested_count. entry (self . id). and_modify (| e | { * e += 1 }). or_insert (1 ). clone ()
126
123
}
127
124
128
125
fn name (& self ) -> & str {
You can’t perform that action at this time.
0 commit comments