diff --git a/cynic-parser/benches/executable.rs b/cynic-parser/benches/executable.rs index 2ef8faff2..7bb3456bb 100644 --- a/cynic-parser/benches/executable.rs +++ b/cynic-parser/benches/executable.rs @@ -1,39 +1,72 @@ -use divan::AllocProfiler; - -#[global_allocator] -static ALLOC: AllocProfiler = AllocProfiler::system(); +// use divan::AllocProfiler; +// #[global_allocator] +// static ALLOC: AllocProfiler = AllocProfiler::system(); fn main() { // Run registered benchmarks. divan::main(); } -const QUERY: &str = include_str!("../tests/executables/kitchen-sink.graphql"); +mod kitchen_sink { + const QUERY: &str = include_str!("../tests/executables/kitchen-sink.graphql"); -#[divan::bench] -fn cynic_parser() -> cynic_parser::ExecutableDocument { - cynic_parser::parse_executable_document(QUERY).unwrap() -} + #[divan::bench] + fn cynic_parser() -> cynic_parser::ExecutableDocument { + cynic_parser::parse_executable_document(QUERY).unwrap() + } -#[divan::bench( - types = [ - &str, - String - ] -)] -fn graphql_parser() -> graphql_parser::query::Document<'static, T> -where - T: graphql_parser::query::Text<'static>, -{ - graphql_parser::parse_query(QUERY).unwrap() -} + #[divan::bench( + types = [ + &str, + String + ] + )] + fn graphql_parser() -> graphql_parser::query::Document<'static, T> + where + T: graphql_parser::query::Text<'static>, + { + graphql_parser::parse_query(QUERY).unwrap() + } + + #[divan::bench] + fn async_graphql_parser() -> async_graphql_parser::types::ExecutableDocument { + async_graphql_parser::parse_query(QUERY).unwrap() + } -#[divan::bench] -fn async_graphql_parser() -> async_graphql_parser::types::ExecutableDocument { - async_graphql_parser::parse_query(QUERY).unwrap() + #[divan::bench] + fn apollo_parser() -> apollo_parser::SyntaxTree { + apollo_parser::Parser::new(QUERY).parse() + } } -#[divan::bench] -fn apollo_parser() -> apollo_parser::SyntaxTree { - apollo_parser::Parser::new(QUERY).parse() +mod introspection { + const QUERY: &str = include_str!("../tests/executables/introspection.graphql"); + + #[divan::bench] + fn cynic_parser() -> cynic_parser::ExecutableDocument { + cynic_parser::parse_executable_document(QUERY).unwrap() + } + + #[divan::bench( + types = [ + &str, + String + ] + )] + fn graphql_parser() -> graphql_parser::query::Document<'static, T> + where + T: graphql_parser::query::Text<'static>, + { + graphql_parser::parse_query(QUERY).unwrap() + } + + #[divan::bench] + fn async_graphql_parser() -> async_graphql_parser::types::ExecutableDocument { + async_graphql_parser::parse_query(QUERY).unwrap() + } + + #[divan::bench] + fn apollo_parser() -> apollo_parser::SyntaxTree { + apollo_parser::Parser::new(QUERY).parse() + } } diff --git a/cynic-parser/tests/executables.rs b/cynic-parser/tests/executables.rs index baffdad28..d5530bb87 100644 --- a/cynic-parser/tests/executables.rs +++ b/cynic-parser/tests/executables.rs @@ -32,6 +32,12 @@ fn inline_fragment_dir() { display_test("tests/executables/inline_fragment_dir.graphql"); } +#[test] +fn introspection_query() { + roundtrip_test("tests/executables/introspection.graphql"); + display_test("tests/executables/introspection.graphql"); +} + #[test] fn kitchen_sink() { double_roundtrip_test("tests/executables/kitchen-sink.graphql"); diff --git a/cynic-parser/tests/executables/introspection.graphql b/cynic-parser/tests/executables/introspection.graphql new file mode 100644 index 000000000..73ad9764c --- /dev/null +++ b/cynic-parser/tests/executables/introspection.graphql @@ -0,0 +1,107 @@ +query IntrospectionQuery { + __schema { + queryType { + name + } + mutationType { + name + } + subscriptionType { + name + } + types { + ...FullType + } + directives { + name + description + locations + args { + ...InputValue + } + } + } +} + +fragment FullType on __Type { + kind + name + description + fields(includeDeprecated: true) { + name + description + args { + ...InputValue + } + type { + ...TypeRef + } + isDeprecated + deprecationReason + } + inputFields { + ...InputValue + } + interfaces { + ...TypeRef + } + enumValues(includeDeprecated: true) { + name + description + isDeprecated + deprecationReason + } + possibleTypes { + ...TypeRef + } +} + +fragment InputValue on __InputValue { + name + description + type { + ...TypeRef + } + defaultValue +} + +fragment TypeRef on __Type { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + } + } + } + } + } + } + } + } + } +} diff --git a/cynic-parser/tests/snapshots/executables__introspection.snap b/cynic-parser/tests/snapshots/executables__introspection.snap new file mode 100644 index 000000000..ace209edc --- /dev/null +++ b/cynic-parser/tests/snapshots/executables__introspection.snap @@ -0,0 +1,112 @@ +--- +source: cynic-parser/tests/executables.rs +expression: output +--- +query IntrospectionQuery { + __schema { + queryType { + name + } + mutationType { + name + } + subscriptionType { + name + } + types { + ... FullType + } + directives { + name + description + locations + args { + ... InputValue + } + } + } +} + +fragment FullType on __Type { + kind + name + description + fields(includeDeprecated: true) { + name + description + args { + ... InputValue + } + type { + ... TypeRef + } + isDeprecated + deprecationReason + } + inputFields { + ... InputValue + } + interfaces { + ... TypeRef + } + enumValues(includeDeprecated: true) { + name + description + isDeprecated + deprecationReason + } + possibleTypes { + ... TypeRef + } +} + +fragment InputValue on __InputValue { + name + description + type { + ... TypeRef + } + defaultValue +} + +fragment TypeRef on __Type { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + } + } + } + } + } + } + } + } + } +} +