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
* Support query_string macro attribute
Add test for query string attribute
Handle non-utf8 paths and files without extensions
Co-authored-by: Surma <surma@surma.dev>
Update crate doc comment
Use options: GraphQLClientCodegenOptions
* Prettier fixes
.map(|ext| ext.to_str().expect("Path must be valid UTF-8"))
82
+
.unwrap_or("<no extension>");
83
+
let schema_string = read_file(schema_path).unwrap();
84
+
match schema_extension {
85
+
"graphql" | "gql" => {
86
+
let s = graphql_parser::schema::parse_schema::<&str>(&schema_string).map_err(|parser_error| GeneralError(format!("Parser error: {}", parser_error))).unwrap();
87
+
Schema::from(s)
88
+
}
89
+
"json" => {
90
+
let parsed: graphql_introspection_query::introspection_response::IntrospectionResponse = serde_json::from_str(&schema_string).unwrap();
91
+
Schema::from(parsed)
92
+
}
93
+
extension => panic!("Unsupported extension for the GraphQL schema: {} (only .json and .graphql are supported)", extension)
94
+
}
95
+
})
96
+
}
97
+
98
+
/// Generates Rust code given a path to a query file, a path to a schema file, and options.
55
99
pubfngenerate_module_token_stream(
56
100
query_path: std::path::PathBuf,
57
101
schema_path:&std::path::Path,
58
102
options:GraphQLClientCodegenOptions,
59
103
) -> 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
-
};
104
+
let query = get_set_query_from_file(query_path.as_path());
105
+
let schema = get_set_schema_from_file(schema_path);
91
106
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