Juniper: having a variable named 'args' in a function leads to weird error messages

Created on 14 Dec 2020  路  4Comments  路  Source: graphql-rust/juniper

I had a variable I'd named "args" in a function. It lead to a whole bunch of compile errors on an unrelated variable when the juniper::graphql_object macro was unpacked.

It would be nice to have an error message that detects reserved words in an argument list.

bug

All 4 comments

We should make these hermetic or mangle the names to make it work.

Do you happen to have a quick repro and the error message?

I had a function whose header was basically this:

[juniper::graphql_object(Context = Context)]

impl TestMutation {
async fn run_task_test(
context: &Context,
jobname: String,
taskname: String,
fsname: String,
args: String,
fidlist: Vec,
) -> juniper::FieldResult {
func(fidlist);
};
....

The errors were:

error[E0277]: the type str cannot be indexed by std::vec::Vec<std::string::String>
--> example.rs:57:1
|
57 | #[juniper::graphql_object(Context = Context)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string indices are ranges of usize
|
= help: the trait std::slice::SliceIndex<str> is not implemented for std::vec::Vec<std::string::String>
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0308]: mismatched types
--> example.rs:57:1
|
57 | #[juniper::graphql_object(Context = Context)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct std::vec::Vec, found &str
|
= note: expected struct std::vec::Vec<std::string::String>
found reference &鈥榮tatic str
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound &_: juniper::FromInputValue is not satisfied
--> example.rs:57:1
|
57 | #[juniper::graphql_object(Context = Context)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait juniper::FromInputValue is not implemented for &_
|
::: /root/.cargo/git/checkouts/juniper-aa5e857cd28538c7/6326acd/juniper/src/ast.rs:153:1
|
153 | pub trait FromInputValue: Sized {
| ------------------------------------------------------- required by this bound in juniper::FromInputValue::from_implicit_null
|
= help: the following implementations were found:
>
>
>
as juniper::FromInputValue>
and 27 others
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0277, E0308.
For more information about an error, try rustc --explain E0277.
error: could not compile example.

As you can see errors don't really point to "try renaming 'args'" as the solution.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

librelois picture librelois  路  3Comments

spacemeowx2 picture spacemeowx2  路  5Comments

MikailBag picture MikailBag  路  6Comments

projektir picture projektir  路  4Comments

norcalli picture norcalli  路  6Comments