作者:龙帅1314的爱_530 | 来源:互联网 | 2023-07-14 17:00
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| // 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
} |
该提问来源于开源项目:99designs/gqlgen
No problem.