Compile-time code generation
kbrandwijk opened this issue · comments
I have recently started experimenting with compile-time code generation for the bindings that graphql-binding
uses, and I thought that might also be applied to GrAMPS at some point.
Do you have any existing plans to incorporate compile-time code generation?
There aren't any existing plans, but I'd be interested to see what you're working on and whether or not it makes sense within the context of GrAMPS. I don't know much about it, so maybe you could hit me with an article or example so I can learn more about it?
You can have a look at https://github.com/supergraphql/graphql-server-static-ts. It contains two build scripts to process schema imports and to generate the bindings for the schemas. You can have a look at https://github.com/supergraphql/graphql-server-static-ts/blob/master/src/generated/bindings.ts#L201-L365 to see what that actually creates. (Disclaimer: alpha-stage, so the generated file contains some elements that need to be refactored out of there, for now the lines I linked are the relevant part). There is also a JS version.
I would imagine that it would be possible to do the same here. You specify a list of datasources that you want to use at design-time (config file? extension to .graphqlconfig.yml to allow GrAMPS sources?), and it would pre-generate the classes needed.
This looks super cool, and I'm into it, but I think I need to walk through building an example app to fully understand the benefits of this approach.
I think extending .graphqlconfig.yml
to allow GrAMPS data sources would be really handy. (It's on my todo list to get a plugin for the CLI so we can start doing graphql gramps dev
as well. #64)
I'll have another look at the code too, to see how and where this would fit in.