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

Check strings for matching enum variants which can be passed in from variables #14

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
19 changes: 19 additions & 0 deletions crates/planner/tests/enum_variable.txt
Original file line number Diff line number Diff line change
@@ -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 } }"
}
6 changes: 6 additions & 0 deletions crates/planner/tests/test.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 15 additions & 5 deletions crates/validation/src/utils.rs
Original file line number Diff line number Diff line change
@@ -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> {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)))
Expand Down