Skip to content

Commit

Permalink
chore: parse query w/ cynic-parser in querygen (#1125)
Browse files Browse the repository at this point in the history
  • Loading branch information
obmarg authored Jan 16, 2025
1 parent c28d315 commit 2d387b4
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 259 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion cynic-querygen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ rust-version = { workspace = true }

[dependencies]
Inflector = { version = "0.11.4", default-features = false }
graphql-parser = "0.4"
once_cell = "1.9"
rust_decimal = "1.22"
thiserror = "1.0.30"
Expand Down
4 changes: 2 additions & 2 deletions cynic-querygen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum Error {
UnsupportedQueryDocument(String),

#[error("could not parse query document: {0}")]
QueryParseError(graphql_parser::query::ParseError),
QueryParseError(cynic_parser::Error),

#[error("could not parse schema document: {0}")]
SchemaParseError(cynic_parser::Error),
Expand Down Expand Up @@ -116,7 +116,7 @@ pub fn document_to_fragment_structs(
.map_err(Error::SchemaParseError)?;

let query =
graphql_parser::parse_query::<&str>(query.as_ref()).map_err(Error::QueryParseError)?;
cynic_parser::parse_executable_document(query.as_ref()).map_err(Error::QueryParseError)?;

let (schema, typename_id) = add_builtins(schema);

Expand Down
6 changes: 3 additions & 3 deletions cynic-querygen/src/query_parsing/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ mod tests {
fn deduplicates_input_types_if_same() {
let (schema, typename_id) = &*GITHUB_SCHEMA;
let type_index = Rc::new(TypeIndex::from_schema(schema, *typename_id));
let query = graphql_parser::parse_query::<&str>(
let query = cynic_parser::parse_executable_document(
r#"
query ($filterOne: IssueFilters!, $filterTwo: IssueFilters!) {
cynic: repository(owner: "obmarg", name: "cynic") {
Expand Down Expand Up @@ -191,7 +191,7 @@ mod tests {
fn finds_variable_input_types() {
let (schema, typename_id) = &*GITHUB_SCHEMA;
let type_index = Rc::new(TypeIndex::from_schema(schema, *typename_id));
let query = graphql_parser::parse_query::<&str>(
let query = cynic_parser::parse_executable_document(
r#"
query MyQuery($input: IssueFilters!) {
cynic: repository(owner: "obmarg", name: "cynic") {
Expand Down Expand Up @@ -224,7 +224,7 @@ mod tests {
let (schema, typename_id) = &*TEST_CASE_SCHEMA;
let type_index = Rc::new(TypeIndex::from_schema(schema, *typename_id));

let query = graphql_parser::parse_query::<&str>(
let query = cynic_parser::parse_executable_document(
r#"
query MyQuery($input: SelfRecursiveInput!, $input2: RecursiveInputParent!) {
recursiveInputField(recursive: $input, recursive2: $input2)
Expand Down
14 changes: 7 additions & 7 deletions cynic-querygen/src/query_parsing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ use std::rc::Rc;
mod inputs;
mod leaf_types;
mod normalisation;
mod parser;
mod sorting;
mod value;
mod variables;

use parser::Document;
use variables::VariableStructDetails;

pub use normalisation::Variable;
pub use value::{LiteralContext, TypedValue};

use cynic_parser::{executable as parser, ExecutableDocument};

use crate::{
casings::CasingExt,
naming::Namer,
output::{self, Output},
Error, TypeIndex,
};

pub fn parse_query_document<'text>(
doc: &Document<'text>,
type_index: &Rc<TypeIndex<'text>>,
) -> Result<Output<'text, 'text>, Error> {
pub fn parse_query_document<'a>(
doc: &'a ExecutableDocument,
type_index: &Rc<TypeIndex<'a>>,
) -> Result<Output<'a, 'a>, Error> {
let normalised = normalisation::normalise(doc, type_index)?;
let input_objects = inputs::extract_input_objects(&normalised)?;

Expand All @@ -42,7 +42,7 @@ pub fn parse_query_document<'text>(

namers
.selection_sets
.force_name(&operation.root, &operation_name);
.force_name(&operation.root, operation_name.clone());

variable_struct_details
.force_name_variables_for(&operation.root, format!("{operation_name}Variables"));
Expand Down
Loading

0 comments on commit 2d387b4

Please sign in to comment.