graphql-rust/graphql-client

Incorrect queries generated when document contains multiple operations

firekind opened this issue · 1 comments

When a document contains multiple operations, the generated QUERY and __QUERY_WORKAROUND constants are incorrect.

Using the schema and queries defined in this test and running cargo expand, you get:

use graphql_client::GraphQLQuery;
#[graphql(
    query_path = "query.graphql",
    schema_path = "schema.graphql",
    response_derives = "Debug, PartialEq, Eq"
)]
pub struct Heights;
pub mod heights {
.
.
.
    pub const OPERATION_NAME: &str = "Heights";
    pub const QUERY: &str = "query Heights($buildingId: ID!, $mountainName: String) {\n  mountainHeight(name: $mountainName)\n  buildingHeight(id: $buildingId)\n}\n\nquery Echo($msg: String) {\n  echo(msg: $msg)\n}";
    const __QUERY_WORKAROUND: &str = "query Heights($buildingId: ID!, $mountainName: String) {\n  mountainHeight(name: $mountainName)\n  buildingHeight(id: $buildingId)\n}\n\nquery Echo($msg: String) {\n  echo(msg: $msg)\n}";
    use serde::{Serialize, Deserialize};
    use super::*;
.
.
.
}

#[graphql(
    query_path = "query.graphql",
    schema_path = "schema.graphql",
    response_derives = "Debug, PartialEq, Eq"
)]
pub struct Echo;
pub mod echo {
.
.
.
    pub const OPERATION_NAME: &str = "Echo";
    pub const QUERY: &str = "query Heights($buildingId: ID!, $mountainName: String) {\n  mountainHeight(name: $mountainName)\n  buildingHeight(id: $buildingId)\n}\n\nquery Echo($msg: String) {\n  echo(msg: $msg)\n}";
    const __QUERY_WORKAROUND: &str = "query Heights($buildingId: ID!, $mountainName: String) {\n  mountainHeight(name: $mountainName)\n  buildingHeight(id: $buildingId)\n}\n\nquery Echo($msg: String) {\n  echo(msg: $msg)\n}";
    use serde::{Serialize, Deserialize};
.
.
.
}

The Echo operation uses the query for Heights instead.

never mind, my bad. Didn't notice that the entire document contents were present in the two constants.