Closed taro-28 closed 4 months ago
Thanks @taro-28! I agree with your idea! Let's keep it simple whenever possible. If necessary we could look into copying the logic of graphql-code-generator
later on and try all options (but personally I don't really understand/like this approach).
Thanks!
If necessary we could look into copying the logic of graphql-code-generator later on and try all options (but personally I don't really understand/like this approach).
If it seems to be more difficult to implement, I'll give it a try.
Hello!
There are some packages in the GraphQL Codegen plugin whose name does not start with
@graphql-codegen/
(e.g. graphql-codegen-typescript-validation-schema), and they are currently not detected correctly by knip.Reproduction
https://stackblitz.com/edit/aub1ebknip-graphql-codegen?file=package.json,knip.json,codegen.json
Cause
I think it is because the plugin is implemented assuming that the package name starts with
@graphql-codegen/
. https://github.com/webpro-nl/knip/blob/main/packages/knip/src/plugins/graphql-codegen/index.ts#L59-L74Suggestions
1: Return all possible package names in
resolveConfig
For example, if
codegen.json
is the following, if any of@graphql-codegen/typescript-validation-schema
,graphql-codegen-typescript-validation-schema
, etc. exist inpackage.json
, they are treated as used.This idea is ideal for users, but I do not know if it can be easily implemented.
2: Support full name plugin names (I think this is the better way)
For example, if
codegen.json
is the following, only ifgraphql-codegen-typescript-validation-schema
exists inpackage.json
, they are treated as used.Of course, GraphQL Codegen can be set up with the full name. https://github.com/dotansimha/graphql-code-generator/blob/master/packages/graphql-codegen-cli/src/plugins.ts#L8-L18
This idea would only require users to set the full name if the package name is a plugin that does not start with
@graphql-codegen/
, but the implementation could be as simple as a conditional branch based on whether the plugin name containscodegen-
or not.I prefer this idea because there are a few plugins whose package names do not start with
@graphql-codegen/
, and the implementation is simple.If the second idea is acceptable, we would like to create a PR! (I plan to modify preset as well)