Skip to content

Commit

Permalink
Add json schema for savedStateConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
captbaritone committed Jun 23, 2024
1 parent c4b2e87 commit 6ccccc9
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
36 changes: 35 additions & 1 deletion compiler/crates/relay-compiler/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ pub struct MultiProjectConfigFile {
feature_flags: FeatureFlags,

/// Watchman saved state config.
#[schemars(skip)] // TODO: Fix me
#[schemars(with = "Option<ScmAwareClockDataJsonSchemaDef>")]
saved_state_config: Option<ScmAwareClockData>,

/// Then name of the global __DEV__ variable to use in generated artifacts
Expand Down Expand Up @@ -1053,3 +1053,37 @@ pub trait OperationPersister {
Ok(())
}
}

// Below are structs that we use as part of our config that are defined in
// crates that are not part of Relay. We are not able to implement `JsonSchema`
// for these structs directly, so we define these shadow structs which match the
// deserialization shape of the original. We can then use `#[serde(with =
// "...")]` to have JsonSchema use these shadow structs to generate the schema.
//
// See [Schemars docs](https://graham.cool/schemars/examples/5-remote_derive/)
// for more context on this pattern.

/// Holds extended clock data that includes source control aware
/// query metadata.
/// <https://facebook.github.io/watchman/docs/scm-query.html>
#[derive(JsonSchema)]
#[serde(remote = "ScmAwareClockData")]
pub struct ScmAwareClockDataJsonSchemaDef {
pub mergebase: Option<String>,
#[serde(rename = "mergebase-with")]
pub mergebase_with: Option<String>,
#[serde(rename = "saved-state")]
pub saved_state: Option<SavedStateClockDataJsonSchemaDef>,
}

/// Holds extended clock data that includes source control aware
/// query metadata.
/// <https://facebook.github.io/watchman/docs/scm-query.html>
#[derive(JsonSchema)]
#[serde(remote = "SavedStateClockData")]
pub struct SavedStateClockDataJsonSchemaDef {
pub storage: Option<String>,
#[serde(rename = "commit-id")]
pub commit: Option<String>,
pub config: Option<Value>,
}
43 changes: 43 additions & 0 deletions compiler/relay-compiler-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4471,6 +4471,49 @@
"null"
]
},
"savedStateConfig": {
"description": "Watchman saved state config.",
"type": [
"object",
"null"
],
"properties": {
"mergebase": {
"type": [
"string",
"null"
]
},
"mergebase-with": {
"type": [
"string",
"null"
]
},
"saved-state": {
"description": "Holds extended clock data that includes source control aware query metadata. <https://facebook.github.io/watchman/docs/scm-query.html>",
"type": [
"object",
"null"
],
"properties": {
"commit-id": {
"type": [
"string",
"null"
]
},
"config": true,
"storage": {
"type": [
"string",
"null"
]
}
}
}
}
},
"sources": {
"description": "A mapping from directory paths (relative to the root) to a source set. If a path is a subdirectory of another path, the more specific path wins.",
"type": "object",
Expand Down

0 comments on commit 6ccccc9

Please sign in to comment.