Skip to content

Commit

Permalink
Use import type in typescript for all imports
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgasson committed Aug 3, 2022
1 parent 44ecca8 commit 05592c8
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 59 deletions.
93 changes: 40 additions & 53 deletions compiler/Cargo.lock

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

23 changes: 17 additions & 6 deletions compiler/crates/relay-compiler/src/artifact_content/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub fn generate_updatable_query(
}

write_import_type_from(
&project_config.typegen_config.language,
&project_config,
&mut section,
generated_types.imported_types,
"relay-runtime",
Expand Down Expand Up @@ -257,7 +257,7 @@ pub fn generate_operation(
}

write_import_type_from(
&project_config.typegen_config.language,
&project_config,
&mut section,
generated_types.imported_types,
"relay-runtime",
Expand Down Expand Up @@ -423,7 +423,7 @@ pub fn generate_split_operation(
writeln!(section, "/*::")?;
}
write_import_type_from(
&project_config.typegen_config.language,
&project_config,
&mut section,
"NormalizationSplitOperation",
"relay-runtime",
Expand Down Expand Up @@ -595,7 +595,7 @@ fn generate_read_only_fragment(
}

write_import_type_from(
&project_config.typegen_config.language,
&project_config,
&mut section,
generated_types.imported_types,
"relay-runtime",
Expand Down Expand Up @@ -785,15 +785,26 @@ fn generate_use_strict_section(language: &TypegenLanguage) -> Result<GenericSect
}

fn write_import_type_from(
language: &TypegenLanguage,
project_config: &ProjectConfig,
section: &mut dyn Write,
type_: &str,
from: &str,
) -> FmtResult {
let language = &project_config.typegen_config.language;
match language {
TypegenLanguage::JavaScript => Ok(()),
TypegenLanguage::Flow => writeln!(section, "import type {{ {} }} from '{}';", type_, from),
TypegenLanguage::TypeScript => writeln!(section, "import {{ {} }} from '{}';", type_, from),
TypegenLanguage::TypeScript => writeln!(
section,
"import {}{{ {} }} from \"{}\";",
if project_config.typegen_config.use_import_type_syntax {
"type "
} else {
""
},
type_,
from
),
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
==================================== INPUT ====================================
fragment LinkedField on User {
name
profilePicture {
uri
width
height
}
}
==================================== OUTPUT ===================================
import type { FragmentRefs } from "relay-runtime";
export type LinkedField$data = {
readonly name: string | null;
readonly profilePicture: {
readonly height: number | null;
readonly uri: string | null;
readonly width: number | null;
} | null;
readonly " $fragmentType": "LinkedField";
};
export type LinkedField$key = {
readonly " $data"?: LinkedField$data;
readonly " $fragmentSpreads": FragmentRefs<"LinkedField">;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fragment LinkedField on User {
name
profilePicture {
uri
width
height
}
}
Loading

0 comments on commit 05592c8

Please sign in to comment.