You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[rewrite for single-file] add a new flag for enable_rewrite_for_single_file vs. single-file mode overwrites the existing resolver.go but build time breaking experience?
#3205
I wanted to use the rewrite for single-file mode and made direct changes to generateSingleFile. I made changes in very similar fashion to generatePerSchema so it behaved similarly in terms of rewriting the file. However, when I run go generate at the root of gqlgen folder. One of the folder insider _examples broke, specifically type-system-extension.
What did you expect?
I understand that the current generateSingleFile does not support rewriting in single-file mode. Still, I want to integrate resolvergen to a build system that cannot work with generatePerSchema but maintaining the rewrite function is important for large schema changes.
Potential Solution
Can we add a new flag enable_rewrite_for_single_file and build on top of that? By doing so, we will not break any build from the _examples while allowing for some flexibility in using single-file. The default for this flag is false but we can use it by adding to our config file:
Add a new boolean field EnableRewriteForSingleFile inside ResolverConfig struct.
plugin/resolvergen/resolver.go
Add a new generateSingleFileEnableRewrite function with similar rewrite behaviors to generatePerSchema
Inside GenerateCode
func (m *Plugin) GenerateCode(data *codegen.Data) error {
switch data.Config.Resolver.Layout {
case config.LayoutSingleFile:
if data.Config.Resolver.EnableRewriteForSingleFile { // add a conditional statement to use rewrite for single-file
return m.generateSingleFileEnableRewrite(data)
}
return m.generateSingleFile(data)
case config.LayoutFollowSchema:
return m.generatePerSchema(data)
Change file notice: // THIS CODE WILL BE UPDATED WITH SCHEMA CHANGES. PREVIOUS IMPLEMENTATION FOR SCHEMA CHANGES WILL BE KEPT IN THE COMMENT SECTION. IMPLEMENTATION FOR UNCHANGED SCHEMA WILL BE KEPT.
Added unit test and testdata to cover the new function GenerateSingleFileEnableRewrite.
Would appreciate any input! 💡 Thank you for your time.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
What happened?
I wanted to use the
rewrite
for single-file mode and made direct changes togenerateSingleFile
. I made changes in very similar fashion togeneratePerSchema
so it behaved similarly in terms of rewriting the file. However, when I rungo generate
at the root of gqlgen folder. One of the folder insider_examples
broke, specificallytype-system-extension
.What did you expect?
I understand that the current
generateSingleFile
does not support rewriting in single-file mode. Still, I want to integrateresolvergen
to a build system that cannot work withgeneratePerSchema
but maintaining the rewrite function is important for large schema changes.Potential Solution
Can we add a new flag
enable_rewrite_for_single_file
and build on top of that? By doing so, we will not break any build from the_examples
while allowing for some flexibility in using single-file. The default for this flag is false but we can use it by adding to our config file:Potential Implementation
codegen/config/resolver.go
EnableRewriteForSingleFile
insideResolverConfig
struct.plugin/resolvergen/resolver.go
generateSingleFileEnableRewrite
function with similar rewrite behaviors togeneratePerSchema
GenerateCode
// THIS CODE WILL BE UPDATED WITH SCHEMA CHANGES. PREVIOUS IMPLEMENTATION FOR SCHEMA CHANGES WILL BE KEPT IN THE COMMENT SECTION. IMPLEMENTATION FOR UNCHANGED SCHEMA WILL BE KEPT.
testdata
to cover the new functionGenerateSingleFileEnableRewrite
.Would appreciate any input! 💡 Thank you for your time.
Beta Was this translation helpful? Give feedback.
All reactions