Skip to content

Commit 64b895c

Browse files
committed
Make project compile
With juniper, you can either the derive or the proc macro, *not both*. See graphql-rust/juniper#553 for some discussion as to why.
1 parent 62140c0 commit 64b895c

File tree

1 file changed

+54
-21
lines changed

1 file changed

+54
-21
lines changed

src/schema.rs

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use chrono::NaiveDate;
2-
use juniper::{FieldResult, RootNode, EmptySubscription, Context as JuniperContext};
2+
use juniper::{Context as JuniperContext, EmptySubscription, FieldResult, RootNode};
33
use std::sync::Arc;
44
use tokio_postgres::Client;
55
use uuid::Uuid;
@@ -13,14 +13,13 @@ pub struct Context {
1313
impl Context {
1414
pub fn with(client: &Arc<Client>) -> Context {
1515
Context {
16-
client: Arc::clone(client)
16+
client: Arc::clone(client),
1717
}
1818
}
1919
}
2020

2121
impl JuniperContext for Context {}
2222

23-
#[derive(GraphQLObject)]
2423
pub struct Member {
2524
pub id: String,
2625
pub email: String,
@@ -31,13 +30,29 @@ pub struct Member {
3130

3231
#[graphql_object(Context = Context)]
3332
impl Member {
34-
pub async fn rides(&self) -> FieldResult<Vec<Ride>> {
35-
let context: &Context = executor.context();
36-
37-
let rows = context.client.query(
38-
"SELECT id, name, description, distance, started, ended FROM ride WHERE rider = $1",
39-
&[&self.id],
40-
).await?;
33+
fn id(&self) -> &str {
34+
&self.id
35+
}
36+
fn email(&self) -> &str {
37+
&self.email
38+
}
39+
fn firstname(&self) -> &str {
40+
&self.firstname
41+
}
42+
fn lastname(&self) -> &str {
43+
&self.firstname
44+
}
45+
fn birthdate(&self) -> NaiveDate {
46+
self.birthdate
47+
}
48+
async fn rides(&self, context: &Context) -> FieldResult<Vec<Ride>> {
49+
let rows = context
50+
.client
51+
.query(
52+
"SELECT id, name, description, distance, started, ended FROM ride WHERE rider = $1",
53+
&[&self.id],
54+
)
55+
.await?;
4156

4257
let mut rides: Vec<Ride> = Vec::with_capacity(rows.len());
4358

@@ -73,10 +88,13 @@ impl QueryRoot {
7388
async fn member(ctx: &Context, id: String) -> FieldResult<Member> {
7489
let uuid = Uuid::parse_str(&id)?;
7590

76-
let row = ctx.client.query_one(
77-
"SELECT email, firstname, lastname, birthdate FROM member WHERE id = $1",
78-
&[&uuid],
79-
).await?;
91+
let row = ctx
92+
.client
93+
.query_one(
94+
"SELECT email, firstname, lastname, birthdate FROM member WHERE id = $1",
95+
&[&uuid],
96+
)
97+
.await?;
8098

8199
let member = Member {
82100
id,
@@ -90,10 +108,13 @@ impl QueryRoot {
90108
}
91109

92110
async fn members(ctx: &Context) -> FieldResult<Vec<Member>> {
93-
let rows = ctx.client.query(
94-
"SELECT id, email, firstname, lastname, birthdate FROM member",
95-
&[],
96-
).await?;
111+
let rows = ctx
112+
.client
113+
.query(
114+
"SELECT id, email, firstname, lastname, birthdate FROM member",
115+
&[],
116+
)
117+
.await?;
97118

98119
let mut members = Vec::new();
99120

@@ -117,7 +138,13 @@ pub struct MutationRoot;
117138

118139
#[graphql_object(Context = Context)]
119140
impl MutationRoot {
120-
async fn register_member(ctx: &Context, email: String, firstname: String, lastname: String, birthdate: NaiveDate) -> FieldResult<Member> {
141+
async fn register_member(
142+
ctx: &Context,
143+
email: String,
144+
firstname: String,
145+
lastname: String,
146+
birthdate: NaiveDate,
147+
) -> FieldResult<Member> {
121148
let id = Uuid::new_v4();
122149
let email = email.to_lowercase();
123150

@@ -135,7 +162,14 @@ impl MutationRoot {
135162
})
136163
}
137164

138-
async fn register_ride(ctx: &Context, rider: String, name: String, description: String, started: NaiveDate, ended: NaiveDate) -> FieldResult<Ride> {
165+
async fn register_ride(
166+
ctx: &Context,
167+
rider: String,
168+
name: String,
169+
description: String,
170+
started: NaiveDate,
171+
ended: NaiveDate,
172+
) -> FieldResult<Ride> {
139173
let id = Uuid::new_v4();
140174

141175
ctx.client.execute(
@@ -153,4 +187,3 @@ impl MutationRoot {
153187
})
154188
}
155189
}
156-

0 commit comments

Comments
 (0)