Skip to content

Commit

Permalink
Add support for .gql file extensions for schema files
Browse files Browse the repository at this point in the history
Summary: This should fix: #3772 by adding `.gql` to the various places in `file_source` when we may query/filter the schema files.

Reviewed By: tyao1

Differential Revision: D33766985

fbshipit-source-id: 25522a2c343ce2e1fb4af69166a4281de9e04801
  • Loading branch information
alunyov authored and facebook-github-bot committed Jan 26, 2022
1 parent 3328e8d commit 03ed79c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
17 changes: 14 additions & 3 deletions compiler/crates/relay-compiler/src/file_source/file_categorizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl FileCategorizer {
Err(Cow::Borrowed("Invalid extension for a generated file."))
}
}
} else if extension == "graphql" {
} else if is_schema_extension(extension) {
if let Some(project_set) = self.schema_file_mapping.get(path) {
Ok(FileGroup::Schema {
project_set: project_set.clone(),
Expand All @@ -278,7 +278,7 @@ impl FileCategorizer {
Ok(FileGroup::Schema { project_set })
} else {
Err(Cow::Borrowed(
"Expected *.graphql file to be either a schema or extension.",
"Expected *.graphql/*.gql file to be either a schema or extension.",
))
}
} else {
Expand Down Expand Up @@ -357,6 +357,10 @@ fn is_source_code_extension(extension: &OsStr) -> bool {
extension == "js" || extension == "jsx" || extension == "ts" || extension == "tsx"
}

fn is_schema_extension(extension: &OsStr) -> bool {
extension == "graphql" || extension == "gql"
}

fn is_valid_source_code_extension(typegen_language: &TypegenLanguage, extension: &OsStr) -> bool {
match typegen_language {
TypegenLanguage::TypeScript => is_source_code_extension(extension),
Expand Down Expand Up @@ -519,7 +523,14 @@ mod tests {
assert_eq!(
categorizer.categorize(&PathBuf::from("src/js/a.graphql")),
Err(Cow::Borrowed(
"Expected *.graphql file to be either a schema or extension."
"Expected *.graphql/*.gql file to be either a schema or extension."
)),
);

assert_eq!(
categorizer.categorize(&PathBuf::from("src/js/a.gql")),
Err(Cow::Borrowed(
"Expected *.graphql/*.gql file to be either a schema or extension."
)),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub struct WalkDirFileSource<'config> {
fn get_expected_file_extensions(config: &Config) -> HashSet<&str> {
let mut file_extensions = HashSet::<&str>::with_capacity(5);
file_extensions.insert("graphql");
file_extensions.insert("gql");

for project in config.enabled_projects() {
match project.typegen_config.language {
TypegenLanguage::Flow => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ 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
Expr::Suffix(vec!["graphql".into()]),
Expr::Suffix(vec!["graphql".into(), "gql".into()]),
// in one of the extension directories
expr_files_in_dirs(roots),
])
Expand Down

0 comments on commit 03ed79c

Please sign in to comment.