99designs / gqlgen

go generate based graphql server library
https://gqlgen.com
MIT License
9.96k stars 1.17k forks source link

Is it possible to generate resolvers in the same folder with .graphql files #2820

Open gepgecici opened 1 year ago

gepgecici commented 1 year ago

I'm trying to modularize my application. I want to do something like below. Is that possible with configs?

todo/
     service.go
     model_gen.go
     todo.graphql
     todo.resolvers.go
order/
     service.go
     model_gen.go
     logger.go
     user.graphql
     user.resolvers.go
product/
     serviceA.go
     serviiceB.go
     product.go (product model)
     shipping.go (shipping model which is related to product)
     model_gen.go
     product.graphql
     shipping.graphql
     product.resolvers.go
     shipping.resolvers.go
UnAfraid commented 1 year ago

You could do something like that, but the generated code would be separated in models and executable schema, however you can always make the actual resolver implementation in as many files as you like and achieve the same result.

For example: model_gen.go executable_schema_gen.go todo.graphql todo.resolver.graphql product.graphql product.resolver.go shipping.graphql shipping.resolver.go

Here is a personal project of mine in which i separated the resolver implementations in their own packages https://github.com/UnAfraid/wg-ui/blob/master/pkg/api/config.go

gepgecici commented 1 year ago

I would like to put each module/feature/service to its own folder. I couldn't figure out it. Generatted code is not important for me.

NOTE: I update the first message to make it clearer.

duongle-kdnd commented 10 months ago

I have the same concern as you. I tried many ways in the gqlgen.yml file but It seems that we can not configure to generate .resolver.go file in different folders. @gepgecici Generating all of .grahqls and *.resolver.go in the same folder is not good enough for code management and maintenance. Maybe we have to write a shell script to generate them in different folders so that we can modularize features, but not easy. Does anyone have any way? Or Am I missing something?

UnAfraid commented 10 months ago

I have the same concern as you. I tried many ways in the gqlgen.yml file but It seems that we can not configure to generate .resolver.go file in different folders. @gepgecici Generating all of .grahqls and *.resolver.go in the same folder is not good enough for code management and maintenance. Maybe we have to write a shell script to generate them in different folders so that we can modularize features, but not easy. Does anyone have any way? Or Am I missing something?

If you turn off the automatic resolver generation you can make the resolvers in as many folders as you want, all gqlgen does is simply generate the interfaces for you, you can implement them from wherever you want, if you look few comments above in my previous comment there is a link to a personal project of mine in which i did exactly that.