Skip to content

How can we write tests for resolvers? #1058

Answered by ilslv
sanket143 asked this question in Q&A

You must be logged in to vote

You can create RootNode with an EmptyMutation and EmptySubscription and run execute on it. We do it like that in integration tests:

pub struct DemoQuery {}

#[graphql_object(context = Context)]
impl DemoQuery {
    pub fn outputs(input: Input) -> Vec<Output> {
        vec![Output {
            id: input.id
        }]
    }
}

#[cfg(test)]
mod tests {
    use juniper::{execute, graphql_value, graphql_vars, EmptyMutation, EmptySubscription, RootNode}

    use super::*;

    #[tokio::test]
    async fn resolves() {
        const QUERY: &str = r#"{
            outputs(input: ...) {
                id
            }
        }"#;

        let schema = RootNode::new(
            DemoQuery,

Replies: 1 comment 1 reply

You must be logged in to vote
1 reply
@sanket143

Answer selected by sanket143
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants