gqlgen: Resolver returning type to be a slice of structs
What happened?
Now resolvers are supposed to return slices of pointers to structs. When using Prisma, their methods always return slices of structs. This means in every method I have to retype the slice to a slice of pointers. Do you know about some way to get around it, or do you think Prisma returning type is to be edited?
What did you expect?
Generated resolvers to be typed to return a slice of structs…
Minimal graphql.schema and models to reproduce
// Cities returns a list of cities
func (r *queryResolver) Cities(
ctx context.Context,
where *prisma.CityWhereInput,
orderBy *prisma.CityOrderByInput,
skip *int,
after *string,
before *string,
first *int,
last *int,
) ([]*prisma.City, error) {
// Returns a slice of structs
result, err := r.Prisma.Cities(&prisma.CitiesParams{
Where: where,
OrderBy: orderBy,
}).Exec(ctx)
// Convert to a slice of pointers
cities := make([]*prisma.City, len(result))
for i := range result {
cities[i] = &result[i]
}
return cities, err
}
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 5
- Comments: 16 (5 by maintainers)
It can be hard to gauge the level of backpressure in some issues. Its a painful migration but most of our code ended up neater for it. I can understand that when working with prisma this is going the other way though.
So lets make it configurable (only for []*Thing vs []Thing, the other pointer changes would be really pervasive). Sorry its taken this long to come to a conclusion.
Stalebots are a cancer of software engineering. Actual problems do not go away just because time has passed; either something is triaged as real, or it hasn’t been triaged yet, and using a bot like that just hopes that things left untriaged fall into the “not a real problem” category.
I would like to second the request to revert/make it configurable. Unlike in case of protobuf, gqlgen lets us use domain models as return types. My domain services rarely return slices of pointers, so now using gqlgen is just about the same as using protobuf (which ironically sounds better, since it’s more consistent, still feels worse from a developer experience point of view)
I’ve run into this too. I think it might be nice to make this configurable behavior both globally and at the field resolver level.
@vektah as an OSS maintainer I know the other side of the story (pressure from the community). Still, it would be nice to know if this is something you would consider (revert (I guess unlikely) or make it configurable) given enough feedback is provided.
If not, I propose to write the reasons down, close and lock this thread and refer to this issue if it comes up in the future.
Consider that the comment, with “commentary”.
Think of it as distributed triage. Triage takes time which I could better spend fixing issues and building features. It doesn’t take much effort to leave a comment every 2 months if an issue is still relevant, does it?
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.