graphql-code-generator
graphql-code-generator copied to clipboard
[WIP] Small Fixes: typescript-oclif plugin
Hey team! 👋
I wrote the oclif
plugin back in October and it was merged in March 2020, which surprised me since I still had some pending questions on the MR. Happily, it all works, and you all have done good work keeping it integrated with all of your changes! There are a couple loose ends IMO worth tying off.
Of the questions in that PR, I'm still most interested in the one about the import paths (question # 2). Presets receive information about where they are in the generated-file tree, but plugins do not appear to (or didn't at the time). This means that this plugin is fragile, and we can't have a file structure like this out-of-the-box:
src/commands/hello.ts
src/commands/foo/bar.ts
# ... with handler ...
src/handler.ts
^ Since the plugin doesn't know how deep it is in the tree, it doesn't know whether to import '../../handler'
or import '../handler'
. We can use a tsconfig.json baseUrl
to work around this issue, or put handler.ts
export files everywhere in the tree, but is it possible for a plugin to know its relative file path to the root? If it's not a simple change or lookup, I'll just add a line to the docs about using baseUrl
(that's what the MR "WIP" is for), although that may not work in all situations.
This also includes some other housekeeping:
- Remove development comments related to the above ^
- Remove the default value for
handlerPath
and require it to be set deliberately. While this is a breaking change, I expect that this is specified in most consuming projects since it's in the docs and example. Setting the default as../../handler
assumes that users will be generating a two-level, "multi"-form CLI, which is not necessarily the expected or common case. - A fix in the docs
Hi @kalzoo !
The initial oclif
PR was great, and the changes here seems to make it simpler to use. Thank you!
Can you please check CI? it seems to break.
@kalzoo let me know when this PR is ready for review ;)
Hey @dotansimha , it's ready (for review, not merge), just been hoping for input on that question 🙂
@kalzoo I know long time has passes, but I don't see any reason not to merge it. You are the owner of the plugin, so I completely trust you on this one. Let me know if you want to get this merged and released.
@kalzoo Is there anything we can help to get this merged?
Yes, I need answers to the questions I posed here and in the original PR. These are not questions about my plugin, they're about the interaction of the plugin with the framework, and how to get the behavior one sees in a preset. I haven't looked at this recently and so I can't say if plugins have more capabilities/information than they did at the time I made this PR, but at that time it wasn't possible for a near-operation-file-invoked plugin to know the depth to use for its import paths.
Hi!
All community plugins (see list below) have been moved to a new dotansimha/graphql-code-generator-community
.
Community plugins:
-
@graphql-codegen/typescript-react-apollo
-
@graphql-codegen/typescript-graphql-request
-
@graphql-codegen/typescript-apollo-angular
-
@graphql-codegen/typescript-apollo-client-helpers
-
@graphql-codegen/typescript-react-query
-
@graphql-codegen/typescript-urql
-
@graphql-codegen/named-operations-object
-
@graphql-codegen/urql-introspection
-
@graphql-codegen/flow-resolvers
-
@graphql-codegen/typescript-vue-apollo
-
@graphql-codegen/typescript-rtk-query
-
@graphql-codegen/flow-operations
-
@graphql-codegen/typescript-msw
-
@graphql-codegen/typescript-mongodb
-
@graphql-codegen/typescript-type-graphql
-
@graphql-codegen/jsdoc
-
@graphql-codegen/typescript-vue-urql
-
@graphql-codegen/kotlin
-
@graphql-codegen/typescript-vue-apollo-smart-ops
-
@graphql-codegen/java
-
@graphql-codegen/c-sharp-operations
-
@graphql-codegen/hasura-allow-list
-
@graphql-codegen/typescript-stencil-apollo
-
@graphql-codegen/relay-operation-optimizer
-
@graphql-codegen/typescript-oclif
-
@graphql-codegen/java-resolvers
-
@graphql-codegen/java-apollo-android
-
@graphql-codegen/flutter-freezed
Please move your PR by following these steps:
From your current PR branch:
- Fork the https://github.com/dotansimha/graphql-code-generator-community repository
- git remote add codegen-community <GIT_URL_OF_YOUR_COMMUNITY_REPO_FORK>
- git fetch codegen-community
- git push codegen-community
Open the PR on dotansimha/graphql-code-generator-community
and close this PR.
Thank you!
thanks for the great work here @kalzoo we have moved this plugin to community repo so let's move it there and then we can consider publishing a canary for you test with https://github.com/dotansimha/graphql-code-generator/pull/4357#issuecomment-1305396802