templates

package
v0.4.24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Constants = `package gen

import (
)

type key int

const (
	KeyPrincipalID      	key    = iota
	KeyLoaders          	key    = iota
	KeyExecutableSchema 	key    = iota
	KeyJWTClaims        	key    = iota
	KeyHTTPRequest          key    = iota
	KeyMutationTransaction	key    = iota
	KeyMutationEvents		key    = iota
	SchemaSDL string = ` + "`{{.SchemaSDL}}`" + `
)
`

Constants ...

View Source
var Database = `` /* 3071-byte string literal not displayed */
View Source
var Dockerfile = `` /* 647-byte string literal not displayed */
View Source
var DummyModel = `` /* 296-byte string literal not displayed */

DummyModel ...

View Source
var EventsController = `` /* 3032-byte string literal not displayed */

EventsController ...

View Source
var Federation = `` /* 382-byte string literal not displayed */

Federation ...

View Source
var Filters = `` /* 5839-byte string literal not displayed */

Filters ...

View Source
var GQLGen = `` /* 1192-byte string literal not displayed */

GQLGen ...

View Source
var HTTPHandler = `` /* 2828-byte string literal not displayed */

HTTPHandler ...

View Source
var Lambda = `` /* 413-byte string literal not displayed */

Lambda ...

View Source
var Loaders = `` /* 1364-byte string literal not displayed */

Loaders ...

View Source
var Main = `` /* 3128-byte string literal not displayed */

Main ...

View Source
var Makefile = `generate:
	GO111MODULE=on go run github.com/novacloudcz/graphql-orm

reinit:
	GO111MODULE=on go run github.com/novacloudcz/graphql-orm init

migrate:
	DATABASE_URL=sqlite3://test.db PORT=8080 go run *.go migrate

automigrate:
	DATABASE_URL=sqlite3://test.db PORT=8080 go run *.go automigrate

run:
	DATABASE_URL=sqlite3://test.db 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 CGO_ENABLED=0 go build -o main lambda/main.go && zip lambda.zip main && rm main

test-sqlite:
	GO111MODULE=on go build -o app *.go && DATABASE_URL=sqlite3://test.db ./app migrate && (ENABLE_DELETE_ALL_RESOLVERS=true DATABASE_URL=sqlite3://test.db PORT=8080 ./app start& export app_pid=$$! && make test-godog || test_result=$$? && kill $$app_pid && exit $$test_result)
test:
	GO111MODULE=on go build -o app *.go && ./app migrate && (ENABLE_DELETE_ALL_RESOLVERS=true 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
`

Makefile ...

View Source
var Migrations = `` /* 1849-byte string literal not displayed */

Migrations ...

View Source
var MigrationsSrc = `` /* 477-byte string literal not displayed */

MigrationsSrc ...

View Source
var Model = `package gen

import (
	"fmt"
	"reflect"
	"time"
	
	"github.com/99designs/gqlgen/graphql"
	"github.com/mitchellh/mapstructure"
)

{{range $object := .Model.ObjectEntities}}

	// {{.Name}}ResultType ...
	type {{.Name}}ResultType struct {
		EntityResultType
	}

	// {{.Name}} ...
	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}}
	}

	// Is_Entity ...
	func (m *{{.Name}}) Is_Entity() {}


	{{range $interface := $object.Interfaces}}
	// Is{{$interface}} ...
	func (m *{{$object.Name}}) Is{{$interface}}() {}
	{{end}}

	// {{.Name}}Changes ...
	type {{.Name}}Changes struct {
		{{range $col := $object.Columns}}
		{{$col.MethodName}} {{$col.InputTypeName}}{{end}}
		{{range $rel := $object.Relationships}}{{if $rel.IsToMany}}
		{{$rel.ChangesName}} {{$rel.ChangesType}}{{end}}{{end}}
	}

	{{range $rel := $object.Relationships}}
		{{if and $rel.IsManyToMany $rel.IsMainRelationshipForManyToMany}}
		// {{$rel.ManyToManyObjectName}} ...
		type {{$rel.ManyToManyObjectName}} struct {
			{{$rel.ForeignKeyDestinationColumn}} string
			{{$rel.InverseRelationship.ForeignKeyDestinationColumn}} string
		}

		// TableName ...
		func ({{$rel.ManyToManyObjectName}}) TableName() string {
			return TableName("{{$rel.ManyToManyJoinTable}}")
		}
		{{end}}
	{{end}}
{{end}}

// ApplyChanges 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)
}
`

Model ...

View Source
var QueryFilters = `` /* 2542-byte string literal not displayed */

QueryFilters ...

View Source
var ResolverCore = `` /* 3134-byte string literal not displayed */

ResolverCore ...

View Source
var ResolverExtensions = `` /* 1667-byte string literal not displayed */

ResolverExtensions ...

View Source
var ResolverFederation = `` /* 3540-byte string literal not displayed */

ResolverFederation ...

View Source
var ResolverMutations = `` /* 9941-byte string literal not displayed */

ResolverMutations ...

View Source
var ResolverQueries = `` /* 11181-byte string literal not displayed */

ResolverQueries ...

View Source
var ResolverSrc = `` /* 557-byte string literal not displayed */

ResolverSrc ...

View Source
var ResolverSrcGen = `` /* 2399-byte string literal not displayed */

ResolverSrcGen ...

View Source
var ResultType = `` /* 7419-byte string literal not displayed */

ResultType ...

View Source
var Sorting = `` /* 1513-byte string literal not displayed */

Sorting ...

Functions

func WriteTemplate

func WriteTemplate(t, filename string, data TemplateData) error

WriteTemplate ...

func WriteTemplateRaw

func WriteTemplateRaw(t, filename string, data interface{}) error

WriteTemplateRaw ...

Types

type TemplateData

type TemplateData struct {
	Model     *model.Model
	Config    *model.Config
	RawSchema *string
}

TemplateData ...

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL