dotansimha / dotansimha/graphql-code-generator
Resolve paths relative to config file
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
### Is your feature request related to a problem? Please describe.
We have a multi-project GraphQL config in our monorepo root.
```yaml
projects:
foo:
schema: ./schemas/foo.graphql
documents: ./apps/foo/**/*.graphql
extensions:
codegen:
generates:
./apps/foo/graphql.ts:
plugins:
- typescript
- typescript-operations
- typed-document-node
bar:
schema: ./schemas/bar.graphql
documents: ./apps/bar/**/*.graphql
extensions:
codegen:
generates:
./apps/bar/graphql.ts:
plugins:
- typescript
- typescript-operations
- typed-document-node
```
When I try to load this config in a child package using `loadContext()`, it tries to resolve each configured path relative to the current working directory. Obviously that doesn't work, because those paths are relative to the config file directory.
### Describe the solution you'd like
I think relative paths in config files should always be resolved relative to the location of the config file.
If that's not an option due to backward compatibility, maybe you could add a `root` option similar to Vite:
https://vite.dev/config/shared-options.html#root
That way we could set `root: import.meta.dirname` in a JS/TS config file to ensure all paths are correctly resolved.
### Describe alternatives you've considered
I've tried setting absolute paths (or resolving them myself in a TS config), but this breaks GraphQL-ESLint and the VS Code extension.
I've tried restating configs in each package that needs them, but this duplication is fragile/hard to get right.
### Any additional important details?
_No response_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.