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-server and typescript-resolvers. After this change, weโ€™ll have typescript (which includes all types, similar to server and common packages), typescript-client (types for queries, mutations, subscriptions and fragments, based on the typescript types), and typescript-resolvers.
  • Use Pick<> to get the fields from typescript plugin declarations. It also means that we no longer need to generate namespaces.
  • Changes and refactor to the configuration flags.
  • Allow to add __typename automatically to the generated output.
  • Allow scalars config to override every type.
  • Better naming solution, we know that the current solution might be annoying. We still plan to use pascalCase as 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

Most upvoted comments

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

Create schema changes overview. Our app is using graphql-modules and we can generate schemaโ€™s without running the application (so no endpoint needed). It would be nice if we could compare it with the current schema on production (which is also in our codebase). Then in our pipeline we can show this overview without running anything.

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 __typename field 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 __typename to all types, including the โ€œfullโ€ types that are today generated by typescript-server would solve my use-case. I need __typename when 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:

const newProduct: Partial<WithTypename<GqlSchema.Product>> = {
        __typename: "Product",
        id: "theid",
        name: "thename",
        description: "thedescription",
      };
const patch = GqlCachePatch.createEntity<Partial<GqlSchema.Product>>(getObjectId(newProduct), newProduct),

The getObjectId function uses __typename to generate a concatenated unique ID in the flat normalized cache as __typename;obj.id. WithTypename is my current workaround to add __typename. It is simply type WithTypename<T> = T & { readonly __typename: string }; but this is not safe as it is string rahter 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-common and typescript-server packages will be joined into a typescript package. This new package will also somehow be the base for typescript-client. So if the typescript package supports adding __typename then it will be possible to add it everywhere, both to types for query/mutation documents and for full schema types.