New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQL Go 笔记 #25

Open
eyasliu opened this Issue Feb 1, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@eyasliu
Copy link
Owner

eyasliu commented Feb 1, 2019

github.com/graph-gophers/graphql-go 遇到一些坑

框架选型

别人已经对比过了,很详细 https://medium.com/open-graphql/choosing-a-graphql-server-library-in-go-8836f893881b

简单的概括就是:

  • github.com/samsarahq/thunder 用struct 的 tag 定义 schema,回调形式定义resolver
  • github.com/graphql-go/graphql 用配置形式定义 schema,resolve 是其中一个配置项
  • github.com/99designs/gqlgen 单独文件定义schema,并自动生成 resolver,可惜不支持 go module
  • github.com/graph-gophers/graphql-go 单独文件定义 schema,以接口形式实现schema的字段

我要在 go module中单独文件定义schema,只有 gophers 符合

返回类型是否指针

  • 如果字段类型是必填,返回的类型不能为指针,如: String! 需要返回 string 类型
  • 如果字段类型是选填,返回的类型一定为指针,如: String 需要返回 *string 类型

这应该是 string 类型永远都会有值,默认值是 "",但是指针类型可以为 nil,可判断为空

Mutation 和 Query 不能分组

graphql-go 无关,是graphql 的 schema 本身就不支持 将 mutation 和 query 分成多个地方,如果 mutation 比较多的话,估计会比较难以管理,query 的根查询倒是问题不大,目前还没有发现什么好方案

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment