Documentation
¶
Index ¶
- Variables
- func WriteInterfaceTemplate(t, filename string, data TemplateData) error
- func WriteInterfaceTemplateRaw(t, filename string, data interface{}) error
- func WriteTemplate(t, filename string, data TemplateData) error
- func WriteTemplateRaw(t, filename string, data interface{}) error
- type TemplateData
Constants ¶
This section is empty.
Variables ¶
View Source
var Callback = `` /* 1804-byte string literal not displayed */
View Source
var Constants = `package gen
import (
)
type key int
const (
KeyPrincipalID key = iota
KeyLoaders key = iota
KeyExecutableSchema key = iota
KeyJWTClaims key = iota
SchemaSDL string = ` + "`{{.SchemaSDL}}`" + `
)
`
View Source
var Database = `` /* 2598-byte string literal not displayed */
View Source
var Dockerfile = `` /* 647-byte string literal not displayed */
View Source
var DummyModel = `` /* 409-byte string literal not displayed */
View Source
var Federation = `` /* 343-byte string literal not displayed */
View Source
var Filters = `` /* 3922-byte string literal not displayed */
View Source
var GQLGen = `` /* 1274-byte string literal not displayed */
View Source
var GeneratedResolver = `` /* 15113-byte string literal not displayed */
View Source
var Graphql = `` /* 2267-byte string literal not displayed */
View Source
var GraphqlApi = `` /* 1441-byte string literal not displayed */
View Source
var HTTPHandler = `` /* 2982-byte string literal not displayed */
View Source
var Keys = `package gen
import (
)
type key int
const (
KeyPrincipalID key = iota
KeyJWTClaims key = iota
)
`
View Source
var Lambda = `` /* 399-byte string literal not displayed */
View Source
var Loaders = `` /* 1346-byte string literal not displayed */
View Source
var Main = `` /* 2674-byte string literal not displayed */
View Source
var Makefile = `generate:
GO111MODULE=on go run code.aliyun.com/maiguangyang/graphql
reinit:
GO111MODULE=on go run code.aliyun.com/maiguangyang/graphql init
migrate:
DATABASE_URL=mysql://'root:123456@localhost:3306/graphql?charset=utf8mb4&parseTime=True&loc=Local' PORT=8080 go run *.go migrate
run:
DATABASE_URL=mysql://'root:123456@localhost:3306/graphql?charset=utf8mb4&parseTime=True&loc=Local' PORT=8080 go run *.go start --cors
voyager:
docker run --rm -v ` + "`" + `pwd` + "`" + `/gen/schema.graphql:/app/schema.graphql -p 8080:80 graphql/voyager
build-lambda-function:
GO111MODULE=on GOOS=linux go build -o main lambda/main.go && zip lambda.zip main && rm main
test:
GO111MODULE=on go build -o app *.go && DATABASE_URL=sqlite3://test.db ./app migrate && (DATABASE_URL=mysql://'root:123456@localhost:3306/graphql?charset=utf8mb4&parseTime=True&loc=Local' PORT=8080 ./app start& export app_pid=$$! && make test-godog || test_result=$$? && kill $$app_pid && exit $$test_result)
// TODO: add detection of host ip (eg. host.docker.internal) for other OS
test-godog:
docker run --rm --network="host" -v "${PWD}/features:/godog/features" -e GRAPHQL_URL=http://$$(if [[ $${OSTYPE} == darwin* ]]; then echo host.docker.internal;else echo localhost;fi):8080/graphql jakubknejzlik/godog-graphql
`
View Source
var Model = `package gen
import (
"fmt"
"reflect"
"time"
"github.com/99designs/gqlgen/graphql"
"github.com/mitchellh/mapstructure"
)
type NotFoundError struct {
Entity string
}
func (e *NotFoundError) Error() string {
return fmt.Sprintf("%s not found", e.Entity)
}
{{range $object := .Model.ObjectEntities}}
type {{.Name}}ResultType struct {
EntityResultType
}
type {{.Name}} struct {
{{range $col := $object.Columns}}
{{$col.MethodName}} {{$col.GoType}} ` + "`" + `{{$col.ModelTags}}` + "`" + `{{end}}
{{range $rel := $object.Relationships}}
{{$rel.MethodName}} {{$rel.GoType}} ` + "`" + `{{$rel.ModelTags}}` + "`" + `
{{if $rel.Preload}}{{$rel.MethodName}}Preloaded bool ` + "`gorm:\"-\"`" + `{{end}}
{{end}}
}
func (m *{{.Name}}) Is_Entity() {}
{{range $interface := $object.Interfaces}}
func (m *{{$object.Name}}) Is{{$interface}}() {}
{{end}}
type {{.Name}}Changes struct {
{{range $col := $object.Columns}}
{{$col.MethodName}} {{$col.GoType}}{{end}}
{{range $rel := $object.Relationships}}{{if $rel.IsToMany}}
{{$rel.ChangesName}} {{$rel.ChangesType}}{{end}}{{end}}
}
{{end}}
// used to convert map[string]interface{} to EntityChanges struct
func ApplyChanges(changes map[string]interface{}, to interface{}) error {
dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
ErrorUnused: true,
TagName: "json",
Result: to,
ZeroFields: true,
// This is needed to get mapstructure to call the gqlgen unmarshaler func for custom scalars (eg Date)
DecodeHook: func(a reflect.Type, b reflect.Type, v interface{}) (interface{}, error) {
if b == reflect.TypeOf(time.Time{}) {
switch a.Kind() {
case reflect.String:
return time.Parse(time.RFC3339, v.(string))
case reflect.Float64:
return time.Unix(0, int64(v.(float64))*int64(time.Millisecond)), nil
case reflect.Int64:
return time.Unix(0, v.(int64)*int64(time.Millisecond)), nil
default:
return v, fmt.Errorf("Unable to parse date from %v", v)
}
}
if reflect.PtrTo(b).Implements(reflect.TypeOf((*graphql.Unmarshaler)(nil)).Elem()) {
resultType := reflect.New(b)
result := resultType.MethodByName("UnmarshalGQL").Call([]reflect.Value{reflect.ValueOf(v)})
err, _ := result[0].Interface().(error)
return resultType.Elem().Interface(), err
}
return v, nil
},
})
if err != nil {
return err
}
return dec.Decode(changes)
}
`
View Source
var QueryFilters = `` /* 2900-byte string literal not displayed */
View Source
var Resolver = `` /* 1169-byte string literal not displayed */
View Source
var ResolverCore = `` /* 2609-byte string literal not displayed */
View Source
var ResolverExtensions = `` /* 1623-byte string literal not displayed */
View Source
var ResolverFederation = `` /* 3113-byte string literal not displayed */
View Source
var ResolverMutations = `` /* 9584-byte string literal not displayed */
View Source
var ResolverQueries = `` /* 7893-byte string literal not displayed */
View Source
var ResolverSrc = `` /* 608-byte string literal not displayed */
View Source
var ResolverSrcGen = `` /* 1754-byte string literal not displayed */
View Source
var ResultType = `` /* 5688-byte string literal not displayed */
View Source
var Sorting = `` /* 1127-byte string literal not displayed */
Functions ¶
func WriteInterfaceTemplate ¶
func WriteInterfaceTemplate(t, filename string, data TemplateData) error
生成前端接口文档
func WriteInterfaceTemplateRaw ¶
func WriteTemplate ¶
func WriteTemplate(t, filename string, data TemplateData) error
Types ¶
Source Files
¶
- callback.go
- constants.go
- database.go
- dockerfile.go
- dummy-model.go
- federation.go
- filters.go
- generated-resolver.go
- gqlgen.yml.go
- graphql.go
- helpers.go
- http-handler.go
- keys.go
- lambda.go
- loaders.go
- main.go
- makefile.go
- model.go
- query-filter.go
- resolver-core.go
- resolver-extensions.go
- resolver-federation.go
- resolver-mutations.go
- resolver-queries.go
- resolver-src-gen.go
- resolver-src-main.go
- resolver.go
- result-type.go
- sorting.go
Click to show internal directories.
Click to hide internal directories.