question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"prettier --write" hook is not working

See original GitHub issue

Describe 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:closed
  • Created 4 years ago
  • Reactions:12
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
tafelitocommented, Apr 9, 2020

@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?

1reaction
rpedroni-sfcommented, Jan 14, 2021

Had the same problem but the reason was quite arbitrary - when using the typescript-resolvers plugin, I was using the config: 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 and eslint started working again 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found