Skip to content

Commit

Permalink
refactor: remove operation from QueryTypePrinterContext, remove TypeP…
Browse files Browse the repository at this point in the history
…rinter trait, remove document from SchemaTypePrinterContext
  • Loading branch information
uhyo committed Dec 27, 2024
1 parent 7c3bc71 commit ba804de
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 17 deletions.
12 changes: 1 addition & 11 deletions crates/printer/src/operation_type_printer/type_printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ use itertools::{Either, Itertools};
use nitrogql_ast::{
base::Pos,
directive::Directive,
operation::{FragmentDefinition, OperationDocument},
operation::FragmentDefinition,
selection_set::{Selection, SelectionSet},
value::Value,
variable::VariablesDefinition,
};
use nitrogql_config_file::TypeTarget;
use nitrogql_semantics::direct_fields_of_output_type;
use sourcemap_writer::SourceMapWriter;

use super::{
super::ts_types::{ts_types_util::ts_intersection, TSType},
Expand All @@ -33,18 +32,9 @@ use super::{
pub struct QueryTypePrinterContext<'a, 'src, S: Text<'src>> {
pub options: &'a OperationTypePrinterOptions,
pub schema: &'a Schema<S, Pos>,
pub operation: &'a OperationDocument<'src>,
pub fragment_definitions: &'a HashMap<&'src str, &'a FragmentDefinition<'src>>,
}

pub trait TypePrinter<'src, S: Text<'src>> {
fn print_type(
&self,
options: &QueryTypePrinterContext<'_, 'src, S>,
writer: &mut impl SourceMapWriter,
);
}

pub fn get_type_for_selection_set<'src, S: Text<'src>>(
context: &QueryTypePrinterContext<'_, 'src, S>,
selection_set: &SelectionSet<'src>,
Expand Down
4 changes: 0 additions & 4 deletions crates/printer/src/operation_type_printer/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ where
.collect();
let context = OperationTypePrinterContext {
schema,
operation,
fragment_definitions,
};
Self { options, context }
Expand All @@ -124,7 +123,6 @@ where

pub struct OperationTypePrinterContext<'a, 'src, S: Text<'src>> {
pub schema: &'a Schema<S, Pos>,
pub operation: &'a OperationDocument<'src>,
pub fragment_definitions: HashMap<&'src str, &'a FragmentDefinition<'src>>,
}

Expand Down Expand Up @@ -167,7 +165,6 @@ impl OperationPrinterVisitor for OperationTypePrinterVisitor<'_, '_> {
let type_printer_context = QueryTypePrinterContext {
options: &self.options,
schema: self.context.schema,
operation: self.context.operation,
fragment_definitions: &self.context.fragment_definitions,
};

Expand Down Expand Up @@ -267,7 +264,6 @@ impl OperationPrinterVisitor for OperationTypePrinterVisitor<'_, '_> {
let type_printer_context = QueryTypePrinterContext {
options: &self.options,
schema: self.context.schema,
operation: self.context.operation,
fragment_definitions: &self.context.fragment_definitions,
};

Expand Down
2 changes: 0 additions & 2 deletions crates/printer/src/schema_type_printer/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use crate::SchemaTypePrinterOptions;

pub struct SchemaTypePrinterContext<'src> {
pub options: &'src SchemaTypePrinterOptions,
pub document: &'src TypeSystemDocument<'src>,
pub schema: &'src Schema<Cow<'src, str>, Pos>,
// Mapping from Scalar name to TypeScript types.
pub scalar_types: HashMap<String, ScalarTypeConfig>,
Expand All @@ -36,7 +35,6 @@ impl SchemaTypePrinterContext<'_> {
let local_type_names = make_local_type_names(document, &scalar_types);
SchemaTypePrinterContext {
options,
document,
schema,
scalar_types,
local_type_names,
Expand Down

0 comments on commit ba804de

Please sign in to comment.