Skip to content

Commit

Permalink
fix: 🐛 add imports in graphql as watched files
Browse files Browse the repository at this point in the history
add imports in graphql as watched files to ensure the importer is invalidated if the imported file changes
  • Loading branch information
DerZade committed Jul 10, 2024
1 parent 5440035 commit 042a8d1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@graphql-codegen/typescript": "^4.0.7",
"@graphql-codegen/typescript-operations": "^4.2.1",
"@graphql-tools/graphql-file-loader": "^8.0.1",
"@graphql-tools/import": "^7.0.1",
"@graphql-tools/load": "^8.0.2",
"commander": "^12.1.0",
"esbuild": "^0.21.4",
Expand Down
13 changes: 13 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { DeclarationWriter } from './declarations_writer';
import { TypeScriptPluginConfig } from '@graphql-codegen/typescript';
import type { TypeScriptDocumentsPluginConfig } from '@graphql-codegen/typescript-operations';
import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader';
import { extractImportLines, parseImportLine } from '@graphql-tools/import';

const EXT = /\.(gql|graphql)$/;

Expand Down Expand Up @@ -135,6 +136,18 @@ export default function typedGraphQLPlugin(options: GraphQLPluginOptions = {}):

resetGQLTagCaches();

const { importLines } = extractImportLines(src);

await Promise.all(
importLines.map(async (line) => {
let { from } = parseImportLine(line.replace(/^#/, '').trim());
from = from.startsWith('./') || from.startsWith('/') ? from : `./${from}`;
const importId = await this.resolve(from, id);
if (importId === null) return;
this.addWatchFile(importId.id);
})
);

const [doc] = await loadDocuments(id, { loaders: [new GraphQLFileLoader()] });

return {
Expand Down

0 comments on commit 042a8d1

Please sign in to comment.