Open ghost opened 1 year ago
would you like to send a PR for this!?
oof sorry about this (I introduced the bug)... IIRC I think I had copied some earlier logic and didn't quite understand what filepath
was even doing here, but it worked in all my tests, and indeed, I guess we weren't using strict mode so I missed the type checking errors
This is still a problem and annoying to discover when upgrading to v4/v5 of the CLI. If you rely on setting cwd
, then you also can't switch over to CodegenContext easily.
Which packages are impacted by your issue?
@graphql-codegen/cli
Describe the bug
When using
watch
in thegenerate
call from@graphql-codegen/cli
you will get an error:This is triggered from here: https://github.com/dotansimha/graphql-code-generator/blob/2139f1db5704aa34a0cd89342736bf67ec556da3/packages/graphql-codegen-cli/src/utils/patterns.ts#L122
filePath
is not always defined (in fact it is not possible to set it at all using the plain object input ofgenerate
), see here: https://github.com/dotansimha/graphql-code-generator/blob/2139f1db5704aa34a0cd89342736bf67ec556da3/packages/graphql-codegen-cli/src/config.ts#L365Typescript in strict mode would have complained here, since the result of the RHS is then in fact
string | undefined
.The constructor is called only with the
config
object, sofilepath
will always beundefined
, triggering the error. https://github.com/dotansimha/graphql-code-generator/blob/2139f1db5704aa34a0cd89342736bf67ec556da3/packages/graphql-codegen-cli/src/config.ts#L448Why not use
strict: true
for this project? That would have caught the bug here.Workaround for the current version: Call
generate
with an instance ofCodegenContext
, instead of using the plain object.Your Example Website or App
private repo
Steps to Reproduce the Bug or Issue
See description
Expected behavior
No crash
Screenshots or Videos
No response
Platform
graphql
version: 16 (irrelevant)@graphql-codegen/*
version(s):@graphql-codegen/cli
4.0.1
Codegen Config File
Additional context
Workaround:
I'm not sure what that extra watcher does, but this is actually working for me, triggering rebuild when any of the
documents
change.