piglovesyou / graphql-let

A webpack loader / babel-plugin / babel-plugin-macros / CLI / generated file manager of GraphQL code generator.
Apache License 2.0
454 stars 34 forks source link

Disable codegen? #549

Open dan-cooke opened 3 years ago

dan-cooke commented 3 years ago

Hi, Is there a way to not run the codegen?

My use case is as follows:

  1. My schema is pointing to a localhost graphql server in development
  2. When I'm developing the codegen runs and generates .d.ts files.
  3. When I want to deploy my changes, I do not want the codegen to run on my CI pipeline, as I will not have a live server to pull the latest schema from.

If I check in the .d.ts files. - is this not enough for graphql-let to work?

piglovesyou commented 3 years ago

Hi! So, you don't have *.graphqls in your source code, but you launch a GraphQL server locally when you develop your project.

My recommendation is to commit schema.graphqls or schema.json in the case, so you can run a codegen command with different .graphql-let.yml. Yes, pushing .d.ts files will also solve the problem, but it'll be tricky since some of .d.ts will be in node_modules.

dan-cooke commented 3 years ago

@piglovesyou thanks for the swift reply!

So I do have .graphql files in my frontend - but they are just for queries and mutations. Not schema definition.

My schema property in graphql-let.yml is pointing to http://localhost:5000 - so everytime I run a build via webpack, the library will ping this endpoint for introspection.

my recommendation is to commit schema.graphqls or schema.json in the case, so you can run a codegen command with different .graphql-let.yml

This was going to be my workaround if we could not come up with a solution in graphql-let. I was trying to avoid this approach however as my backend does not use .graphql files either (uses graphql-compose to generate the schema at runtime)

So here are my options at the minute:

  1. Modify graphql-let so that all it needs to run, is the index.d.ts files, this may involve moving all the index.d.ts files out of node_modules and into a directory which can be checked in - I see a similar issue raised here https://github.com/piglovesyou/graphql-let/issues/487

  2. Spin up my backend server on my CI in order to build my frontend

  3. Generate a schema.json file in my frontend during development and use this for graphql-let when running in CI.

I'm leaning towards option 1 personally, as it ensures a central source of truth for graphql-let. The other 2 introduce possible inconsitencies.

Conclusion

Do you think it would be easy to implement the suggested change? I would be willing to give it a go

paales commented 3 years ago

@dan-cooke You can fairly easily generate a schema.graphqls from your endpoint https://www.graphql-code-generator.com/docs/plugins/schema-ast