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

Add better filter error message for string instead of array. #461

Merged
merged 3 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions trustfall_core/src/graphql_query/directives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ impl TryFrom<&Positioned<Directive>> for FilterDirective {
{
let value_list = match &value_argument.node {
Value::List(list) => Ok(list),
Value::String(argument_value) => Err(ParseError::FilterExpectsListNotString(
op.to_owned(),
argument_value.to_owned(),
value_argument.pos,
)),
_ => Err(ParseError::InappropriateTypeForDirectiveArgument(
"@filter".to_owned(),
"value".to_owned(),
Expand Down
6 changes: 6 additions & 0 deletions trustfall_core/src/graphql_query/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ pub enum ParseError {
#[error("Directive {0} received value of inappropriate type for argument {1}")]
InappropriateTypeForDirectiveArgument(String, String, Pos),

#[error(
"Value argument in @filter directive is a string instead of a list. \
Did you mean to put '@filter(op: \"{0}\", value: [\"{1}\"])' instead?"
)]
FilterExpectsListNotString(String, String, Pos),

#[error("Field {0} received an invalid value for argument {1}: {2}")]
InvalidFieldArgument(String, String, Value, Pos),

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Err(FilterExpectsListNotString("=", "$zero", Pos(
line: 4,
column: 39,
)))
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
TestGraphQLQuery (
// The `value` in a filter expects an array with a single value instead of
// just a single value.
schema_name: "numbers",
query: r#"
{
Zero {
value @filter(op: "=", value: "$zero")
}
}"#,
arguments: {
"zero": Uint64(0)
},
)