Replies: 11 comments
-
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. |
Beta Was this translation helpful? Give feedback.
-
I would still very much like to see this :) Would save us some boilerplate. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
This is still an issue |
Beta Was this translation helpful? Give feedback.
-
I'm also very interested in this feature. Right now I work around it by having an intermediate "type" with the fields in question. Then have a resolver on this. It is messy because your queries now end up as:
Rather than having the fields directly on foo. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
This is still an issue |
Beta Was this translation helpful? Give feedback.
-
I just ran into this one. @jszwedko did you find out any way to work around it short of duplicating code? |
Beta Was this translation helpful? Give feedback.
-
any update? |
Beta Was this translation helpful? Give feedback.
-
@joaoinc: This is a niche workaround, but in one case I had a model struct that implemented the interface, and the other models that implement the interface embedded the struct. The interface included a method to get a pointer of the embedded type. This captures all of the generated resolver fields. Then for the fields that need manual resolvers, I call the generic's resolver method to avoid duplication. Schema interface Foo { field: String! }
type GenericFoo implements Foo { ... }
type SpecialFoo implements Foo { ... } Models type Foo interface {
Base() *GenericFoo
}
// GenericFoo implements Foo
type GenericFoo struct {}
type SpecialFoo struct { *GenericFoo } Resolvers func (r *specialFooResolver) Field(ctx context.Context, obj *models.SpecialFoo) (string, error) {
gr := &genericFooResolver{Resolver: r.Resolver}
return gr.Field(ctx, obj.GenericFoo)
}
func (r *genericFooResolver) Field(ctx context.Context, obj *models.GenericFoo) (string, error) {
panic("not implemented")
} I came here looking for a solution for types where the type that is embedded isn't the interface, since they almost always have the same resolver in my project. I'm thinking I'll define the generic resolver methods elsewhere and call them in each instance. |
Beta Was this translation helpful? Give feedback.
-
Expected Behaviour
I'd like to be able to specify that a field resolver should be generated on a GraphQL
interface
type.The purpose of this is to reduce duplication of code for resolved fields that are resolved in the same way for all types implementing the interface.
If possible, it could look for a field resolver on the concrete type, and, if it finds none, fall back to the resolver on the interface type to allow overriding it in the cases where you might want to. For my particular use case, I have no need to override the field resolver on the interface type as they are all resolved in the same way for all implementations of the interface.
Actual Behavior
Right now, I have to specify that a resolver should be generated on the fields of each GraphQL
type
implementing the interface. This results in some duplication as, in my case, the shared fields are all resolved in the same fashion.Minimal graphql.schema and models to reproduce
This is a simplified use case of ours (we have types modeling data sources that all share some configuration).
schema.graphql
gqlgen.yml
resolver.go generated
You'll note that no
ShapeResolver
type is generated.Beta Was this translation helpful? Give feedback.
All reactions