cometkim / gatsby-plugin-typegen

Let's give developers using GatsbyJS better DX with extreme type-safety
https://www.gatsbyjs.org/packages/gatsby-plugin-typegen/
MIT License
204 stars 25 forks source link

content model changes are not picked up for type generation #82

Closed nibtime closed 4 years ago

nibtime commented 4 years ago

First of all, thanks for providing this awesome plugin!

Schema and type generation works perfectly and is very fast. The only thing that doesn't seem to work is picking up content model changes (i.e. Markdown). If I add, alter or remove a Markdown frontmatter field while running gatsby develop, the change is reflected in the remote schema at localhost:8000/___graphql, but generated schemas by gatsby-plugin-typegen are not updated, that only happens once when executing gatsby develop. If I just remove and add known properties from queries or fragments, type generation works instantly as expected.

I use the plugin together with the Apollo VS Code extension and consume the remote schema at localhost:8000/___graphql instead of the generated schema file in apollo.config.js to get IntelliSense for content model updates. However, type generation of the plugin fails, because it seems to not know about the schema update:

[typegen] An error on codegen
    GraphQLDocumentError: Cannot query field "testValue" on type "MarkdownRemarkFrontmatterForm".

  AggregateError: GraphQLDocumentError: Cannot query field "testValue" on type "MarkdownRemarkFrontmatterForm".

  - validate-documents.js:53 Object.checkValidationErrors
    [iacm-site]/[gatsby-plugin-typegen]/[@graphql-codegen]/core/dist/common/src/validate-documents.js:53:15

  - codegen.js:63 codegen
    [iacm-site]/[gatsby-plugin-typegen]/dist/graphql-codegen-core/src/codegen.js:63:9

Is it intentional that schema updates only happen at startup (e.g. performance reasons) or is this due to some misconfiguration by me or a bug?

cometkim commented 4 years ago

Hello @nibtime, thank you for reporting this!

Schema registration is currently happening only once the startup. I just couldn't consider the schema change scenario (forgot that the remark source changes it dynamically in runtime :sweat_smile:)

I'll fix it in the right next version! #79

cometkim commented 4 years ago

Hey @nibtime, I just fixed this and published v2.2.0

Hope you enjoy :)

nibtime commented 4 years ago

@cometkim

wow, that was fast! 😄. Thank you very much!