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

chore: test & benchmark parsing introspection #1098

Merged
merged 1 commit into from
Nov 13, 2024
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
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
}
}
}
}
}
}
}
}
}
}

Loading