Skip to content

Commit

Permalink
Search through untracked files for graphql-tag. Don't error out on fi…
Browse files Browse the repository at this point in the history
…les that can't be found.
  • Loading branch information
jeresig committed Jul 2, 2024
1 parent 4a4aebd commit 32e8589
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/spicy-bugs-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@khanacademy/graphql-flow': patch
---

Search through untracked files for graphql-tag. Don't error out on files that can't be found.
5 changes: 4 additions & 1 deletion src/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ import {dirname} from 'path';
/** Step (1) */

const findGraphqlTagReferences = (root: string): Array<string> => {
// NOTE(john): We want to include untracked files here so that we can
// generate types for them. This is useful for when we have a new file
// that we want to generate types for, but we haven't committed it yet.
const response = execSync(
"git grep -I --word-regexp --name-only --fixed-strings 'graphql-tag' -- '*.js' '*.jsx' '*.ts' '*.tsx'",
"git grep -I --word-regexp --name-only --fixed-strings --untracked 'graphql-tag' -- '*.js' '*.jsx' '*.ts' '*.tsx'",
{
encoding: 'utf8',
cwd: root,
Expand Down
4 changes: 3 additions & 1 deletion src/parser/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ const listExternalReferences = (file: FileResult): Array<string> => {
if (v.type === 'import') {
if (followImports) {
const absPath = getPathWithExtension(v.path);
paths[absPath] = true;
if (absPath) {
paths[absPath] = true;
}
}
} else {
v.source.expressions.forEach((expr) => add(expr, true));
Expand Down
5 changes: 4 additions & 1 deletion src/parser/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ export const getPathWithExtension = (pathWithoutExtension: string): string => {
if (fs.existsSync(pathWithoutExtension + '.ts')) {
return pathWithoutExtension + '.ts';
}
throw new Error("Can't find file at " + pathWithoutExtension);
// NOTE(john): This is a bit of a hack, but it's necessary for when we
// have a file that doesn't have an extension. This will happen when we
// delete all of the type files before re-running graphql-flow again.
return "";
};

0 comments on commit 32e8589

Please sign in to comment.