Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix example for boxed-any #63

Merged
merged 1 commit into from
Dec 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions models/dynamic-starwars/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ pub fn schema() -> Result<Schema, SchemaError> {
FieldFuture::new(async move {
let starwars = ctx.data::<StarWars>()?;
let id = ctx.args.try_get("id")?;
Ok(starwars.human(id.string()?).map(FieldValue::borrowed_any))
Ok(starwars
.human(id.string()?)
.map(|v| FieldValue::borrowed_any(v)))
})
})
.argument(InputValue::new("id", TypeRef::named_nn(TypeRef::STRING))),
Expand All @@ -227,7 +229,7 @@ pub fn schema() -> Result<Schema, SchemaError> {
let starwars = ctx.data::<StarWars>()?;
let humans = starwars.humans();
Ok(Some(FieldValue::list(
humans.into_iter().map(FieldValue::borrowed_any),
humans.into_iter().map(|v| FieldValue::borrowed_any(v)),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should change borrowed_any(obj: &'a (impl Any + Send + Sync)) to borrowed_any(obj: &'a (impl Any + Send + Sync + ?Send)) to avoid this unnecessary map calls?

)))
})
},
Expand All @@ -237,7 +239,9 @@ pub fn schema() -> Result<Schema, SchemaError> {
FieldFuture::new(async move {
let starwars = ctx.data::<StarWars>()?;
let id = ctx.args.try_get("id")?;
Ok(starwars.droid(id.string()?).map(FieldValue::borrowed_any))
Ok(starwars
.droid(id.string()?)
.map(|v| FieldValue::borrowed_any(v)))
})
})
.argument(InputValue::new("id", TypeRef::named_nn(TypeRef::STRING))),
Expand All @@ -250,7 +254,7 @@ pub fn schema() -> Result<Schema, SchemaError> {
let starwars = ctx.data::<StarWars>()?;
let droids = starwars.droids();
Ok(Some(FieldValue::list(
droids.into_iter().map(FieldValue::borrowed_any),
droids.into_iter().map(|v| FieldValue::borrowed_any(v)),
)))
})
},
Expand Down