graphql-code-generator: Planned breaking changes for typescript plugins ๐
Hi,
We are currently planing to refactor and reimplement the typescript plugins.
These changes include:
- Change the scope of the plugins. Today we have
typescript-common,typescript-client,typescript-serverandtypescript-resolvers. After this change, weโll havetypescript(which includes all types, similar to server and common packages),typescript-client(types for queries, mutations, subscriptions and fragments, based on thetypescripttypes), andtypescript-resolvers. - Use
Pick<>to get the fields fromtypescriptplugin declarations. It also means that we no longer need to generatenamespaces. - Changes and refactor to the configuration flags.
- Allow to add
__typenameautomatically to the generated output. - Allow
scalarsconfig to override every type. - Better naming solution, we know that the current solution might be annoying. We still plan to use
pascalCaseas default, but it will be easier and less buggy to override it. - We will try to provide backward compatibility, and it might not be easy.
- Allow to generate internal fields of
graphql. - Tree shaking for all packages
- Cleanup for old code
Please feel free to add to this thread more ideas regarding the typescript package! ๐
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 33
- Comments: 23 (11 by maintainers)
Commits related to this issue
- Refactor TypeScript plugins (#1353) Related: https://github.com/dotansimha/graphql-code-generator/issues/1350 Planned in this PR: - [x] Move all common code from `flow` to a common package. - [... — committed to dotansimha/graphql-code-generator by dotansimha 5 years ago
- Fix Apollo Angular https://github.com/dotansimha/graphql-code-generator/issues/1350#issuecomment-473096132 — committed to dotansimha/graphql-code-generator by ardatan 5 years ago
- Fix `* as` import (#1468) * Fix isGlob import * Fix Apollo Angular https://github.com/dotansimha/graphql-code-generator/issues/1350#issuecomment-473096132 — committed to dotansimha/graphql-code-generator by ardatan 5 years ago
1.0.0 is available now ๐
@NickClark Please open a new issue if something is wrong ๐
Looking over the outputโฆ Good work guys! Also love that Class documents are exported separately now!
Wow this last i totally missed, will run it today. My second thought was about how to generate types per module, but as already discussed it will be hard when modules require other modules. So one file maybe is still best ๐
@maapteh
It feels like this feature it not part of the codegenโs scope, but I think https://github.com/kamilkisiela/graphql-inspector can do this for you ๐
Agreed, the
__typenamefield is a bit special since it is part of the schema in the sense that you can query for it (and I guess that ability is part of the spec). But then again it is not really part of the schema as you donโt declare it in the types.Btw, I just migrated from 0.13 to 0.17 yesterday and I am loving the new config files, so much simpler ๐
Yes, adding
__typenameto all types, including the โfullโ types that are today generated bytypescript-serverwould solve my use-case. I need__typenamewhen I add entities to the client-side cache because I use it to generate the unique ID in the cache. To explain some more, I have this on the client-side:The
getObjectIdfunction uses__typenameto generate a concatenated unique ID in the flat normalized cache as__typename;obj.id.WithTypenameis my current workaround to add__typename. It is simplytype WithTypename<T> = T & { readonly __typename: string };but this is not safe as it isstringrahter than the correct string literal type. I understand my use-case and this example is probably unusual but I hope the example clarifies rather than adds more confusion ๐.My understanding of the outlined plan is that the
typescript-commonandtypescript-serverpackages will be joined into atypescriptpackage. This new package will also somehow be the base fortypescript-client. So if thetypescriptpackage supports adding__typenamethen it will be possible to add it everywhere, both to types for query/mutation documents and for full schema types.