Skip to content

Commit

Permalink
Merge branch 'main' into feature/support-mjs-and-cjs-configs
Browse files Browse the repository at this point in the history
  • Loading branch information
jantimon authored Jan 16, 2025
2 parents 6d97d0b + be8f5f7 commit bc99cce
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 19 deletions.
2 changes: 1 addition & 1 deletion compiler/crates/dependency-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ common = { path = "../common" }
graphql-ir = { path = "../graphql-ir" }
graphql-syntax = { path = "../graphql-syntax" }
relay-transforms = { path = "../relay-transforms" }
rustc-hash = "1.1.0"
rustc-hash = "2.1.0"
schema = { path = "../schema" }
schema-diff = { path = "../schema-diff" }
serde = { version = "1.0.185", features = ["derive", "rc"] }
Expand Down
2 changes: 1 addition & 1 deletion compiler/crates/relay-compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ relay-saved-state-loader = { path = "../relay-saved-state-loader" }
relay-schema = { path = "../relay-schema" }
relay-transforms = { path = "../relay-transforms" }
relay-typegen = { path = "../relay-typegen" }
rustc-hash = "1.1.0"
rustc-hash = "2.1.0"
schema = { path = "../schema" }
schema-diff = { path = "../schema-diff" }
schema-validate-lib = { path = "../schema-validate" }
Expand Down
8 changes: 4 additions & 4 deletions compiler/crates/relay-compiler/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,12 +997,12 @@ impl SingleProjectConfigFile {
}
})?,
);
for extension_dir in self.schema_extensions.iter() {
for extension_path in self.schema_extensions.iter() {
paths.push(
canonicalize(root_dir.join(extension_dir.clone())).map_err(|_| {
ConfigValidationError::ExtensionDirNotExistent {
canonicalize(root_dir.join(extension_path.clone())).map_err(|_| {
ConfigValidationError::ExtensionPathNotExistent {
project_name: self.project_name,
extension_dir: extension_dir.clone(),
extension_path: extension_path.clone(),
}
})?,
);
Expand Down
6 changes: 3 additions & 3 deletions compiler/crates/relay-compiler/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ pub enum ConfigValidationError {
},

#[error(
"The `schemaExtensions` configured for project `{project_name}` does not exist at `{extension_dir}`."
"The `schemaExtensions` configured for project `{project_name}` does not exist at `{extension_path}`."
)]
ExtensionDirNotExistent {
ExtensionPathNotExistent {
project_name: ProjectName,
extension_dir: PathBuf,
extension_path: PathBuf,
},

#[error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn get_watchman_expr(config: &Config) -> Expr {

let extension_roots = config.get_extension_roots();
if !extension_roots.is_empty() {
let extensions_expr = expr_graphql_files_in_dirs(extension_roots);
let extensions_expr = expr_graphql_file_or_dir_contents(extension_roots);
expressions.push(extensions_expr);
}

Expand Down Expand Up @@ -132,13 +132,27 @@ fn expr_files_in_dirs(roots: Vec<PathBuf>) -> Expr {

fn expr_graphql_files_in_dirs(roots: Vec<PathBuf>) -> Expr {
Expr::All(vec![
// ending in *.graphql
// ending in *.graphql or *.gql
Expr::Suffix(vec!["graphql".into(), "gql".into()]),
// in one of the extension directories
expr_files_in_dirs(roots),
])
}

// Expression to get all graphql items by path or path of containing folder.
fn expr_graphql_file_or_dir_contents(paths: Vec<PathBuf>) -> Expr {
Expr::All(vec![
Expr::Suffix(vec!["graphql".into(), "gql".into()]),
Expr::Any(vec![
Expr::Name(NameTerm {
paths: paths.clone(),
wholename: true,
}),
expr_files_in_dirs(paths),
]),
])
}

/// Helper to create an `anyof` expression if multiple items are passed or just
/// return the expression for a single item input `Vec`.
/// Panics for empty expressions. These are not valid in Watchman. We could
Expand Down
2 changes: 1 addition & 1 deletion compiler/crates/relay-schema-generation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ intern = { path = "../intern" }
lazy_static = "1.4"
relay-config = { path = "../relay-config" }
relay-docblock = { path = "../relay-docblock" }
rustc-hash = "1.1.0"
rustc-hash = "2.1.0"
schema-extractor = { path = "../schema-extractor" }
serde = { version = "1.0.185", features = ["derive", "rc"] }
thiserror = "2"
Expand Down
2 changes: 1 addition & 1 deletion compiler/crates/relay-transforms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ parking_lot = { version = "0.12.1", features = ["send_guard"] }
regex = "1.9.2"
relay-config = { path = "../relay-config" }
relay-schema = { path = "../relay-schema" }
rustc-hash = "1.1.0"
rustc-hash = "2.1.0"
schema = { path = "../schema" }
serde = { version = "1.0.185", features = ["derive", "rc"] }
thiserror = "2"
Expand Down
2 changes: 1 addition & 1 deletion compiler/crates/schema-diff/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ graphql-syntax = { path = "../graphql-syntax" }
intern = { path = "../intern" }
lazy_static = "1.4"
relay-config = { path = "../relay-config" }
rustc-hash = "1.1.0"
rustc-hash = "2.1.0"
schema = { path = "../schema" }
2 changes: 1 addition & 1 deletion compiler/crates/schema-extractor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ hermes_comments = { git = "https://github.com/facebook/hermes.git" }
hermes_estree = { git = "https://github.com/facebook/hermes.git" }
hermes_parser = { git = "https://github.com/facebook/hermes.git" }
intern = { path = "../intern" }
rustc-hash = "1.1.0"
rustc-hash = "2.1.0"
serde = { version = "1.0.185", features = ["derive", "rc"] }
thiserror = "2"
2 changes: 1 addition & 1 deletion packages/relay-compiler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ file sources, and "listen" to the file changes in the "watch" mode. If
[string]
- `excludes` Directories to ignore under `src`. [array] [default:
["\*\*/node_modules/\*\*", "\*\*/__mocks__/\*\*", "\*\*/__generated__/\*\*"]]
- `schemaExtensions` List of directories with schema extensions. [array]
- `schemaExtensions` List of files or directories with schema extensions. [array]
- `schemaConfig`
- `nodeInterfaceIdField` Configure the name of the globally unique ID field on
the Node interface. Useful if you can't use the default `id` field name.
Expand Down
7 changes: 4 additions & 3 deletions website/docs/guides/client-schema-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ The Relay Compiler fully supports client-side extensions of the schema, which al

## Extending the server schema

To extend the server schema, create a new `.graphql` file inside your `--src` directory.
Let's call it `./src/clientSchema.graphql`.
This file needs to be in a folder referenced in the `"schemaExtensions"` of your Relay config.
To extend the server schema, create a new `.graphql` file inside your `--src`
directory. Let's call it `./src/clientSchema.graphql`. This file needs to be
referenced in the `"schemaExtensions"` of your Relay config, either directly or
via its folder.

This schema describes what local data can be queried on the client.
It can even be used to extend an existing server schema.
Expand Down

0 comments on commit bc99cce

Please sign in to comment.