Skip to content

Commit c6be76f

Browse files
authored
Search through untracked files for graphql-tag. Don't error out on files that can't be found. (#66)
## Summary: This fixes two bugs: 1) Creating types wouldn't work if the files hadn't yet been checked in to Git. This fixes that by now searching through untracked files, as well. 2) The script couldn't run if the graphql type files didn't exist. This fixes that by gracefully handling paths that don't exist. Issue: FEI-5065 ## Test plan: I built it and ran it in webapp and it worked as expected. Author: jeresig Reviewers: somewhatabstract, kevinb-khan, jaredly Required Reviewers: Approved By: somewhatabstract Checks: ✅ Lint & Test (ubuntu-latest, 16.x) Pull Request URL: #66
1 parent 4a4aebd commit c6be76f

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

.changeset/spicy-bugs-wave.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@khanacademy/graphql-flow': patch
3+
---
4+
5+
Search through untracked files for graphql-tag. Don't error out on files that can't be found.

src/cli/run.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ import {dirname} from 'path';
3232
/** Step (1) */
3333

3434
const findGraphqlTagReferences = (root: string): Array<string> => {
35+
// NOTE(john): We want to include untracked files here so that we can
36+
// generate types for them. This is useful for when we have a new file
37+
// that we want to generate types for, but we haven't committed it yet.
3538
const response = execSync(
36-
"git grep -I --word-regexp --name-only --fixed-strings 'graphql-tag' -- '*.js' '*.jsx' '*.ts' '*.tsx'",
39+
"git grep -I --word-regexp --name-only --fixed-strings --untracked 'graphql-tag' -- '*.js' '*.jsx' '*.ts' '*.tsx'",
3740
{
3841
encoding: 'utf8',
3942
cwd: root,

src/parser/parse.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ const listExternalReferences = (file: FileResult): Array<string> => {
105105
if (v.type === 'import') {
106106
if (followImports) {
107107
const absPath = getPathWithExtension(v.path);
108-
paths[absPath] = true;
108+
if (absPath) {
109+
paths[absPath] = true;
110+
}
109111
}
110112
} else {
111113
v.source.expressions.forEach((expr) => add(expr, true));

src/parser/utils.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,9 @@ export const getPathWithExtension = (pathWithoutExtension: string): string => {
2020
if (fs.existsSync(pathWithoutExtension + '.ts')) {
2121
return pathWithoutExtension + '.ts';
2222
}
23-
throw new Error("Can't find file at " + pathWithoutExtension);
23+
// NOTE(john): This is a bit of a hack, but it's necessary for when we
24+
// have a file that doesn't exist. This will happen when we delete all of
25+
// the type files before re-running graphql-flow again. We want to ensure
26+
// that we don't error out in this case.
27+
return "";
2428
};

0 commit comments

Comments
 (0)