gqty-dev / gqty

The No-GraphQL Client for TypeScript
https://gqty.dev
MIT License
934 stars 26 forks source link

fix(cli): fix watching of schema files outside of working directory #1998

Closed lubosmato closed 3 months ago

lubosmato commented 3 months ago

The PR fixes watching of schema files that are outside of working directory.

Solves #1997

vicary commented 3 months ago

@lubosmato Thanks for contributing!

There are some missing bits that I'd like to add before merging, would you please enable Allow edits from maintainers?

lubosmato commented 3 months ago

Hi @vicary, thank you for this amazing project. Allow by maintainers should be allowed.

vicary commented 3 months ago

@lubosmato For some reason a canary is not published, would you like to test the main branch locally before release?

lubosmato commented 3 months ago

@vicary I have just tested it and it's not working 🤔. I will check what is the problem and ping back.

lubosmato commented 3 months ago

isMatch is now checking resolved file path against parent folder which is not correct. E.g. fullPath = "./api/schema.graphql" and wachEndpoints = ["./api/"].

The correct isMatch params should be fullPath and resolved filenames of endpoints:

diff --git a/packages/cli/src/commands/default.ts b/packages/cli/src/commands/default.ts
index 1f54a4b4..9d9c4508 100644
--- a/packages/cli/src/commands/default.ts
+++ b/packages/cli/src/commands/default.ts
@@ -274,12 +274,13 @@ export const addCommand = (command: Command) => {

         // Watch file changes
         (async () => {
-          const watchEndpoints = endpoints
-            .map((endpoint) => path.resolve(endpoint))
+          const watchFiles = endpoints
+            .map((endpoint) => path.resolve(endpoint));
+          const watchDirectories = watchFiles
             .map((endpoint) => path.dirname(endpoint));

           const watchIterable = pipeAsync(
-            [...new Set(watchEndpoints)],
+            [...new Set(watchDirectories)],
             map((path) =>
               pipeAsync(
                 watch(path),
@@ -296,7 +297,7 @@ export const addCommand = (command: Command) => {

             const fullPath = path.resolve(parentPath, filename);

-            if (!isMatch(fullPath, watchEndpoints)) continue;
+            if (!isMatch(fullPath, watchFiles)) continue;

             // Already queued
             if (shouldRun) continue;
vicary commented 3 months ago

@lubosmato My bad for the oversight, pushed again to main.