eddeee888 / graphql-code-generator-plugins

List of GraphQL Code Generator plugins that complements the official plugins.
MIT License
50 stars 12 forks source link

__typename is required to be set explicitly. #148

Closed lbenevento closed 1 year ago

lbenevento commented 1 year ago

Describe the bug __typename is required to be set explicitly. I'm actually not sure if this is the intended behavior.

To Reproduce Steps to reproduce the behavior: _1. I have just set everything up as per the documentation.

Expected behavior I think the most intuitive approach would be for the __typename property to be inferred based on the type itself.

eddeee888 commented 1 year ago

Hello @lbenevento !

Yes, totally agree with you 🙂

In v0.5, __typename will be optional by default for types, except for union members and interface implementing types.

For now in v0.4, here's how you can make __typename optional:

const config: CodegenConfig = {
  schema: "**/schema.graphql",
  generates: {
    "src/schema": defineConfig({
      typesPluginsConfig: {
        nonOptionalTypename: false, // Note that in v0.5, this will be set automatically
      },
    }),
  },
};

v0.5 is just around the corner 🙂 I'm adding a few features upstream in typescript-resolvers so we are just waiting for this PR to be merged.

Let me know if you have any other questions!

lbenevento commented 1 year ago

Thank you, I did read the documentation but I didn't quite catch that option! I'll use that while waiting for v0.5 to ship. Awesome work! 😁