Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.graphql-let.yml cacheDir relative vs absolute #605

Open
kevinvalk opened this issue Nov 4, 2021 · 3 comments
Open

.graphql-let.yml cacheDir relative vs absolute #605

kevinvalk opened this issue Nov 4, 2021 · 3 comments

Comments

@kevinvalk
Copy link

Firstly, great tool, super useful!

I was trying to move all my *.graphql files into a separate internal private package (specifically monorepo). While struggling with includes, paths, webpack, typescript etc, I think I stumbled upon a discrepancy in cacheDir usage.

If no cacheDir is set, the folder (node_modules.cache\graphql-let) seems it is always generated relatively to the .graphql-let.yml file. Even if you use in another package something like graphql-let --config ../packages/graphql/.graphql-let.yml.

However, if you set cacheDir, the cache folder is placed relatively to the location graphql-let is run from. It feels that both of these should behave similar (relative vs absolute paths).

P.S. Maybe related, paths specified in schema are relative to where graphql-let is executed and not where the configuration file is placed. Not sure, but in my use case, it would be better if the paths are all relative to the location of the .graphql-let.yml file. Curious what you think.

@comp615
Copy link
Contributor

comp615 commented May 4, 2022

Adding related context here if you use the jestTransformer, it's very difficult to get it setup alongside a moved config.

  • The config file is searched for from the rootDir (or run location)
  • But then the config file's cacheDir is searched from relative to rootDir, even if the config file was found in another dir
    const { rootDir: cwd } = jestConfig;
    const { configFile, subsequentTransformer } = getOption(jestConfig);
    const [config, configHash] = loadConfigSync(cwd, configFile);
    const { execContext } = createExecContextSync(cwd, config, configHash);
    const { tsxFullPath } = createPaths(execContext, relative(cwd, sourcePath));
    const tsxContent = readFileSync(tsxFullPath, 'utf-8');

Instead, the transformer should generate the ultimate transform location by using the location of the cacheDir relative to the configFile dir NOT to its own rootDir.

Concretely:

workspace/app/.graphql-let.yml

cacheDir: ../.cache

jest-config.js

rootDir: '/workspace',
{ configFile: "./app/.graphql-let.yml" }

when running jest, it will try to replace the file with the cached file at .cache/blah instead of workspace/.cache, which is incorrect (everything else in the setup will work though)

comp615 added a commit to comp615/graphql-let that referenced this issue May 5, 2022
Partially addresses piglovesyou#605 

Sets a new cwd context in cases where the config file does not reside in the jest root directory. This is necessary because the config file can then give the cache location, but it will be relative to its own location (not that of the jest config)
@comp615
Copy link
Contributor

comp615 commented Aug 31, 2022

Additionally, wanted to add that this same path mismatch issue is encountered looking for schema too. The paths there have the same issue of being generated relative to the "run" directory. So if you have a root generator, but another folder like /app that runs webpack, it becomes impossible to correctly specify paths in the config file.

comp615 added a commit to comp615/graphql-let that referenced this issue Apr 10, 2023
Partially addresses piglovesyou#605 

Sets a new cwd context in cases where the config file does not reside in the jest root directory. This is necessary because the config file can then give the cache location, but it will be relative to its own location (not that of the jest config)
@comp615
Copy link
Contributor

comp615 commented Jun 15, 2023

Heya, I think I've fixed this in the associated pull request. I'm currently testing to verify at our org, but would be curious to hear if it helps you all. You can try it using the version "graphql-let": "comp615/graphql-let#cityblock_integration",. Feedback welcome!

comp615 added a commit to comp615/graphql-let that referenced this issue Feb 9, 2024
Partially addresses piglovesyou#605 

Sets a new cwd context in cases where the config file does not reside in the jest root directory. This is necessary because the config file can then give the cache location, but it will be relative to its own location (not that of the jest config)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants