microsoft / cppgraphqlgen

C++ GraphQL schema service generator
MIT License
326 stars 46 forks source link

Question on CMake schemagen #299

Closed ckaminski closed 6 months ago

ckaminski commented 6 months ago

Regarding _update_graphql_schemafiles:

Is there a reason it copies the files from the schemagen directory back to the source directory? Is there any solid use case for this?

Am I causing myself future issues if I remove this behavior?

For example, in my project graphql/CMakeLists.txt, if I write:

find_package(cppgraphqlgen CONFIG REQUIRED)

update_graphql_schema_files(graphqllib schema.graphql Schema schema --stubs) 

I notice cmake writes the files to /graphql but then also makes copies in my project graphql/ dir. I was hoping to store some non-generated files, there, but maybe that's just not how this library was envisioned to be used?

Would I not want to build my library from those generated out-of-source schema files when using _add_graphql_schematarget ?

wravery commented 6 months ago

The idea with the CMake utilities is to automate having a separate folder and library target for the generated files. It also favors copying them back to the source directory instead of compiling from the build directory so that not every consumer needs to run, or even install, the generator(s).

Using the CMake utilities is optional, though. If you want to mix generated files with implementation files, or even run the generator separately, you can do that manually, or with your own build logic. This is just that pattern that I find works best for automatically triggering the generator(s) when the schema/query documents change and rebuilding the dependencies of that target.