INNER CODE UNIT · Rust

get_set_schema_from_file

graphql-rust/graphql-client · graphql_client_codegen/src/lib.rs:74

fn get_set_schema_from_file(schema_path: &std::path::Path) -> Schema {
    get_set_cached(&SCHEMA_CACHE, schema_path, || {
        let schema_extension = schema_path
            .extension()
            .map(|ext| ext.to_str().expect("Path must be valid UTF-8"))
            .unwrap_or("<no extension>");
        let schema_string = read_file(schema_path).unwrap();
        match schema_extension {
            "graphql" | "graphqls"| "gql" => {
                let s = graphql_parser::schema::parse_schema::<&str>(&schema_string).map_err(|parser_error| GeneralError(format!("Parser error: {}", parser_error))).unwrap();
                Schema::from(s)
            }
            "json" => {
                let parsed: graphql_introspection_query::introspection_response::IntrospectionResponse = serde_json::from_str(&schema_string).unwrap();
                Schema::from(parsed)
            }
            extension => panic!("Unsupported extension for the GraphQL schema: {} (only .json, .graphql, .graphqls and .gql are supported)", extension)
        }

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…