Does Cynic support a single mutation running multiple queries? #511
-
hello, is it possible to build a single mutation executing multiple operations? Example: add two comments on github in a single blow (edited the cynic github mutation example). mutation ($commentBody: String!, $commentBody2: String!) {
m1:addComment(
input: {
body: $commentBody
subjectId: "MDU6SXNzdWU2ODU4NzUxMzQ="
clientMutationId: null
}
) {
commentEdge {
node {
id
}
}
}
m2:addComment(
input: {
body: $commentBody2
subjectId: "MDU6SXNzdWU2ODU4NzUxMzQ="
clientMutationId: null
}
) {
commentEdge {
node {
id
}
}
}
} variables:
thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @jman-schief - i'm pretty sure this should be possible. You just need to use the #[cynic::schema_for_derives(
file = r#"schema.graphql"#,
)]
mod queries {
use super::schema;
#[derive(cynic::QueryVariables, Debug)]
pub struct UnnamedQueryVariables {
pub comment_body: String,
pub comment_body2: String,
}
#[derive(cynic::QueryFragment, Debug)]
#[cynic(graphql_type = "Mutation", variables = "UnnamedQueryVariables")]
pub struct UnnamedQuery {
#[arguments(input: { body: $comment_body, clientMutationId: null, subjectId: "MDU6SXNzdWU2ODU4NzUxMzQ=" })]
#[cynic(rename = "addComment")]
pub m1: Option<AddCommentPayload>,
#[arguments(input: { body: $comment_body2, clientMutationId: null, subjectId: "MDU6SXNzdWU2ODU4NzUxMzQ=" })]
#[cynic(rename = "addComment")]
pub m2: Option<AddCommentPayload>,
}
#[derive(cynic::QueryFragment, Debug)]
pub struct AddCommentPayload {
pub comment_edge: Option<IssueCommentEdge>,
}
#[derive(cynic::QueryFragment, Debug)]
pub struct IssueCommentEdge {
pub node: Option<IssueComment>,
}
#[derive(cynic::QueryFragment, Debug)]
pub struct IssueComment {
pub id: cynic::Id,
}
#[derive(cynic::InputObject, Debug)]
pub struct AddCommentInput {
pub body: String,
pub client_mutation_id: Option<String>,
pub subject_id: cynic::Id,
}
}
mod schema {
cynic::use_schema!(r#"schema.graphql"#);
} |
Beta Was this translation helpful? Give feedback.
-
Thank you so much for the suggestion, as I am dipping my toes into this library, I wasn't aware of the I love how the v2 of this library is shaping up, for the moment I'll stick to the v1 and eventually port it when there's an official release. Thanks again Footnotes
|
Beta Was this translation helpful? Give feedback.
Hi @jman-schief - i'm pretty sure this should be possible. You just need to use the
rename
attribute to tellcynic
thatm1
&m2
are actually theaddComment
fields. I tried putting your query into the generator and it gave me this, which hopefully illustrates the idea: