Skip to content

Commit

Permalink
Add a test of spreads (#776)
Browse files Browse the repository at this point in the history
  • Loading branch information
obmarg authored Sep 12, 2023
1 parent 340a300 commit b38c2ab
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cynic/tests/snapshots/spread__snapshot_test_query.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
source: cynic/tests/spread.rs
expression: query.query
---
query FilmDirectorQuery($id: ID) {
film(id: $id) {
id
__typename
... {
title
director
}
... {
releaseDate
}
}
}


69 changes: 69 additions & 0 deletions cynic/tests/spread.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#![allow(dead_code)]

mod schema {
cynic::use_schema!("../schemas/starwars.schema.graphql");
}

#[derive(cynic::QueryFragment, Debug)]
#[cynic(
graphql_type = "Film",
schema_path = "../schemas/starwars.schema.graphql"
)]
struct FilmDetails {
title: Option<String>,
director: Option<String>,
}

#[derive(cynic::QueryFragment, Debug)]
#[cynic(
graphql_type = "Film",
schema_path = "../schemas/starwars.schema.graphql"
)]
struct FilmMoreDetails {
release_date: Option<String>,
}

#[derive(cynic::QueryFragment, Debug)]
#[cynic(schema_path = "../schemas/starwars.schema.graphql")]
struct Film {
id: cynic::Id,
#[cynic(spread)]
details: FilmDetails,
#[cynic(spread)]
more_details: FilmMoreDetails,
}

#[derive(cynic::QueryVariables)]
struct FilmArguments {
id: Option<cynic::Id>,
}

#[derive(cynic::QueryFragment, Debug)]
#[cynic(
graphql_type = "Root",
variables = "FilmArguments",
schema_path = "../schemas/starwars.schema.graphql"
)]
struct FilmDirectorQuery {
#[arguments(id: $id)]
film: Option<Film>,
}

fn build_query() -> cynic::Operation<FilmDirectorQuery, FilmArguments> {
use cynic::QueryBuilder;

FilmDirectorQuery::build(FilmArguments {
id: Some("ZmlsbXM6MQ==".into()),
})
}

#[test]
fn snapshot_test_query() {
// Running a snapshot test of the query building functionality as that gives us
// a place to copy and paste the actual GQL we're using for running elsewhere,
// and also helps ensure we don't change queries by mistake

let query = build_query();

insta::assert_snapshot!(query.query);
}

0 comments on commit b38c2ab

Please sign in to comment.