diff --git a/compiler/crates/relay-typegen/src/lib.rs b/compiler/crates/relay-typegen/src/lib.rs index 29638887835cc..944b3f12b3f0d 100644 --- a/compiler/crates/relay-typegen/src/lib.rs +++ b/compiler/crates/relay-typegen/src/lib.rs @@ -1228,16 +1228,14 @@ impl<'a> TypeGenerator<'a> { fn transform_graphql_scalar_type(&mut self, scalar: ScalarID) -> AST { let scalar_name = self.schema.scalar(scalar).name; - if scalar_name == *TYPE_ID || scalar_name == *TYPE_STRING { + if let Some(&custom_scalar) = self.typegen_config.custom_scalar_types.get(&scalar_name) { + AST::RawType(custom_scalar) + } else if scalar_name == *TYPE_ID || scalar_name == *TYPE_STRING { AST::String } else if scalar_name == *TYPE_FLOAT || scalar_name == *TYPE_INT { AST::Number } else if scalar_name == *TYPE_BOOLEAN { AST::Boolean - } else if let Some(&custom_scalar) = - self.typegen_config.custom_scalar_types.get(&scalar_name) - { - AST::RawType(custom_scalar) } else { if self.typegen_config.require_custom_scalar_types { panic!( diff --git a/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-raw-response-on-conditional.expected b/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-raw-response-on-conditional.expected index cd1662fd012a8..ff888db336015 100644 --- a/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-raw-response-on-conditional.expected +++ b/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-raw-response-on-conditional.expected @@ -19,7 +19,7 @@ fragment FriendFragment on User { import type { FriendFragment$fragmentType } from "FriendFragment.graphql"; export type ExampleQuery$variables = {| id: string, - condition: boolean, + condition: CustomBoolean, |}; export type ExampleQuery$data = {| +node: ?{| diff --git a/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-stream-connection.expected b/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-stream-connection.expected index 0dc7cf2f52b1b..23e2424b0f175 100644 --- a/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-stream-connection.expected +++ b/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-stream-connection.expected @@ -52,7 +52,7 @@ export type TestDefer$rawResponse = {| |}>, +pageInfo: ?{| +endCursor: ?string, - +hasNextPage: ?boolean, + +hasNextPage: ?CustomBoolean, |}, |}, |} | {| diff --git a/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-stream.expected b/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-stream.expected index 2e1ed57d7ff98..bb912ddf9220b 100644 --- a/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-stream.expected +++ b/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-stream.expected @@ -46,7 +46,7 @@ export type TestStream$rawResponse = {| |}>, +pageInfo: ?{| +endCursor: ?string, - +hasNextPage: ?boolean, + +hasNextPage: ?CustomBoolean, |}, |}, |} | {| diff --git a/compiler/crates/relay-typegen/tests/generate_flow/mod.rs b/compiler/crates/relay-typegen/tests/generate_flow/mod.rs index b98c71d791e4d..e58278c40eede 100644 --- a/compiler/crates/relay-typegen/tests/generate_flow/mod.rs +++ b/compiler/crates/relay-typegen/tests/generate_flow/mod.rs @@ -7,9 +7,10 @@ use common::{ConsoleLogger, FeatureFlag, FeatureFlags, SourceLocationKey}; use fixture_tests::Fixture; -use fnv::FnvHashMap; +use fnv::{FnvBuildHasher, FnvHashMap}; use graphql_ir::{build, Program}; use graphql_syntax::parse_executable; +use indexmap::IndexMap; use intern::string_key::Intern; use relay_codegen::JsModuleFormat; use relay_test_schema::{get_test_schema, get_test_schema_with_extensions}; @@ -17,6 +18,8 @@ use relay_transforms::{apply_transforms, ConnectionInterface}; use relay_typegen::{self, TypegenConfig, TypegenLanguage}; use std::sync::Arc; +type FnvIndexMap = IndexMap; + pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { let parts = fixture.content.split("%extensions%").collect::>(); let (source, schema) = match parts.as_slice() { @@ -56,8 +59,11 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { let js_module_format = JsModuleFormat::Haste; let has_unified_output = false; + let mut custom_scalar_types = FnvIndexMap::default(); + custom_scalar_types.insert("Boolean".intern(), "CustomBoolean".intern()); let typegen_config = TypegenConfig { language: TypegenLanguage::Flow, + custom_scalar_types, ..Default::default() };