You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Generates Rust code given a query document, a schema and options.
55
-
pubfngenerate_module_token_stream(
56
-
query_path: std::path::PathBuf,
57
-
schema_path:&std::path::Path,
58
-
options:GraphQLClientCodegenOptions,
59
-
) -> Result<TokenStream,BoxError>{
56
+
fnget_set_cached<K: std::cmp::Ord,V:Clone>(
57
+
cache:&CacheMap<K,V>,
58
+
key:K,
59
+
value:V,
60
+
) -> Result<V,BoxError>{
60
61
use std::collections::btree_map;
61
62
62
-
let schema_extension = schema_path
63
-
.extension()
64
-
.and_then(std::ffi::OsStr::to_str)
65
-
.unwrap_or("INVALID");
66
-
let schema_string;
67
-
68
-
// Check the schema cache.
69
-
let schema: schema::Schema = {
70
-
letmut lock = SCHEMA_CACHE.lock().expect("schema cache is poisoned");
71
-
match lock.entry(schema_path.to_path_buf()){
63
+
let cached:V = {
64
+
letmut lock = cache.lock().expect("cache is poisoned");
65
+
match lock.entry(key){
72
66
btree_map::Entry::Occupied(o) => o.get().clone(),
73
-
btree_map::Entry::Vacant(v) => {
74
-
schema_string = read_file(v.key())?;
75
-
let schema = match schema_extension {
76
-
"graphql" | "gql" => {
77
-
let s = graphql_parser::schema::parse_schema::<&str>(&schema_string).map_err(|parser_error| GeneralError(format!("Parser error: {}", parser_error)))?;
78
-
schema::Schema::from(s)
79
-
}
80
-
"json" => {
81
-
let parsed: graphql_introspection_query::introspection_response::IntrospectionResponse = serde_json::from_str(&schema_string)?;
82
-
schema::Schema::from(parsed)
83
-
}
84
-
extension => returnErr(GeneralError(format!("Unsupported extension for the GraphQL schema: {} (only .json and .graphql are supported)", extension)).into())
let s = graphql_parser::schema::parse_schema::<&str>(&schema_string).map_err(|parser_error| GeneralError(format!("Parser error: {}", parser_error)))?;
101
+
Schema::from(s)
102
+
}
103
+
"json" => {
104
+
let parsed: graphql_introspection_query::introspection_response::IntrospectionResponse = serde_json::from_str(&schema_string)?;
105
+
Schema::from(parsed)
103
106
}
107
+
extension => returnErr(GeneralError(format!("Unsupported extension for the GraphQL schema: {} (only .json and .graphql are supported)", extension)).into())
104
108
}
105
-
};
109
+
})
110
+
}
106
111
107
-
let query = crate::query::resolve(&schema,&query)?;
112
+
/// Generates Rust code given a path to a query file, a path to a schema file, and options.
113
+
pubfngenerate_module_token_stream(
114
+
query_path: std::path::PathBuf,
115
+
schema_path:&std::path::Path,
116
+
options:GraphQLClientCodegenOptions,
117
+
) -> Result<TokenStream,BoxError>{
118
+
let query = get_set_query_from_file(query_path.as_path())?;
119
+
let schema = get_set_schema_from_file(schema_path)?;
0 commit comments