diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0f493a5814d92..1fb788114e87d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -143,6 +143,31 @@ jobs: run: grep -r --include "*.rs" --files-without-match "@generated" crates | xargs rustfmt --check --config="skip_children=true" working-directory: ./compiler/ + build-config-schema: + name: Build Relay Compiler Config JSON Schema + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + toolchain: 1.64.0 + override: true + + - uses: actions-rs/cargo@v1 + with: + command: build + args: --features vendored --manifest-path compiler/Cargo.toml --bin relay-config-schema --release + + - name: Generate JSON Schema + run: | + ./compiler/target/release/relay-config-schema > relay-config-schema.json; + node scripts/fixJsonSchema.js; + - name: Upload JSON Schema + uses: actions/upload-artifact@v2 + with: + name: relay-config-schema.json + path: ./relay-config-schema.json + build-compiler: name: Build Rust Compiler (${{ matrix.target.os }}) strategy: @@ -218,7 +243,7 @@ jobs: name: Publish to NPM runs-on: ubuntu-latest if: github.event_name == 'push' && github.repository == 'facebook/relay' - needs: [js-tests, js-lint, typecheck, build-tests, build-compiler] + needs: [js-tests, js-lint, typecheck, build-tests, build-compiler, build-config-schema] steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 @@ -253,6 +278,11 @@ jobs: with: name: relay-bin-win-x64 path: artifacts/win-x64 + - name: Download artifact relay-config-schema + uses: actions/download-artifact@v2 + with: + name: relay-config-schema.json + path: artifacts/relay-config-schmea.json - name: Mark binaries as executable working-directory: artifacts run: | diff --git a/compiler/Cargo.lock b/compiler/Cargo.lock index 400eba940a626..fab1c304d1297 100644 --- a/compiler/Cargo.lock +++ b/compiler/Cargo.lock @@ -225,6 +225,7 @@ dependencies = [ "lsp-types", "md-5", "rayon", + "schemars", "serde", "serde_json", ] @@ -394,6 +395,15 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "docblock-shared" +version = "0.0.0" +dependencies = [ + "common", + "intern", + "lazy_static", +] + [[package]] name = "docblock-syntax" version = "0.0.0" @@ -412,6 +422,12 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bd4b30a6560bbd9b4620f4de34c3f14f60848e58a9b7216801afcb4c7b31c3c" +[[package]] +name = "dyn-clone" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9b0705efd4599c15a38151f4721f7bc388306f61084d3bfd50bd07fbca5cb60" + [[package]] name = "either" version = "1.6.1" @@ -913,6 +929,7 @@ dependencies = [ "once_cell", "parking_lot 0.11.2", "rand", + "schemars", "serde", "serde_bytes", "serde_derive", @@ -1552,6 +1569,7 @@ dependencies = [ "relay-typegen", "schema", "schema-diff", + "schemars", "serde", "serde_bser", "serde_json", @@ -1575,17 +1593,28 @@ dependencies = [ "intern", "pathdiff", "regex", + "schemars", "serde", "serde_json", "strum", "strum_macros", ] +[[package]] +name = "relay-config-schema" +version = "0.1.0" +dependencies = [ + "relay-compiler", + "schemars", + "serde_json", +] + [[package]] name = "relay-docblock" version = "0.0.0" dependencies = [ "common", + "docblock-shared", "docblock-syntax", "extract-graphql", "fixture-tests", @@ -1609,6 +1638,7 @@ dependencies = [ "common", "crossbeam", "dashmap", + "docblock-shared", "docblock-syntax", "dunce", "extract-graphql", @@ -1666,6 +1696,7 @@ version = "0.0.0" dependencies = [ "common", "dashmap", + "docblock-shared", "errors", "fixture-tests", "fnv", @@ -1694,6 +1725,7 @@ name = "relay-typegen" version = "0.0.0" dependencies = [ "common", + "docblock-shared", "fixture-tests", "fnv", "graphql-ir", @@ -1852,6 +1884,31 @@ dependencies = [ "thiserror", ] +[[package]] +name = "schemars" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a5fb6c61f29e723026dc8e923d94c694313212abbecbbe5f55a7748eec5b307" +dependencies = [ + "dyn-clone", + "indexmap", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f188d036977451159430f3b8dc82ec76364a42b7e289c2b18a9a18f4470058e9" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn", +] + [[package]] name = "scopeguard" version = "1.1.0" @@ -1923,6 +1980,17 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_derive_internals" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "serde_json" version = "1.0.79" diff --git a/compiler/Cargo.toml b/compiler/Cargo.toml index d9a1fdda6e819..4b3b96ce266ea 100644 --- a/compiler/Cargo.toml +++ b/compiler/Cargo.toml @@ -29,4 +29,5 @@ members = [ "crates/schema-print", "crates/schema-validate", "crates/signedsource", + "crates/relay-config-schema" ] diff --git a/compiler/crates/common/Cargo.toml b/compiler/crates/common/Cargo.toml index 696222259783c..e5ce0e1c47597 100644 --- a/compiler/crates/common/Cargo.toml +++ b/compiler/crates/common/Cargo.toml @@ -14,5 +14,6 @@ log = { version = "0.4.17", features = ["kv_unstable", "kv_unstable_std"] } lsp-types = "0.93.2" md-5 = "0.10" rayon = "1.2" +schemars = {version = "0.8.11", features = ["indexmap1"] } serde = { version = "1.0.136", features = ["derive", "rc"] } serde_json = { version = "1.0.79", features = ["float_roundtrip", "unbounded_depth"] } diff --git a/compiler/crates/common/src/feature_flags.rs b/compiler/crates/common/src/feature_flags.rs index 799f3fe5c73b7..a3e7e49b202e9 100644 --- a/compiler/crates/common/src/feature_flags.rs +++ b/compiler/crates/common/src/feature_flags.rs @@ -12,12 +12,13 @@ use std::fmt::Result as FmtResult; use indexmap::IndexSet; use intern::string_key::StringKey; use intern::Lookup; +use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; -use crate::Rollout; +use crate::rollout::Rollout; -#[derive(Default, Debug, Serialize, Deserialize, Clone)] +#[derive(Default, Debug, Serialize, Deserialize, Clone, JsonSchema)] #[serde(deny_unknown_fields)] pub struct FeatureFlags { #[serde(default)] @@ -77,7 +78,7 @@ pub struct FeatureFlags { pub emit_normalization_nodes_for_client_edges: bool, } -#[derive(Debug, Deserialize, Clone, Serialize)] +#[derive(Debug, Deserialize, Clone, Serialize, JsonSchema)] #[serde(tag = "kind", rename_all = "lowercase")] pub enum FeatureFlag { /// Fully disabled: developers may not use this feature diff --git a/compiler/crates/common/src/named_item.rs b/compiler/crates/common/src/named_item.rs index 516c092c60544..a844c559ca2e5 100644 --- a/compiler/crates/common/src/named_item.rs +++ b/compiler/crates/common/src/named_item.rs @@ -12,6 +12,7 @@ use intern::impl_lookup; use intern::string_key::Intern; use intern::string_key::StringKey; use intern::Lookup; +use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; @@ -45,7 +46,8 @@ pub trait Named { Ord, PartialEq, PartialOrd, - Serialize + Serialize, + JsonSchema )] pub struct DirectiveName(pub StringKey); diff --git a/compiler/crates/common/src/rollout.rs b/compiler/crates/common/src/rollout.rs index 6fd6b0632c1fa..278e2413ff86f 100644 --- a/compiler/crates/common/src/rollout.rs +++ b/compiler/crates/common/src/rollout.rs @@ -7,13 +7,14 @@ use md5::Digest; use md5::Md5; +use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; /// A utility to enable gradual rollout of large codegen changes. /// Can be constructed as the Default which passes or a percentage between 0 and /// 100. -#[derive(Default, Debug, Serialize, Deserialize, Clone, Copy)] +#[derive(Default, Debug, Serialize, Deserialize, Clone, Copy, JsonSchema)] pub struct Rollout(Option); impl Rollout { diff --git a/compiler/crates/intern/Cargo.toml b/compiler/crates/intern/Cargo.toml index 13def7a85df02..7633d119e8fc9 100644 --- a/compiler/crates/intern/Cargo.toml +++ b/compiler/crates/intern/Cargo.toml @@ -17,6 +17,7 @@ serde = { version = "1.0.136", features = ["derive", "rc"] } serde_bytes = "0.11" serde_derive = "1.0" smallvec = { version = "1.6.1", features = ["serde", "union"] } +schemars = {version = "0.8.11" } [dev-dependencies] bincode = "1.3.3" diff --git a/compiler/crates/intern/src/string_key.rs b/compiler/crates/intern/src/string_key.rs index 0912cea9f90fd..f4cf5882fca5e 100644 --- a/compiler/crates/intern/src/string_key.rs +++ b/compiler/crates/intern/src/string_key.rs @@ -12,6 +12,9 @@ use std::fmt::Formatter; use std::str::FromStr; use indexmap::IndexMap; +use schemars::schema::InstanceType; +use schemars::schema::SchemaObject; +use schemars::JsonSchema; use serde::Deserialize; use serde::Deserializer; use serde::Serialize; @@ -55,6 +58,20 @@ impl StringKey { } } +impl JsonSchema for StringKey { + fn schema_name() -> String { + "StringKey".to_owned() + } + + fn json_schema(_: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { + SchemaObject { + instance_type: Some(InstanceType::String.into()), + ..Default::default() + } + .into() + } +} + impl Lookup for StringKey { fn lookup(self) -> &'static str { self.0.as_str() diff --git a/compiler/crates/relay-compiler/Cargo.toml b/compiler/crates/relay-compiler/Cargo.toml index bdff20454a6ec..94c9f06ebf47d 100644 --- a/compiler/crates/relay-compiler/Cargo.toml +++ b/compiler/crates/relay-compiler/Cargo.toml @@ -51,6 +51,7 @@ relay-transforms = { path = "../relay-transforms" } relay-typegen = { path = "../relay-typegen" } schema = { path = "../schema" } schema-diff = { path = "../schema-diff" } +schemars = { version = "0.8.11", features = ["indexmap1"]} serde = { version = "1.0.136", features = ["derive", "rc"] } serde_bser = "0.3" serde_json = { version = "1.0.79", features = ["float_roundtrip", "unbounded_depth"] } diff --git a/compiler/crates/relay-compiler/src/compiler_state.rs b/compiler/crates/relay-compiler/src/compiler_state.rs index f19db00de470b..0e0dc1b1d58cb 100644 --- a/compiler/crates/relay-compiler/src/compiler_state.rs +++ b/compiler/crates/relay-compiler/src/compiler_state.rs @@ -33,6 +33,7 @@ use relay_config::SchemaConfig; use schema::SDLSchema; use schema_diff::definitions::SchemaChange; use schema_diff::detect_changes; +use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use zstd::stream::read::Decoder as ZstdDecoder; @@ -58,7 +59,7 @@ use crate::file_source::SourceControlUpdateStatus; pub type ProjectName = StringKey; /// Set of project names. -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash, JsonSchema)] #[serde(from = "DeserializableProjectSet")] pub struct ProjectSet(Vec); diff --git a/compiler/crates/relay-compiler/src/config.rs b/compiler/crates/relay-compiler/src/config.rs index ac1d4dfba981b..2e6fb2be84b84 100644 --- a/compiler/crates/relay-compiler/src/config.rs +++ b/compiler/crates/relay-compiler/src/config.rs @@ -44,6 +44,7 @@ pub use relay_config::SchemaLocation; use relay_config::TypegenConfig; pub use relay_config::TypegenLanguage; use relay_transforms::CustomTransformsConfig; +use schemars::JsonSchema; use serde::de::Error as DeError; use serde::Deserialize; use serde::Deserializer; @@ -599,9 +600,9 @@ fn get_default_excludes() -> Vec { } /// Schema of the compiler configuration JSON file. -#[derive(Debug, Serialize, Deserialize, Default)] +#[derive(Debug, Serialize, Deserialize, Default, JsonSchema)] #[serde(deny_unknown_fields, rename_all = "camelCase")] -struct MultiProjectConfigFile { +pub struct MultiProjectConfigFile { /// Optional name for this config, might be used for logging or custom extra /// artifact generator code. #[serde(default)] @@ -635,16 +636,21 @@ struct MultiProjectConfigFile { feature_flags: FeatureFlags, /// Watchman saved state config. + #[schemars(skip)] saved_state_config: Option, /// Then name of the global __DEV__ variable to use in generated artifacts is_dev_variable_name: Option, } -#[derive(Debug, Serialize, Deserialize)] -#[serde(deny_unknown_fields, rename_all = "camelCase", default)] +fn default_project_name() -> StringKey { + "default".intern() +} + +#[derive(Debug, Serialize, Deserialize, JsonSchema)] +#[serde(deny_unknown_fields, rename_all = "camelCase")] pub struct SingleProjectConfigFile { - #[serde(skip)] + #[serde(skip, default = "default_project_name")] pub project_name: StringKey, /// Path to schema.graphql @@ -659,24 +665,28 @@ pub struct SingleProjectConfigFile { /// [DEPRECATED] This is deprecated field, we're not using it in the V13. /// Adding to the config, to show the warning, and not a parse error. + #[serde(default)] pub include: Vec, /// [DEPRECATED] This is deprecated field, we're not using it in the V13. /// Adding to the config, to show the warning, and not a parse error. + #[serde(default)] pub extensions: Vec, /// Directories to ignore under src /// default: ['**/node_modules/**', '**/__mocks__/**', '**/__generated__/**'], - #[serde(alias = "exclude")] + #[serde(default, alias = "exclude")] pub excludes: Vec, /// List of directories with schema extensions. + #[serde(default)] pub schema_extensions: Vec, /// This option controls whether or not a catch-all entry is added to enum type definitions /// for values that may be added in the future. Enabling this means you will have to update /// your application whenever the GraphQL server schema adds new enum values to prevent it /// from breaking. + #[serde(default)] pub no_future_proof_enums: bool, /// The name of the language plugin (?) used for input files and artifacts @@ -684,9 +694,11 @@ pub struct SingleProjectConfigFile { /// Mappings from custom scalars in your schema to built-in GraphQL /// types, for type emission purposes. + #[serde(default)] pub custom_scalars: FnvIndexMap, /// This option enables emitting es modules artifacts. + #[serde(default)] pub eager_es_modules: bool, /// Query Persist Configuration @@ -702,9 +714,11 @@ pub struct SingleProjectConfigFile { pub codegen_command: Option, /// Formatting style for generated files. + #[serde(default)] pub js_module_format: JsModuleFormat, /// Extra configuration for the schema itself. + #[serde(default)] pub schema_config: SchemaConfig, /// Configuration for @module @@ -891,9 +905,9 @@ impl SingleProjectConfigFile { } } -#[derive(Serialize)] +#[derive(Serialize, JsonSchema)] #[serde(untagged)] -enum ConfigFile { +pub enum ConfigFile { /// Base case configuration (mostly of OSS) where the project /// have single schema, and single source directory SingleProject(SingleProjectConfigFile), @@ -928,7 +942,7 @@ It also cannot be a single project config file due to: } } -#[derive(Debug, Deserialize, Serialize, Default)] +#[derive(Debug, Deserialize, Serialize, Default, JsonSchema)] #[serde(deny_unknown_fields, rename_all = "camelCase")] pub struct ConfigFileProject { /// If a base project is set, the documents of that project can be diff --git a/compiler/crates/relay-config-schema/Cargo.toml b/compiler/crates/relay-config-schema/Cargo.toml new file mode 100644 index 0000000000000..a407e6cc2b8af --- /dev/null +++ b/compiler/crates/relay-config-schema/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "relay-config-schema" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +schemars = { version="0.8.11" } +relay-compiler = { path = "../relay-compiler" } +serde_json = { version = "1.0.79" } diff --git a/compiler/crates/relay-config-schema/src/main.rs b/compiler/crates/relay-config-schema/src/main.rs new file mode 100644 index 0000000000000..61663e12224f0 --- /dev/null +++ b/compiler/crates/relay-config-schema/src/main.rs @@ -0,0 +1,7 @@ +use relay_compiler::config::ConfigFile; +use schemars::schema_for; + +fn main() { + let schema = schema_for!(ConfigFile); + println!("{}", serde_json::to_string_pretty(&schema).unwrap()); +} diff --git a/compiler/crates/relay-config/Cargo.toml b/compiler/crates/relay-config/Cargo.toml index e030b7f1e3910..cc4787f20976c 100644 --- a/compiler/crates/relay-config/Cargo.toml +++ b/compiler/crates/relay-config/Cargo.toml @@ -17,3 +17,4 @@ serde = { version = "1.0.136", features = ["derive", "rc"] } serde_json = { version = "1.0.79", features = ["float_roundtrip", "unbounded_depth"] } strum = "0.21" strum_macros = "0.21" +schemars = { version = "0.8.11", features = ["indexmap1"]} diff --git a/compiler/crates/relay-config/src/connection_interface.rs b/compiler/crates/relay-config/src/connection_interface.rs index 48de084f7db6b..446b23883f13f 100644 --- a/compiler/crates/relay-config/src/connection_interface.rs +++ b/compiler/crates/relay-config/src/connection_interface.rs @@ -7,11 +7,12 @@ use intern::string_key::Intern; use intern::string_key::StringKey; +use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; /// Configuration where Relay should expect some fields in the schema. -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, JsonSchema)] #[serde(deny_unknown_fields, rename_all = "camelCase")] pub struct ConnectionInterface { pub cursor: StringKey, diff --git a/compiler/crates/relay-config/src/diagnostic_report_config.rs b/compiler/crates/relay-config/src/diagnostic_report_config.rs index 93f7dccf4c81d..0365a0245c9bc 100644 --- a/compiler/crates/relay-config/src/diagnostic_report_config.rs +++ b/compiler/crates/relay-config/src/diagnostic_report_config.rs @@ -6,11 +6,12 @@ */ use common::DiagnosticSeverity; +use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; /// Levels for reporting errors in the compiler. -#[derive(Copy, Clone, Debug, Deserialize, Serialize)] +#[derive(Copy, Clone, Debug, Deserialize, Serialize, JsonSchema)] #[serde(rename_all = "lowercase")] pub enum DiagnosticLevel { /// Report only errors @@ -35,7 +36,7 @@ impl From for DiagnosticSeverity { } /// Configuration for all diagnostic reporting in the compiler -#[derive(Copy, Clone, Debug, Deserialize, Serialize)] +#[derive(Copy, Clone, Debug, Deserialize, Serialize, JsonSchema)] #[serde(rename_all = "camelCase")] pub struct DiagnosticReportConfig { /// Threshold for diagnostics to be critical to the compiler's execution. diff --git a/compiler/crates/relay-config/src/js_module_format.rs b/compiler/crates/relay-config/src/js_module_format.rs index 1ceac0327d638..a9bf9966f308e 100644 --- a/compiler/crates/relay-config/src/js_module_format.rs +++ b/compiler/crates/relay-config/src/js_module_format.rs @@ -5,11 +5,12 @@ * LICENSE file in the root directory of this source tree. */ +use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; /// Formatting style for generated files. -#[derive(Copy, Clone, Debug, Deserialize, Serialize)] +#[derive(Copy, Clone, Debug, Deserialize, Serialize, JsonSchema)] #[serde(rename_all = "lowercase")] pub enum JsModuleFormat { /// Common JS style, e.g. `require('../path/MyModule')` diff --git a/compiler/crates/relay-config/src/module_import_config.rs b/compiler/crates/relay-config/src/module_import_config.rs index b1ed8dfbaf9fb..c2ccc6205f98c 100644 --- a/compiler/crates/relay-config/src/module_import_config.rs +++ b/compiler/crates/relay-config/src/module_import_config.rs @@ -6,11 +6,12 @@ */ use intern::string_key::StringKey; +use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; /// Configuration for @module. -#[derive(Debug, Deserialize, Serialize, Default, Copy, Clone)] +#[derive(Debug, Deserialize, Serialize, Default, Copy, Clone, JsonSchema)] #[serde(deny_unknown_fields, rename_all = "camelCase")] pub struct ModuleImportConfig { /// Defines the custom import statement to be generated on the @@ -19,7 +20,17 @@ pub struct ModuleImportConfig { pub dynamic_module_provider: Option, } -#[derive(Debug, Deserialize, Serialize, Eq, Clone, Copy, PartialEq, Hash)] +#[derive( + Debug, + Deserialize, + Serialize, + Eq, + Clone, + Copy, + PartialEq, + Hash, + JsonSchema +)] #[serde(tag = "mode")] pub enum DynamicModuleProvider { /// Generates a module provider using JSResource diff --git a/compiler/crates/relay-config/src/non_node_id_fields_config.rs b/compiler/crates/relay-config/src/non_node_id_fields_config.rs index a0623e72c2d4f..2564df6fb5c22 100644 --- a/compiler/crates/relay-config/src/non_node_id_fields_config.rs +++ b/compiler/crates/relay-config/src/non_node_id_fields_config.rs @@ -8,11 +8,12 @@ use std::collections::HashMap; use intern::string_key::StringKey; +use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; /// Configuration of Relay's validation for `id` fields outside of the `Node` interface. -#[derive(Debug, Default, Serialize, Deserialize)] +#[derive(Debug, Default, Serialize, Deserialize, JsonSchema)] #[serde(deny_unknown_fields, rename_all = "camelCase")] pub struct NonNodeIdFieldsConfig { /// A map of parent type names to allowed type names for fields named `id` diff --git a/compiler/crates/relay-config/src/project_config.rs b/compiler/crates/relay-config/src/project_config.rs index d76dcbce01ab3..6fd190a871032 100644 --- a/compiler/crates/relay-config/src/project_config.rs +++ b/compiler/crates/relay-config/src/project_config.rs @@ -24,6 +24,7 @@ use intern::string_key::Intern; use intern::string_key::StringKey; use intern::Lookup; use regex::Regex; +use schemars::JsonSchema; use serde::de::Error; use serde::Deserialize; use serde::Deserializer; @@ -42,7 +43,7 @@ type FnvIndexMap = IndexMap; pub type ProjectName = StringKey; -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] #[serde(deny_unknown_fields)] pub struct RemotePersistConfig { /// URL to send a POST request to to persist. @@ -77,7 +78,7 @@ where Ok(Some(permits)) } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] pub enum LocalPersistAlgorithm { MD5, SHA1, @@ -91,7 +92,7 @@ impl Default for LocalPersistAlgorithm { } } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] #[serde(deny_unknown_fields)] pub struct LocalPersistConfig { pub file: PathBuf, @@ -100,7 +101,7 @@ pub struct LocalPersistConfig { pub algorithm: LocalPersistAlgorithm, } -#[derive(Debug, Serialize, Clone)] +#[derive(Debug, Serialize, Clone, JsonSchema)] #[serde(untagged)] pub enum PersistConfig { Remote(RemotePersistConfig), @@ -146,7 +147,7 @@ pub enum SchemaLocation { Directory(PathBuf), } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "camelCase")] pub struct SchemaConfig { #[serde(default)] diff --git a/compiler/crates/relay-config/src/typegen_config.rs b/compiler/crates/relay-config/src/typegen_config.rs index 8f1594fcf7c3b..a2bca60f78f42 100644 --- a/compiler/crates/relay-config/src/typegen_config.rs +++ b/compiler/crates/relay-config/src/typegen_config.rs @@ -11,6 +11,7 @@ use common::ScalarName; use fnv::FnvBuildHasher; use indexmap::IndexMap; use intern::string_key::StringKey; +use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use strum::IntoEnumIterator; @@ -25,7 +26,8 @@ type FnvIndexMap = IndexMap; Clone, Serialize, Deserialize, - PartialEq + PartialEq, + JsonSchema )] #[serde(deny_unknown_fields, rename_all = "lowercase")] pub enum TypegenLanguage { @@ -50,21 +52,21 @@ impl TypegenLanguage { } } -#[derive(Debug, Serialize, Deserialize, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)] #[serde(untagged)] pub enum CustomScalarType { Name(StringKey), Path(CustomScalarTypeImport), } -#[derive(Debug, Serialize, Deserialize, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)] pub struct CustomScalarTypeImport { pub name: StringKey, pub path: PathBuf, } -#[derive(Debug, Serialize, Deserialize, Default)] +#[derive(Debug, Serialize, Deserialize, Default, JsonSchema)] #[serde(deny_unknown_fields, rename_all = "camelCase")] pub struct TypegenConfig { /// The desired output language, "flow" or "typescript". @@ -110,7 +112,7 @@ pub struct TypegenConfig { pub eager_es_modules: bool, } -#[derive(Default, Debug, Serialize, Deserialize, Clone, Copy)] +#[derive(Default, Debug, Serialize, Deserialize, Clone, Copy, JsonSchema)] #[serde(deny_unknown_fields, tag = "phase")] pub struct FlowTypegenConfig { /// This option controls whether or not a catch-all entry is added to enum type definitions diff --git a/scripts/config.tests.json b/scripts/config.tests.json index a7eb49eb32bfe..f431ab94e905a 100644 --- a/scripts/config.tests.json +++ b/scripts/config.tests.json @@ -28,7 +28,6 @@ "jsModuleFormat": "commonjs", "featureFlags": { "enable_relay_resolver_transform": true, - "use_named_imports_for_relay_resolvers": true, "relay_resolver_model_syntax_enabled": true, "enable_flight_transform": true, "no_inline": { diff --git a/scripts/fixJsonSchema.js b/scripts/fixJsonSchema.js new file mode 100644 index 0000000000000..50fde319de94d --- /dev/null +++ b/scripts/fixJsonSchema.js @@ -0,0 +1,16 @@ +// This script exists to replace the root `anyOf` with `oneOf` in our JSON Schema. +// The Rust Crate `schemars` is not properly outputting `oneOf` so we'll manually edit it here + +const fs = require('fs'); + +const schemaPath = './relay-config-schema.json'; + +const fileContents = fs.readFileSync(schemaPath, 'utf-8'); +const parsedFileContents = JSON.parse(fileContents); + +parsedFileContents.oneOf = parsedFileContents.anyOf; +delete parsedFileContents.anyOf; + +const outputFileContents = JSON.stringify(parsedFileContents, null, 2); + +fs.writeFileSync(schemaPath, outputFileContents); \ No newline at end of file