Skip to content

Commit 29e2231

Browse files
committed
Update to diesel changes
1 parent 1fc06e1 commit 29e2231

File tree

5 files changed

+42
-29
lines changed

5 files changed

+42
-29
lines changed

Cargo.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ members = [
88
]
99

1010
[replace]
11-
"diesel:1.3.2" = { git = "https://github.com/weiznich/diesel", rev = "a0e25315820290" }
12-
"diesel_migrations:1.3.0" = { git = "https://github.com/weiznich/diesel", rev = "a0e25315820290" }
13-
"migrations_internals:1.3.0" = { git = "https://github.com/weiznich/diesel", rev = "a0e25315820290" }
14-
"migrations_macros:1.3.0" = { git = "https://github.com/weiznich/diesel", rev = "a0e25315820290" }
15-
"diesel_derives:1.3.0" = { git = "https://github.com/weiznich/diesel", rev = "a0e25315820290" }
11+
"diesel:1.3.2" = { git = "https://github.com/weiznich/diesel", rev = "d4184dbb85ee" }
12+
"diesel_migrations:1.3.0" = { git = "https://github.com/weiznich/diesel", rev = "d4184dbb85ee" }
13+
"migrations_internals:1.3.0" = { git = "https://github.com/weiznich/diesel", rev = "d4184dbb85ee" }
14+
"migrations_macros:1.3.0" = { git = "https://github.com/weiznich/diesel", rev = "d4184dbb85ee" }
15+
"diesel_derives:1.3.0" = { git = "https://github.com/weiznich/diesel", rev = "d4184dbb85ee" }
1616
"juniper:0.9.2" = { git = "https://github.com/weiznich/juniper", rev = "15cfff0a78" }
1717
"juniper_codegen:0.9.2" = { git = "https://github.com/weiznich/juniper/", rev = "15cfff0a78" }

wundergraph/src/query_helper/has_one.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use helper::FromLookAheadValue;
77
use juniper::meta::MetaType;
88
use juniper::{
99
Arguments, ExecutionResult, Executor, FieldError, FromInputValue, GraphQLType, InputValue,
10-
Registry, Selection, ToInputValue, Value, LookAheadValue
10+
LookAheadValue, Registry, Selection, ToInputValue, Value,
1111
};
1212

1313
use std::hash::Hash;
@@ -31,6 +31,20 @@ where
3131
}
3232
}
3333

34+
impl<'a, K, I> Into<Option<&'a K>> for &'a HasOne<Option<K>, Option<I>>
35+
where
36+
&'a I: Identifiable<Id = &'a K>,
37+
K: Eq + Hash,
38+
{
39+
fn into(self) -> Option<&'a K> {
40+
match *self {
41+
HasOne::Id(Some(ref k)) => Some(k),
42+
HasOne::Item(Some(ref i)) => Some(i.id()),
43+
HasOne::Id(None) | HasOne::Item(None) => None,
44+
}
45+
}
46+
}
47+
3448
impl<R, T> FromInputValue for HasOne<R, T>
3549
where
3650
R: FromInputValue,

wundergraph_derive/src/filter.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@ pub fn derive(item: &syn::DeriveInput) -> Result<TokenStream, Diagnostic> {
2525
if f.has_flag("skip") {
2626
None
2727
} else if is_has_one(field_ty) {
28-
let reference_ty = if is_option_ty(field_ty) {
29-
quote!(self::wundergraph::filter::NullableReferenceFilter)
30-
} else {
31-
quote!(self::wundergraph::filter::ReferenceFilter)
32-
};
28+
let reference_ty =
29+
if is_option_ty(inner_ty_arg(field_ty, "HasOne", 1).expect("It's there")) {
30+
quote!(self::wundergraph::filter::NullableReferenceFilter)
31+
} else {
32+
quote!(self::wundergraph::filter::ReferenceFilter)
33+
};
3334
let remote_table = f.remote_table().map(|t| quote!(#t::table)).unwrap_or_else(
3435
|_| {
35-
let remote_type = inner_ty_arg(inner_of_option_ty(&f.ty), "HasOne", 1)
36-
.expect("It's HasOne");
36+
let remote_type = inner_of_option_ty(
37+
inner_ty_arg(&f.ty, "HasOne", 1).expect("It's HasOne"),
38+
);
3739
quote!{
3840
<#remote_type as diesel::associations::HasTable>::Table
3941
}

wundergraph_derive/src/wundergraph_entity.rs

+12-15
Original file line numberDiff line numberDiff line change
@@ -255,18 +255,15 @@ fn handle_has_one(
255255
.remote_table()
256256
.map(|t| quote!(#t::table))
257257
.unwrap_or_else(|_| {
258-
let remote_type = inner_of_option_ty(
259-
inner_ty_arg(inner_of_option_ty(&f.ty), "HasOne", 1)
260-
.expect("It's HasOne"),
261-
);
258+
let remote_type = inner_of_option_ty(inner_of_option_ty(
259+
inner_ty_arg(&f.ty, "HasOne", 1).expect("It's HasOne"),
260+
));
262261
quote!{
263262
<#remote_type as diesel::associations::HasTable>::Table
264263
}
265264
});
266-
let map_fn = if is_option_ty(&f.ty) {
267-
quote!(filter_map(|i| i#field_access.as_ref().map(|g| {
268-
g.expect_id("Id is there").clone()
269-
})))
265+
let map_fn = if is_option_ty(inner_ty_arg(&f.ty, "HasOne", 1).expect("Is HasOne")) {
266+
quote!(filter_map(|i| i#field_access.expect_id("Id is there").clone()))
270267
} else {
271268
quote!(map(|i| i#field_access.expect_id("Id is there").clone()))
272269
};
@@ -277,20 +274,20 @@ fn handle_has_one(
277274
.#map_fn
278275
.collect::<self::std::collections::HashSet<_>>();
279276
};
280-
let lookup_and_assign = if is_option_ty(&f.ty) {
277+
let lookup_and_assign = if is_option_ty(
278+
inner_ty_arg(&f.ty, "HasOne", 1).expect("It's there"),
279+
) {
281280
quote!{
282281
if let std::option::Option::Some(id)
283-
= i#field_access.as_ref().map(|g| {
284-
g.expect_id("Id is there").clone()
285-
})
282+
= i#field_access.expect_id("Id is there").clone()
286283
{
287284
if let std::option::Option::Some(c) = items.get(&id).cloned() {
288-
i#field_access = std::option::Option::Some(
289-
self::wundergraph::query_helper::HasOne::Item(c)
285+
i#field_access = self::wundergraph::query_helper::HasOne::Item(
286+
std::option::Option::Some(c)
290287
);
291288
}
292289
} else {
293-
i#field_access = std::option::Option::None;
290+
i#field_access = self::wundergraph::query_helper::HasOne::Item(std::option::Option::None);
294291
}
295292
}
296293
} else {

wundergraph_example/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ mod hero {
257257
/// Which species a hero belongs to
258258
species: HasOne<i32, Species>,
259259
/// On which world a hero was born
260-
home_world: Option<HasOne<i32, HomeWorld>>,
260+
home_world: HasOne<Option<i32>, Option<HomeWorld>>,
261261
/// Episodes a hero appears in
262262
appears_in: HasMany<AppearsIn>,
263263
/// List of friends of the current hero

0 commit comments

Comments
 (0)