Skip to main content

api_testing_core/graphql/
schema.rs

1use std::path::{Path, PathBuf};
2
3use anyhow::Context;
4
5use crate::Result;
6
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub struct GraphqlOperationFile {
9    pub path: PathBuf,
10    pub operation: String,
11}
12
13impl GraphqlOperationFile {
14    pub fn load(path: impl AsRef<Path>) -> Result<Self> {
15        let path = path.as_ref();
16        let operation = std::fs::read_to_string(path)
17            .with_context(|| format!("read operation file: {}", path.display()))?;
18        Ok(Self {
19            path: std::fs::canonicalize(path).unwrap_or_else(|_| path.to_path_buf()),
20            operation,
21        })
22    }
23}