Documentation ¶
Index ¶
- Variables
- func Makefile(tableName string) string
- func Prompt(text string) string
- func RunInteractive(cmd string) error
- func RunInteractiveInDir(cmd, dir string) error
- 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
- func WriterOriginalFile(data interface{}, filename string) error
- type TemplateData
Constants ¶
This section is empty.
Variables ¶
View Source
var AuthHandler = `` /* 993-byte string literal not displayed */
View Source
var AuthJWT = `` /* 1800-byte string literal not displayed */
View Source
var AuthOpenRouters = `package auth
var NoAuthRoutes = []string{
"__schema",
"Schema",
}`
View Source
var AuthRouter = `` /* 1010-byte string literal not displayed */
View Source
var Constants = `` /* 253-byte string literal not displayed */
View Source
var Database = `` /* 2503-byte string literal not displayed */
View Source
var DummyModel = `` /* 938-byte string literal not displayed */
View Source
var Encrypt = `` /* 2106-byte string literal not displayed */
View Source
var EnumsConst = `` /* 167-byte string literal not displayed */
View Source
var Filters = `` /* 3929-byte string literal not displayed */
View Source
var Func = `` /* 1408-byte string literal not displayed */
View Source
var GQLGen = `` /* 1081-byte string literal not displayed */
View Source
var Gitignore = `
.vscode
go.sum
`
View Source
var Graphql = `` /* 2334-byte string literal not displayed */
View Source
var GraphqlApi = `` /* 3647-byte string literal not displayed */
View Source
var HandlerHtml = Playground + "`" + Html + "`))" + Func
View Source
var Html = `<!DOCTYPE html>
<html>
<head>
<title>{{.title}}</title>
<link
rel="stylesheet"
href="https://cdn.bootcdn.net/ajax/libs/graphiql/` + graphiqlVersion + `/graphiql.min.css"
/>
</head>
<body style="margin: 0;">
<div id="graphiql" style="height: 100vh;"></div>
<script
src="https://cdn.bootcdn.net/ajax/libs/react/` + reactVersion + `/umd/react.production.min.js"
></script>
<script
src="https://cdn.bootcdn.net/ajax/libs/react-dom/` + reactVersion + `/umd/react-dom.production.min.js"
></script>
<script
src="https://cdn.bootcdn.net/ajax/libs/graphiql/` + graphiqlVersion + `/graphiql.min.js"
></script>
<script>
{{- if .endpointIsAbsolute}}
const url = {{.endpoint}};
const subscriptionUrl = {{.subscriptionEndpoint}};
{{- else}}
const url = location.protocol + '//' + location.host + {{.endpoint}};
const wsProto = location.protocol == 'https:' ? 'wss:' : 'ws:';
const subscriptionUrl = wsProto + '//' + location.host + {{.endpoint}};
{{- end}}
const fetcher = GraphiQL.createFetcher({ url, subscriptionUrl });
ReactDOM.render(
React.createElement(GraphiQL, {
fetcher: fetcher,
tabs: true,
headerEditorEnabled: true,
shouldPersistHeaders: true
}),
document.getElementById('graphiql'),
);
</script>
</body>
</html>
`
View Source
var HttpHandler = `` /* 2814-byte string literal not displayed */
View Source
var Loaders = `` /* 3919-byte string literal not displayed */
View Source
var Main = `` /* 2389-byte string literal not displayed */
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}}
{{$rel.MethodName}} {{$rel.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 Playground = `package gen
import (
"html/template"
"net/http"
"net/url"
)
var page = template.Must(template.New("graphiql").Parse(`
View Source
var QueryFilters = `` /* 2429-byte string literal not displayed */
View Source
var ResolverCore = `` /* 2176-byte string literal not displayed */
View Source
var ResolverEvents = `` /* 5714-byte string literal not displayed */
View Source
var ResolverMutations = `` /* 20462-byte string literal not displayed */
View Source
var ResolverQueries = `` /* 9506-byte string literal not displayed */
View Source
var ResolverSrc = `` /* 801-byte string literal not displayed */
View Source
var ResolverSrcConfig = `` /* 174-byte string literal not displayed */
View Source
var ResolverSrcGen = `` /* 1846-byte string literal not displayed */
View Source
var ResolverSrcUtils = `` /* 1835-byte string literal not displayed */
View Source
var ResolverUtils = `` /* 4400-byte string literal not displayed */
View Source
var ResultType = `` /* 3792-byte string literal not displayed */
View Source
var Rsa = `` /* 4262-byte string literal not displayed */
View Source
var Rule = `` /* 1262-byte string literal not displayed */
View Source
var Sorting = `` /* 1043-byte string literal not displayed */
View Source
var UpLoad = `` /* 1797-byte string literal not displayed */
View Source
var UploadModel = `` /* 419-byte string literal not displayed */
View Source
var Validator = `` /* 4487-byte string literal not displayed */
Functions ¶
func WriteInterfaceTemplate ¶
func WriteInterfaceTemplate(t, filename string, data TemplateData) error
生成前端接口文档
func WriteTemplate ¶
func WriteTemplate(t, filename string, data TemplateData) error
func WriteTemplateRaw ¶
func WriterOriginalFile ¶
Types ¶
Source Files ¶
- auth-handler.go
- auth-jwt.go
- auth-open-routes.go
- auth-router.go
- constants.go
- database.go
- dummy-model.go
- encrypt.go
- filters.go
- gitignore.go
- gqlgen.yml.go
- graphql.go
- helpers.go
- html.go
- http-handler.go
- loaders.go
- main.go
- makefile.go
- model.go
- query-filter.go
- resolver-core.go
- resolver-enums-const.go
- resolver-events.go
- resolver-mutations.go
- resolver-queries.go
- resolver-src-config.go
- resolver-src-gen.go
- resolver-src-main.go
- resolver-src-upload.go
- resolver-src-utils.go
- resolver-utils.go
- result-type.go
- rsa.go
- sorting.go
- upload-model.go
- utils-rule.go
- utils-validator.go
Click to show internal directories.
Click to hide internal directories.