Skip to content

Commit

Permalink
chore: test & benchmark parsing introspection (#1098)
Browse files Browse the repository at this point in the history
  • Loading branch information
obmarg authored Nov 13, 2024
1 parent 4d362ac commit 97ecb36
Show file tree
Hide file tree
Showing 4 changed files with 285 additions and 27 deletions.
87 changes: 60 additions & 27 deletions cynic-parser/benches/executable.rs
Original file line number Diff line number Diff line change
@@ -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<T>() -> 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<T>() -> 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<T>() -> 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()
}
}
6 changes: 6 additions & 0 deletions cynic-parser/tests/executables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
107 changes: 107 additions & 0 deletions cynic-parser/tests/executables/introspection.graphql
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
}
}
}
}
}
}
112 changes: 112 additions & 0 deletions cynic-parser/tests/snapshots/executables__introspection.snap
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
}
}
}
}
}
}

0 comments on commit 97ecb36

Please sign in to comment.