Skip to content

Commit 94a0286

Browse files
committed
graphql_client_codegen: update to graphql_parser 0.3
Requires 0.3.1 so that `Document<'a, String>::into_static()` exists. Future work can try and reduce the amount of `'static` used throughout the API, but this at least gets 0.3 into a working state.
1 parent 74e2860 commit 94a0286

File tree

9 files changed

+208
-114
lines changed

9 files changed

+208
-114
lines changed

graphql_client_codegen/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ edition = "2018"
99

1010
[dependencies]
1111
graphql-introspection-query = { version = "0.2.0", path = "../graphql-introspection-query" }
12-
graphql-parser = "0.3"
12+
graphql-parser = "0.3.1"
1313
heck = "0.3"
1414
lazy_static = "1.3"
1515
proc-macro2 = { version = "^1.0", features = [] }

graphql_client_codegen/src/codegen.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,16 @@ fn generate_fragment_definitions<'a>(
236236
}
237237

238238
/// For default value constructors.
239-
fn graphql_parser_value_to_literal(
240-
value: &graphql_parser::query::Value,
239+
fn graphql_parser_value_to_literal<'doc, T>(
240+
value: &graphql_parser::query::Value<'doc, T>,
241241
ty: TypeId,
242242
is_optional: bool,
243243
query: &BoundQuery<'_>,
244-
) -> TokenStream {
244+
) -> TokenStream
245+
where
246+
T: graphql_parser::query::Text<'doc>,
247+
T::Value: quote::ToTokens,
248+
{
245249
use graphql_parser::query::Value;
246250

247251
let inner = match value {
@@ -289,11 +293,15 @@ fn graphql_parser_value_to_literal(
289293
}
290294

291295
/// For default value constructors.
292-
fn render_object_literal(
293-
object_map: &BTreeMap<String, graphql_parser::query::Value>,
296+
fn render_object_literal<'doc, T>(
297+
object_map: &BTreeMap<T::Value, graphql_parser::query::Value<'doc, T>>,
294298
input_id: InputId,
295299
query: &BoundQuery<'_>,
296-
) -> TokenStream {
300+
) -> TokenStream
301+
where
302+
T: graphql_parser::query::Text<'doc>,
303+
T::Value: quote::ToTokens,
304+
{
297305
let input = query.schema.get_input(input_id);
298306
let constructor = Ident::new(&input.name, Span::call_site());
299307
let fields: Vec<TokenStream> = input

graphql_client_codegen/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type CacheMap<T> = std::sync::Mutex<HashMap<std::path::PathBuf, T>>;
4747

4848
lazy_static! {
4949
static ref SCHEMA_CACHE: CacheMap<schema::Schema> = CacheMap::default();
50-
static ref QUERY_CACHE: CacheMap<(String, graphql_parser::query::Document)> =
50+
static ref QUERY_CACHE: CacheMap<(String, graphql_parser::query::Document<'static, String>)> =
5151
CacheMap::default();
5252
}
5353

@@ -74,7 +74,7 @@ pub fn generate_module_token_stream(
7474
schema_string = read_file(v.key())?;
7575
let schema = match schema_extension {
7676
"graphql" | "gql" => {
77-
let s = graphql_parser::schema::parse_schema(&schema_string).map_err(|parser_error| GeneralError(format!("Parser error: {}", parser_error)))?;
77+
let s = graphql_parser::schema::parse_schema::<&str>(&schema_string).map_err(|parser_error| GeneralError(format!("Parser error: {}", parser_error)))?;
7878
schema::Schema::from(s)
7979
}
8080
"json" => {
@@ -97,7 +97,8 @@ pub fn generate_module_token_stream(
9797
hash_map::Entry::Vacant(v) => {
9898
let query_string = read_file(v.key())?;
9999
let query = graphql_parser::parse_query(&query_string)
100-
.map_err(|err| GeneralError(format!("Query parser error: {}", err)))?;
100+
.map_err(|err| GeneralError(format!("Query parser error: {}", err)))?
101+
.into_static();
101102
v.insert((query_string, query)).clone()
102103
}
103104
}

0 commit comments

Comments
 (0)