-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a configuration option to generate embedded types #626
Comments
Do you have any thoughts on what the configuration for this would look like? |
Not quite sure what would be best, I'll just throw some suggestions What about a simple That could be maybe too restrictive, so maybe a completely dedicated option for interfaces: embedded:
- Customer
- Employee or maybe in the top-level object: models:
User:
model: github.com/steebchen/keskin-api/prisma.User
embed:
- Customer
- Employee or separately and specify a type to embed: models:
Customer:
embedded: true or the same as above but more explicit: models:
Customer:
embed: github.com/steebchen/keskin-api/prisma.User
# this should mean generate the model and embed `User` |
An alternative approach would be something like: User:
embed: github.com/steebchen/keskin-api/prisma.User
interface: github.com/steebchen/keskin-api/prisma.IUser Anything implementing the interface would automatically embed the given type, if one is set. Multiple inheritance is a thing too, eg from the spec interface NamedEntity {
name: String
}
interface ValuedEntity {
value: Int
}
type Person implements NamedEntity {
name: String
age: Int
}
type Business implements NamedEntity & ValuedEntity {
name: String
value: Int
employeeCount: Int
} could generate type INamedEntity interface {
IsNamedEntity()
}
type NamedEntityBase struct {
Name string
}
func (NamedEntityBase) IsNamedEntity() {}
type IValuedEntity interface {
IsValuedEntity()
}
type ValuedEntityBase struct {
Value string
}
func (ValuedEntityBase) IsValuedEntity() {}
type Person struct {
*NamedEntityBase
Age int
}
type Business struct {
*NamedEntityBase
*ValuedEntityBase
EmployeeCount int
} @lwc implemented the current interface generation, I wonder if he has thoughts? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Not stale |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Not stale |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Not stale |
Are there any plans to implement this? I'm facing the same issue and it should be an easy task to solve it. Edit: The workaround solution above doesn't work anymore. Gqlgen expects an interface
A possible workaround is to specify an interface interface IUser {
# ...
}
type User implements IUser {
# ...
}
type Customer implements IUser {
# ...
} now, gqlgen correctly generates a User struct |
Created a PR helping with this, it does not cover all possible edge cases, but it's under a configuration flag so it can be turned on on demand and potentially helping in most cases. Hope to get any feedback on the PR and hopefully have this merged asap |
This schema
produces
This works fine, but it's cumbersome to work with when converting from an internal type (e.g.
User
) to aCustomer
orEmployee
.This forces me to declare those types by myself and import them in gqlgen:
This also works fine, but it's a bit annoying to define it manually and importing it manually. It also gets more cumbersome if the schema gets more complex with more user types and more complex schemas (for example when implementing multiple interfaces).
It would be great if there was an option so that embedded structs could be automatically generated.
The text was updated successfully, but these errors were encountered: