安装 gqlfetch
go install github.com/suessflorian/gqlfetch/gqlfetch@latest
mkdir schema
mkdir operations
拉取 schema
gqlfetch --endpoint "http://192.168.1.204:8088/graphql" > schema/schema.gql
gqlg --schemaFilePath schema/schema.gql --destDirPath operations --depthLimit 5
go mod init gql
go get github.com/Khan/genqlient
go run github.com/Khan/genqlient --init
修改 genqlient.yaml 配置
schema: schema/schema.gql
operations:
- operations/*/*.gql
generated: gen/genqlient.go
package: gql
bindings:
Long:
type: int64
创建 gen.go
//go:generate go run github.com/Khan/genqlient genqlient.yaml
package gen
生成代码
go generate