热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Resolverreturningtypetobeasliceofstructs

Whathappened?Nowresolversaresupposedtoreturnslicesofpointers


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.





   



推荐阅读
author-avatar
龙帅1314的爱_530
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有