dgs-codegen icon indicating copy to clipboard operation
dgs-codegen copied to clipboard

Suggestion: Make outputDir configurable instead of fixing it to 'generated'

Open grahamrvvup opened this issue 3 years ago • 3 comments

We'd like to be able to add the generated code to source control so we can still see the history of that code over time. One problem we're having is that we'd like it to fit the usual src/{set}/{language} convention but the outputDir is always set to 'generated' which prevents us from doing that. If that directory could be changed so it could be overridden then we could get it working the way we need but the default could continue to be the existing hard-coded value.

I could put together a quick PR if other people would find it useful?

grahamrvvup avatar Nov 18 '21 17:11 grahamrvvup

I totally agree about configuring outputDir, it's probably useful config. In regards to tracking generated code in src/{set}/{language} I think it's not a good idea. It's better to track changes of .graphqls files and don't depend on generated classes since generated implementation might change in time(without changing interface).

npwork avatar Nov 21 '21 21:11 npwork

I agree with @npwork. In general you want to track the .graphqls files, that said, I understand folks can be hesitant on the generated code, or be pulling the graphqls files dynamically, and therefore want to have a clear understanding on what was generated.

I think that today you should be able to do something like...

generateJava {
    description "Generates Java code based on Rosetta's GraphQL schemas"
    packageName = 'foo.bar.baz'
    generatedSourcesDir = "${projectDir}/src/foo-bar-schema"
}
sourceSets.main.java.srcDirs += ["${projectDir}/src/foo-bar-schema/generated"]

berngp avatar Dec 06 '21 19:12 berngp

I'm not discarding the idea of being able to configure the full path, the question then is how to convey it without making it confusing for folks that use generatedSourcesDir already.

berngp avatar Dec 06 '21 19:12 berngp