diff --git a/crates/graphql_artifact_generation/src/generate_artifacts.rs b/crates/graphql_artifact_generation/src/generate_artifacts.rs index 9269d83a..546c3a0f 100644 --- a/crates/graphql_artifact_generation/src/generate_artifacts.rs +++ b/crates/graphql_artifact_generation/src/generate_artifacts.rs @@ -7,7 +7,7 @@ use graphql_lang_types::{ }; use intern::{string_key::Intern, Lookup}; -use isograph_config::{GenerateFileExtensionsOption, OptionalValidationLevel}; +use isograph_config::GenerateFileExtensionsOption; use isograph_lang_types::{ ArgumentKeyAndValue, ClientFieldId, NonConstantValue, SelectableServerFieldId, SelectionType, ServerFieldSelection, TypeAnnotation, UnionVariant, VariableDefinition, @@ -79,7 +79,7 @@ pub fn get_artifact_path_and_content( project_root: &Path, artifact_directory: &Path, file_extensions: GenerateFileExtensionsOption, - on_missing_babel_transform: OptionalValidationLevel, + no_babel_transform: bool, ) -> Vec { let mut encountered_client_field_map = BTreeMap::new(); let mut path_and_contents = vec![]; @@ -302,7 +302,7 @@ pub fn get_artifact_path_and_content( path_and_contents.push(build_iso_overload_artifact( schema, file_extensions, - on_missing_babel_transform, + no_babel_transform, )); path_and_contents diff --git a/crates/graphql_artifact_generation/src/iso_overload_file.rs b/crates/graphql_artifact_generation/src/iso_overload_file.rs index 76f93031..cb649b95 100644 --- a/crates/graphql_artifact_generation/src/iso_overload_file.rs +++ b/crates/graphql_artifact_generation/src/iso_overload_file.rs @@ -1,5 +1,5 @@ use intern::Lookup; -use isograph_config::{GenerateFileExtensionsOption, OptionalValidationLevel}; +use isograph_config::GenerateFileExtensionsOption; use std::{cmp::Ordering, path::PathBuf}; use common_lang_types::{ArtifactPathAndContent, SelectableFieldName}; @@ -13,15 +13,15 @@ use crate::generate_artifacts::ISO_TS; fn build_iso_overload_for_entrypoint( validated_client_field: &ValidatedClientField, file_extensions: GenerateFileExtensionsOption, - on_missing_babel_transform: OptionalValidationLevel, + no_babel_transform: bool, ) -> (Option, String) { let formatted_field = format!( "entrypoint {}.{}", validated_client_field.type_and_field.type_name, validated_client_field.type_and_field.field_name ); - match on_missing_babel_transform { - OptionalValidationLevel::Ignore => ( + match no_babel_transform { + true => ( None, format!( " @@ -31,7 +31,7 @@ export function iso( formatted_field ), ), - OptionalValidationLevel::Error | OptionalValidationLevel::Warn => { + false => { let mut s: String = "".to_string(); let import = format!( "import entrypoint_{} from '../__isograph/{}/{}/entrypoint{}';\n", @@ -96,7 +96,7 @@ export function iso( pub(crate) fn build_iso_overload_artifact( schema: &ValidatedSchema, file_extensions: GenerateFileExtensionsOption, - on_missing_babel_transform: OptionalValidationLevel, + no_babel_transform: bool, ) -> ArtifactPathAndContent { let mut imports = "import type { IsographEntrypoint } from '@isograph/react';\n".to_string(); let mut content = String::from( @@ -158,9 +158,9 @@ type MatchesWhitespaceAndString< content.push_str(&field_overload); } - let entrypoint_overloads = sorted_entrypoints(schema).into_iter().map(|field| { - build_iso_overload_for_entrypoint(field, file_extensions, on_missing_babel_transform) - }); + let entrypoint_overloads = sorted_entrypoints(schema) + .into_iter() + .map(|field| build_iso_overload_for_entrypoint(field, file_extensions, no_babel_transform)); for (import, entrypoint_overload) in entrypoint_overloads { if let Some(import) = import { imports.push_str(&import); @@ -177,20 +177,13 @@ export function iso(_isographLiteralText: string): {\n", ); - content.push_str(match on_missing_babel_transform { - OptionalValidationLevel::Error => { + content.push_str(match no_babel_transform { + false => { " throw new Error('iso: Unexpected invocation at runtime. Either the Babel transform ' + 'was not set up, or it failed to identify this call site. Make sure it ' + 'is being used verbatim as `iso`.');" } - OptionalValidationLevel::Warn => { - - " console.warn('iso: Unexpected invocation at runtime. Either the Babel transform ' + - 'was not set up, or it failed to identify this call site. Make sure it ' + - 'is being used verbatim as `iso`.'); - return (clientFieldResolver: any) => clientFieldResolver;" - } - OptionalValidationLevel::Ignore => { + true => { " return (clientFieldResolver: any) => clientFieldResolver;" } }); diff --git a/crates/isograph_compiler/src/compiler_state.rs b/crates/isograph_compiler/src/compiler_state.rs index 1095faed..d6affede 100644 --- a/crates/isograph_compiler/src/compiler_state.rs +++ b/crates/isograph_compiler/src/compiler_state.rs @@ -1,9 +1,7 @@ use std::path::PathBuf; use graphql_artifact_generation::get_artifact_path_and_content; -use isograph_config::{ - create_config, CompilerConfig, GenerateFileExtensionsOption, OptionalValidationLevel, -}; +use isograph_config::{create_config, CompilerConfig, GenerateFileExtensionsOption}; use isograph_schema::{Schema, UnvalidatedSchema}; use crate::{ @@ -85,7 +83,7 @@ impl CompilerState { source_files, &self.config, self.config.options.generate_file_extensions, - self.config.options.on_missing_babel_transform, + self.config.options.no_babel_transform, )?; Ok(CompilationStats { client_field_count: stats.client_field_count, @@ -102,7 +100,7 @@ impl CompilerState { source_files, &self.config, self.config.options.generate_file_extensions, - self.config.options.on_missing_babel_transform, + self.config.options.no_babel_transform, )?; Ok(CompilationStats { client_field_count: stats.client_field_count, @@ -121,7 +119,7 @@ impl CompilerState { source_files, &self.config, self.config.options.generate_file_extensions, - self.config.options.on_missing_babel_transform, + self.config.options.no_babel_transform, )?; Ok(CompilationStats { client_field_count: stats.client_field_count, @@ -152,7 +150,7 @@ pub fn validate_and_create_artifacts_from_source_files( source_files: SourceFiles, config: &CompilerConfig, file_extensions: GenerateFileExtensionsOption, - on_missing_babel_transform: OptionalValidationLevel, + no_babel_transform: bool, ) -> Result { // Create schema let mut unvalidated_schema = UnvalidatedSchema::new(); @@ -169,7 +167,7 @@ pub fn validate_and_create_artifacts_from_source_files( &config.project_root, &config.artifact_directory, file_extensions, - on_missing_babel_transform, + no_babel_transform, ); let total_artifacts_written = write_artifacts_to_disk(artifacts, &config.artifact_directory)?; diff --git a/crates/isograph_config/src/compilation_options.rs b/crates/isograph_config/src/compilation_options.rs index 8582013e..60762db3 100644 --- a/crates/isograph_config/src/compilation_options.rs +++ b/crates/isograph_config/src/compilation_options.rs @@ -27,7 +27,7 @@ pub struct CompilerConfig { #[derive(Default, Debug, Clone, Copy)] pub struct ConfigOptions { pub on_invalid_id_type: OptionalValidationLevel, - pub on_missing_babel_transform: OptionalValidationLevel, + pub no_babel_transform: bool, pub generate_file_extensions: GenerateFileExtensionsOption, } @@ -183,7 +183,7 @@ pub fn create_config(config_location: PathBuf) -> CompilerConfig { #[serde(default, deny_unknown_fields)] struct ConfigFileOptions { on_invalid_id_type: ConfigFileOptionalValidationLevel, - on_missing_babel_transform: ConfigFileOptionalValidationLevel, + no_babel_transform: bool, include_file_extensions_in_import_statements: bool, } @@ -207,9 +207,7 @@ impl Default for ConfigFileOptionalValidationLevel { fn create_options(options: ConfigFileOptions) -> ConfigOptions { ConfigOptions { on_invalid_id_type: create_optional_validation_level(options.on_invalid_id_type), - on_missing_babel_transform: create_optional_validation_level( - options.on_missing_babel_transform, - ), + no_babel_transform: options.no_babel_transform, generate_file_extensions: create_generate_file_extensions( options.include_file_extensions_in_import_statements, ),