Skip to content

Commit 8661127

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 8661127

File tree

9 files changed

+124
-66
lines changed

9 files changed

+124
-66
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ fn generate_fragment_definitions<'a>(
237237

238238
/// For default value constructors.
239239
fn graphql_parser_value_to_literal(
240-
value: &graphql_parser::query::Value,
240+
value: &graphql_parser::query::Value<'static, String>,
241241
ty: TypeId,
242242
is_optional: bool,
243243
query: &BoundQuery<'_>,
@@ -290,7 +290,7 @@ fn graphql_parser_value_to_literal(
290290

291291
/// For default value constructors.
292292
fn render_object_literal(
293-
object_map: &BTreeMap<String, graphql_parser::query::Value>,
293+
object_map: &BTreeMap<String, graphql_parser::query::Value<'static, String>>,
294294
input_id: InputId,
295295
query: &BoundQuery<'_>,
296296
) -> TokenStream {

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
}

graphql_client_codegen/src/query.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub(crate) struct VariableId(u32);
6161

6262
pub(crate) fn resolve(
6363
schema: &Schema,
64-
query: &graphql_parser::query::Document,
64+
query: &graphql_parser::query::Document<'static, String>,
6565
) -> Result<Query, QueryValidationError> {
6666
let mut resolved_query: Query = Default::default();
6767

@@ -100,7 +100,7 @@ pub(crate) fn resolve(
100100

101101
fn create_roots(
102102
resolved_query: &mut Query,
103-
query: &graphql_parser::query::Document,
103+
query: &graphql_parser::query::Document<'static, String>,
104104
schema: &Schema,
105105
) -> Result<(), QueryValidationError> {
106106
// First, give ids to all fragments and operations.
@@ -194,7 +194,7 @@ fn create_roots(
194194
fn resolve_fragment(
195195
query: &mut Query,
196196
schema: &Schema,
197-
fragment_definition: &graphql_parser::query::FragmentDefinition,
197+
fragment_definition: &graphql_parser::query::FragmentDefinition<'static, String>,
198198
) -> Result<(), QueryValidationError> {
199199
let graphql_parser::query::TypeCondition::On(on) = &fragment_definition.type_condition;
200200
let on = schema.find_type(on).ok_or_else(|| {
@@ -227,7 +227,7 @@ fn resolve_fragment(
227227
fn resolve_union_selection(
228228
query: &mut Query,
229229
_union_id: UnionId,
230-
selection_set: &graphql_parser::query::SelectionSet,
230+
selection_set: &graphql_parser::query::SelectionSet<'static, String>,
231231
parent: SelectionParent,
232232
schema: &Schema,
233233
) -> Result<(), QueryValidationError> {
@@ -271,7 +271,7 @@ fn resolve_union_selection(
271271
fn resolve_object_selection<'a>(
272272
query: &mut Query,
273273
object: &dyn crate::schema::ObjectLike,
274-
selection_set: &graphql_parser::query::SelectionSet,
274+
selection_set: &graphql_parser::query::SelectionSet<'static, String>,
275275
parent: SelectionParent,
276276
schema: &'a Schema,
277277
) -> Result<(), QueryValidationError> {
@@ -341,7 +341,7 @@ fn resolve_object_selection<'a>(
341341
fn resolve_selection(
342342
ctx: &mut Query,
343343
on: TypeId,
344-
selection_set: &graphql_parser::query::SelectionSet,
344+
selection_set: &graphql_parser::query::SelectionSet<'static, String>,
345345
parent: SelectionParent,
346346
schema: &Schema,
347347
) -> Result<(), QueryValidationError> {
@@ -373,7 +373,7 @@ fn resolve_selection(
373373
fn resolve_inline_fragment(
374374
query: &mut Query,
375375
schema: &Schema,
376-
inline_fragment: &graphql_parser::query::InlineFragment,
376+
inline_fragment: &graphql_parser::query::InlineFragment<'static, String>,
377377
parent: SelectionParent,
378378
) -> Result<SelectionId, QueryValidationError> {
379379
let graphql_parser::query::TypeCondition::On(on) = inline_fragment
@@ -409,7 +409,7 @@ fn resolve_inline_fragment(
409409
fn resolve_operation(
410410
query: &mut Query,
411411
schema: &Schema,
412-
operation: &graphql_parser::query::OperationDefinition,
412+
operation: &graphql_parser::query::OperationDefinition<'static, String>,
413413
) -> Result<(), QueryValidationError> {
414414
match operation {
415415
graphql_parser::query::OperationDefinition::Mutation(m) => {
@@ -554,7 +554,7 @@ impl Query {
554554
pub(crate) struct ResolvedVariable {
555555
pub(crate) operation_id: OperationId,
556556
pub(crate) name: String,
557-
pub(crate) default: Option<graphql_parser::query::Value>,
557+
pub(crate) default: Option<graphql_parser::query::Value<'static, String>>,
558558
pub(crate) r#type: StoredFieldType,
559559
}
560560

@@ -624,7 +624,7 @@ impl UsedTypes {
624624

625625
fn resolve_variables(
626626
query: &mut Query,
627-
variables: &[graphql_parser::query::VariableDefinition],
627+
variables: &[graphql_parser::query::VariableDefinition<'static, String>],
628628
schema: &Schema,
629629
operation_id: OperationId,
630630
) {

graphql_client_codegen/src/schema.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,12 @@ pub(crate) fn input_is_recursive_without_indirection(input_id: InputId, schema:
443443
let mut visited_types = HashSet::<&str>::new();
444444
input.contains_type_without_indirection(input_id, schema, &mut visited_types)
445445
}
446-
impl std::convert::From<graphql_parser::schema::Document> for Schema {
447-
fn from(ast: graphql_parser::schema::Document) -> Schema {
446+
impl<'doc, T> std::convert::From<graphql_parser::schema::Document<'doc, T>> for Schema
447+
where
448+
T: graphql_parser::query::Text<'doc>,
449+
T::Value: AsRef<str>,
450+
{
451+
fn from(ast: graphql_parser::schema::Document<'doc, T>) -> Schema {
448452
graphql_parser_conversion::build_schema(ast)
449453
}
450454
}
@@ -459,10 +463,13 @@ impl std::convert::From<graphql_introspection_query::introspection_response::Int
459463
}
460464
}
461465

462-
pub(crate) fn resolve_field_type(
466+
pub(crate) fn resolve_field_type<'doc, T>(
463467
schema: &Schema,
464-
inner: &graphql_parser::schema::Type,
465-
) -> StoredFieldType {
468+
inner: &graphql_parser::schema::Type<'doc, T>,
469+
) -> StoredFieldType
470+
where
471+
T: graphql_parser::query::Text<'doc>,
472+
{
466473
use crate::type_qualifiers::graphql_parser_depth;
467474
use graphql_parser::schema::Type::*;
468475

@@ -483,7 +490,7 @@ pub(crate) fn resolve_field_type(
483490
}
484491
NamedType(name) => {
485492
return StoredFieldType {
486-
id: schema.find_type_id(name),
493+
id: schema.find_type_id(name.as_ref()),
487494
qualifiers,
488495
}
489496
}

0 commit comments

Comments
 (0)