My graphql query string is very long and some of them are reused, so I want to separate them as strings. But I don't know how to assemble them.
Because the query string is too long, I temporarily use "..." to indicate it.
pub const USER: &'static str = r#"
user{
id
...
}
"#;
pub const REPLY: &'static str = r#"
replies{
id
...
}
"#;
pub const MEDIA: &'static str = r#"
medias{
id
...
}
"#;
// I want to insert the above string into POST
// Assuming the form of {variable}
pub const POST: &'static str = r#"query(
$id: String!
) {
getPost(id: $id){
id
text
{USER}
{REPLY}
{MEDIA}
...
created_at
}
}"#;
I don't know how to implement this features. I have tried format! and other methods, but they can't be implemented.
Compared with other languages, such as js, it is very simple to implement this features. E.g:
// es6 template string
let gql_query_str = `
query(
$id: String!
) {
getPost(id: $id){
id
text
${USER}
${REPLY}
${MEDIA}
...
created_at
}
}
`