graphql-java-codegen icon indicating copy to clipboard operation
graphql-java-codegen copied to clipboard

Introduce sub-packages for generated models

Open donbeave opened this issue 3 years ago • 7 comments

Is your feature request related to a problem? Please describe. When the project is big and the GraphQL schema is huge the amount of generated classes inside one single package is enormous. For such projects, it's difficult to use IDE to find a specific class. I think it will be better if we will add an ability to separate generated files by groups (sub-packages), for example, inputs will to the package inputs, enums to enums, types to types, etc. And as well can introduce supports defining sub-packages by using directive on top of the entity.

donbeave avatar Apr 12 '21 20:04 donbeave

@kobylynskyi what do you think about this concept?

donbeave avatar Apr 12 '21 20:04 donbeave

This is similar to a problem I mentioned earlier https://github.com/kobylynskyi/graphql-java-codegen/issues/289, mainly considering that package management will become extremely complex (Because this library uses a common import instead of a full class name like grpc. Maybe this is a place that needs to be improved in the future. Truth to tell, there are some problems with common import.).

Best practice: it may take the graphql specification to support package declaration to make the third-party library better implemented.

jxnu-liguobin avatar Apr 13 '21 03:04 jxnu-liguobin

I like the idea, but my main concern is how to gracefully manage cross-package imports. Need to think about this a bit more, but in general, the feature request is ok to me.

@jxnu-liguobin, true! Looks like the topic from #289 brought up again 😄

kobylynskyi avatar Apr 16 '21 12:04 kobylynskyi

Personally, I am not a fan of having types together with just the types. I would like to have items grouped by their use case. So, things related to each other should be in a package.

I noticed there is a proposal for namespace support (https://github.com/graphql/graphql-spec/issues/163) but it does not seem to be really active.

robbertnoordzij avatar Apr 21 '21 15:04 robbertnoordzij

Yes, but at present, we can only store the schemas in different files according to requirements. Unless graphql/graphql-spec#163 proposal can be accepted by graphql-java.

jxnu-liguobin avatar Apr 22 '21 09:04 jxnu-liguobin

So you would suggest something like a mapping from schema to package?

users.schema > com.kobylynskyi.graphql.users products.schema > com.kobylynskyi.graphql.products

robbertnoordzij avatar Apr 22 '21 14:04 robbertnoordzij

@robbertnoordzij, you can already do that. Check https://github.com/kobylynskyi/graphql-java-codegen/tree/master/plugins/gradle#different-configurations-for-graphql-schemas

kobylynskyi avatar Apr 22 '21 15:04 kobylynskyi

Closing due to inactivity

kobylynskyi avatar Mar 18 '23 05:03 kobylynskyi