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
let schema_string = read_file(schema_path).unwrap();
86
+
match schema_extension {
87
+
"graphql" | "gql" => {
88
+
let s = graphql_parser::schema::parse_schema::<&str>(&schema_string).map_err(|parser_error| GeneralError(format!("Parser error: {}", parser_error))).unwrap();
89
+
Schema::from(s)
90
+
}
91
+
"json" => {
92
+
let parsed: graphql_introspection_query::introspection_response::IntrospectionResponse = serde_json::from_str(&schema_string).unwrap();
93
+
Schema::from(parsed)
94
+
}
95
+
extension => panic!("Unsupported extension for the GraphQL schema: {} (only .json and .graphql are supported)", extension)
96
+
}
97
+
})
98
+
}
99
+
100
+
/// Generates Rust code given a path to a query file, a path to a schema file, and options.
55
101
pubfngenerate_module_token_stream(
56
102
query_path: std::path::PathBuf,
57
103
schema_path:&std::path::Path,
58
104
options:GraphQLClientCodegenOptions,
59
105
) -> Result<TokenStream,BoxError>{
60
-
use std::collections::btree_map;
61
-
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()){
72
-
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())
85
-
};
86
-
87
-
v.insert(schema).clone()
88
-
}
89
-
}
90
-
};
106
+
let query = get_set_query_from_file(query_path.as_path());
107
+
let schema = get_set_schema_from_file(schema_path);
91
108
92
-
// We need to qualify the query with the path to the crate it is part of
93
-
let(query_string, query) = {
94
-
letmut lock = QUERY_CACHE.lock().expect("query cache is poisoned");
95
-
match lock.entry(query_path){
96
-
btree_map::Entry::Occupied(o) => o.get().clone(),
97
-
btree_map::Entry::Vacant(v) => {
98
-
let query_string = read_file(v.key())?;
99
-
let query = graphql_parser::parse_query(&query_string)
0 commit comments