Skip to content
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
2 changes: 1 addition & 1 deletion benches/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use graphql_parser::parse_query;

fn load_file(name: &str) -> String {
let mut buf = String::with_capacity(1024);
let path = format!("tests/samples/{}.graphql", name);
let path = format!("tests/queries/{}.graphql", name);
let mut f = File::open(&path).unwrap();
f.read_to_string(&mut buf).unwrap();
buf
Expand Down
12 changes: 12 additions & 0 deletions src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,15 @@ pub(crate) fn format_directives(dirs: &[Directive], f: &mut Formatter) {
dir.display(f);
}
}

macro_rules! impl_display {
($( $typ: ident, )+) => {
$(
impl fmt::Display for $typ {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&to_string(self))
}
}
)+
};
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ extern crate combine;


mod common;
#[macro_use]
mod format;
mod position;
mod tokenizer;
Expand Down
12 changes: 1 addition & 11 deletions src/query/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,17 +326,7 @@ impl Displayable for Directive {
}
}

macro_rules! impl_display {
($( $typ: ident, )+) => {
$(
impl fmt::Display for $typ {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&to_string(self))
}
}
)+
};
}

impl_display!(
Document,
Definition,
Expand Down
73 changes: 30 additions & 43 deletions src/schema/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ pub enum DirectiveLocation {
FragmentDefinition,
FragmentSpread,
InlineFragment,

// type_system
Schema,
Scalar,
Expand All @@ -212,7 +213,7 @@ pub struct DirectiveDefinition {
}

impl DirectiveLocation {
/// Returns graphql syntax compatible name of the directive
/// Returns GraphQL syntax compatible name of the directive
pub fn as_str(&self) -> &'static str {
use self::DirectiveLocation::*;
match *self {
Expand All @@ -236,53 +237,38 @@ impl DirectiveLocation {
InputFieldDefinition => "INPUT_FIELD_DEFINITION",
}
}
/// Returns true if this location is for queries (execution)

/// Returns `true` if this location is for queries (execution)
pub fn is_query(&self) -> bool {
use self::DirectiveLocation::*;
match *self {
Query => true,
Mutation => true,
Subscription => true,
Field => true,
FragmentDefinition => true,
FragmentSpread => true,
InlineFragment => true,
Schema => false,
Scalar => false,
Object => false,
FieldDefinition => false,
ArgumentDefinition => false,
Interface => false,
Union => false,
Enum => false,
EnumValue => false,
InputObject => false,
InputFieldDefinition => false,
Query
| Mutation
| Subscription
| Field
| FragmentDefinition
| FragmentSpread
| InlineFragment
=> true,

Schema
| Scalar
| Object
| FieldDefinition
| ArgumentDefinition
| Interface
| Union
| Enum
| EnumValue
| InputObject
| InputFieldDefinition
=> false,
}
}
/// Returns true if this location is for schema

/// Returns `true` if this location is for schema
pub fn is_schema(&self) -> bool {
use self::DirectiveLocation::*;
match *self {
Query => false,
Mutation => false,
Subscription => false,
Field => false,
FragmentDefinition => false,
FragmentSpread => false,
InlineFragment => false,
Schema => true,
Scalar => true,
Object => true,
FieldDefinition => true,
ArgumentDefinition => true,
Interface => true,
Union => true,
Enum => true,
EnumValue => true,
InputObject => true,
InputFieldDefinition => true,
}
!self.is_query()
}
}

Expand Down Expand Up @@ -317,6 +303,7 @@ impl FromStr for DirectiveLocation {
"INPUT_FIELD_DEFINITION" => InputFieldDefinition,
_ => return Err(InvalidDirectiveLocation),
};
return Ok(val);

Ok(val)
}
}
14 changes: 0 additions & 14 deletions src/schema/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,20 +388,6 @@ impl Displayable for DirectiveDefinition {
}
}



macro_rules! impl_display {
($( $typ: ident, )+) => {
$(
impl fmt::Display for $typ {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&to_string(self))
}
}
)+
};
}

impl_display!(
Document,
Definition,
Expand Down
5 changes: 3 additions & 2 deletions src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,15 @@ fn check_dec(value: &str) -> bool {
}

fn check_exp(value: &str) -> bool {
if value.len() == 0 {
if value.is_empty() {
return false;
}
let first = value.chars().next().unwrap();
if first != '-' && first != '+' && (first <= '0' || first >= '9') {
return false;
}
return value[1..].chars().all(|x| x >= '0' && x <= '9');

value[1..].chars().all(|x| x >= '0' && x <= '9')
}

fn check_float(value: &str, exponent: Option<usize>, real: Option<usize>)
Expand Down
2 changes: 1 addition & 1 deletion tests/query_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn test_error(filename: &str) {
let mut iter = buf.splitn(2, "\n---\n");
let graphql = iter.next().unwrap();
let expected = iter.next().expect("file should contain error message");
let err = parse_query(&graphql).unwrap_err();
let err = parse_query(graphql).unwrap_err();
assert_eq!(err.to_string(), expected);
}

Expand Down