Skip to content

Commit

Permalink
repalce on_missing_babel_transform with no_babel_transform
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrykWalach committed Dec 21, 2024
1 parent f167654 commit c30a130
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 35 deletions.
6 changes: 3 additions & 3 deletions crates/graphql_artifact_generation/src/generate_artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<ArtifactPathAndContent> {
let mut encountered_client_field_map = BTreeMap::new();
let mut path_and_contents = vec![];
Expand Down Expand Up @@ -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
Expand Down
31 changes: 12 additions & 19 deletions crates/graphql_artifact_generation/src/iso_overload_file.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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>, 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!(
"
Expand All @@ -31,7 +31,7 @@ export function iso<T>(
formatted_field
),
),
OptionalValidationLevel::Error | OptionalValidationLevel::Warn => {
false => {
let mut s: String = "".to_string();
let import = format!(
"import entrypoint_{} from '../__isograph/{}/{}/entrypoint{}';\n",
Expand Down Expand Up @@ -96,7 +96,7 @@ export function iso<T>(
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(
Expand Down Expand Up @@ -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);
Expand All @@ -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;"
}
});
Expand Down
14 changes: 6 additions & 8 deletions crates/isograph_compiler/src/compiler_state.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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<usize, BatchCompileError> {
// Create schema
let mut unvalidated_schema = UnvalidatedSchema::new();
Expand All @@ -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)?;
Expand Down
8 changes: 3 additions & 5 deletions crates/isograph_config/src/compilation_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -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,
}

Expand All @@ -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,
),
Expand Down

0 comments on commit c30a130

Please sign in to comment.