diff --git a/crates/planner/tests/enum_variable.txt b/crates/planner/tests/enum_variable.txt new file mode 100644 index 0000000..293cf47 --- /dev/null +++ b/crates/planner/tests/enum_variable.txt @@ -0,0 +1,19 @@ +query($sortOrder: UserSortOrder!){ + users(sortOrder: $sortOrder) { + id + username + } +} +--- +{ + "sortOrder": "CREATED_AT" +} +--- +{ + "type": "fetch", + "service": "accounts", + "variables": { + "sortOrder": "CREATED_AT" + }, + "query": "query($sortOrder: UserSortOrder!) { users(sortOrder: $sortOrder) { id username } }" +} diff --git a/crates/planner/tests/test.graphql b/crates/planner/tests/test.graphql index 66b49b4..55f0720 100644 --- a/crates/planner/tests/test.graphql +++ b/crates/planner/tests/test.graphql @@ -24,6 +24,12 @@ type Query { user(id: ID!): User @resolve(service: "accounts") topProducts: [Product!]! @resolve(service: "products") node(id: ID!): Node @resolve(service: "accounts") + users(sortOrder: UserSortOrder!): [User!]! @resolve(service: "accounts") +} + +enum UserSortOrder { + NAME + CREATED_AT } type Mutation { diff --git a/crates/validation/src/utils.rs b/crates/validation/src/utils.rs index b811c8b..486e0d8 100644 --- a/crates/validation/src/utils.rs +++ b/crates/validation/src/utils.rs @@ -1,9 +1,8 @@ -use std::collections::HashSet; -use std::fmt::{Display, Formatter, Result as FmtResult}; - use graphgate_schema::{ComposedSchema, TypeKind}; use parser::types::{BaseType, Type}; -use value::ConstValue; +use std::collections::HashSet; +use std::fmt::{Display, Formatter, Result as FmtResult}; +use value::{ConstValue, Name}; #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Scope<'a> { @@ -117,6 +116,18 @@ pub fn is_valid_input_value( } else { None } + } else if let ConstValue::String(v) = value { + if ty.enum_values.contains_key(&Name::new(v.to_string())) { + None + } else { + Some(valid_error( + &path_node, + format!( + "enumeration type \"{}\" does not contain the value \"{}\"", + ty.name, value + ) + )) + } } else { Some(valid_error( &path_node, @@ -176,7 +187,6 @@ pub fn is_valid_input_value( } } } - if !ty.nullable { if matches!(value, ConstValue::Null) { Some(valid_error(&path_node, format!("expected type \"{}\"", ty)))