"prettier --write" hook is not working
See original GitHub issueDescribe the bug
I am using the ‘near-operation-file’ preset to generate types next to the files including GraphQL operations. I have also added an afterAllFileWrite
hook to run prettier on the generated files but prettier seems to be run only on one of the two files that get generated.
I have also tried using an afterOneFileWrite
hook instead, but the behavior is the same.
To Reproduce Steps to reproduce the behavior:
- Use the following config.
- Create two
.ts
files each one including a GraphQL query. - Add some prettier rules to be run on the generated types.
- Generate the types using
@graphql-codegen
.
My codegen.yml
config file:
overwrite: true
schema: 'http://localhost:24000/graphql'
documents:
- './pages/**/*.{ts,tsx}'
- './components/**/*.{ts,tsx}'
generates:
./generated/graphql/types.ts:
plugins:
- 'typescript'
./:
preset: 'near-operation-file'
presetConfig:
extension: '.gql.types.tsx'
baseTypesPath: 'generated/graphql/types.ts'
plugins:
- 'typescript-operations'
- 'typescript-react-apollo'
config:
withHooks: true
hooks:
afterAllFileWrite:
- prettier --write
Expected behavior
The lifecycle hook should be run for all generated files, not just for one of them.
Environment:
- OS: macOS 10.14.5
@graphql-codegen
: 1.8.3- Node: 11.10.1
Additional context
N/A
Issue Analytics
- State:
- Created 4 years ago
- Reactions:12
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Pre-commit Hook - Prettier
Pre-commit Hook. You can use Prettier with a pre-commit tool. This can re-format your files that are marked as “staged” via git add...
Read more >Prettier as a pre-commit hook is not working on Javascript files
I have integrated prettier as a pre-commit hook and added following code in.pre-comit-config.yaml file:
Read more >"Run Git hooks" on Commit no longer works with prettier
What steps will reproduce the problem? Click on Commit button; Select Run Git hooks checkbox; Click Commit and Push. What is the expected...
Read more >Using Prettier with a Pre-commit Hook | Brian Han
The Problem. It's difficult for everyone to commit to using a new tool. It's not maintainable to ask every team member to install...
Read more >Frontend Handbook | Code Quality / Tools - Infinum
No matter which code quality tools we use, git hooks are a great way to ... If you do not notice issues with...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@dotansimha I just run into this issue. You’re correct, it only works if the hook in the root-level position. Is that intended by design?
Had the same problem but the reason was quite arbitrary - when using the
typescript-resolvers
plugin, I was using theconfig: context
field with a bad path value (always forget it’s relative to the generated file!).➡️ Once this was fixed with the correct path to context,
prettier
andeslint
started working again 😃