Prisma Go client to return slices of pointers to structs

prisma

#1

Hi,

Right now I am using gqlgen to generate my resolvers. The library now generates resolvers that expect to return a slice of pointers, but Prisma returns a slice of stucts. I am here to ask how do you think this should be solved. I think there should be an agreement on the from both libs as retyping it is pain in the butt, especially in Go without generics.

Here is an example of what I talk about:

func (r *cityResolver) Locations(ctx context.Context, obj *prisma.City, where *prisma.LocationWhereInput, orderBy *prisma.LocationOrderByInput, skip *int, after *string, before *string, first *int, last *int) ([]*prisma.Location, error) {

    results, err := r.Prisma.Locations(&prisma.LocationsParams{
        Where: where,
        OrderBy: orderBy,
    }).Exec(ctx)

    locations := make([]*prisma.Location, len(results))
    for i := range results {
       locations[i] = &results[i]
    }

    return locations, err

}

#2

Bump. Running into this same issue


#3

You can mark the location elements to not be nil in your gqlgen schema. This will generate the resolver to return references instead of pointers.

type City {
  locations: [Location!]!
  ...
}

#4

This is unfortunately not true anymore with gqlgen 0.9.0…