From d571deef57b682f92e71f9374c2c59893db811af Mon Sep 17 00:00:00 2001 From: Amine Hilaly Date: Sat, 17 Aug 2019 00:48:08 +0200 Subject: vendor: upgrade github.com/99designs/gqlgen to v0.9.2 --- .../github.com/99designs/gqlgen/codegen/args.gotpl | 4 +++ .../99designs/gqlgen/codegen/config/config.go | 38 ++++++++++++---------- vendor/github.com/99designs/gqlgen/codegen/data.go | 5 +-- .../github.com/99designs/gqlgen/codegen/field.go | 14 ++++---- .../99designs/gqlgen/codegen/field.gotpl | 5 +++ .../99designs/gqlgen/codegen/input.gotpl | 4 +++ .../github.com/99designs/gqlgen/codegen/object.go | 3 +- .../99designs/gqlgen/codegen/templates/import.go | 3 +- .../gqlgen/codegen/templates/templates.go | 14 ++++---- vendor/github.com/99designs/gqlgen/codegen/type.go | 4 +-- .../gqlgen/graphql/introspection/schema.go | 18 +++++----- .../github.com/99designs/gqlgen/graphql/version.go | 2 +- .../99designs/gqlgen/handler/websocket.go | 7 ++-- .../99designs/gqlgen/internal/code/imports.go | 9 ++--- .../99designs/gqlgen/internal/imports/prune.go | 9 ++--- .../99designs/gqlgen/plugin/modelgen/models.gotpl | 2 +- 16 files changed, 76 insertions(+), 65 deletions(-) (limited to 'vendor/github.com/99designs') diff --git a/vendor/github.com/99designs/gqlgen/codegen/args.gotpl b/vendor/github.com/99designs/gqlgen/codegen/args.gotpl index c76bf0f7..318f1ff4 100644 --- a/vendor/github.com/99designs/gqlgen/codegen/args.gotpl +++ b/vendor/github.com/99designs/gqlgen/codegen/args.gotpl @@ -14,6 +14,10 @@ func (ec *executionContext) {{ $name }}(ctx context.Context, rawArgs map[string] } if data, ok := tmp.({{ $arg.TypeReference.GO | ref }}) ; ok { arg{{$i}} = data + {{- if $arg.TypeReference.IsNilable }} + } else if tmp == nil { + arg{{$i}} = nil + {{- end }} } else { return nil, fmt.Errorf(`unexpected type %T from directive, should be {{ $arg.TypeReference.GO }}`, tmp) } diff --git a/vendor/github.com/99designs/gqlgen/codegen/config/config.go b/vendor/github.com/99designs/gqlgen/codegen/config/config.go index c7a7d4d8..8e8992e3 100644 --- a/vendor/github.com/99designs/gqlgen/codegen/config/config.go +++ b/vendor/github.com/99designs/gqlgen/codegen/config/config.go @@ -16,7 +16,7 @@ import ( "github.com/pkg/errors" "github.com/vektah/gqlparser" "github.com/vektah/gqlparser/ast" - yaml "gopkg.in/yaml.v2" + "gopkg.in/yaml.v2" ) type Config struct { @@ -38,17 +38,7 @@ func DefaultConfig() *Config { SchemaFilename: StringList{"schema.graphql"}, Model: PackageConfig{Filename: "models_gen.go"}, Exec: PackageConfig{Filename: "generated.go"}, - Directives: map[string]DirectiveConfig{ - "skip": { - SkipRuntime: true, - }, - "include": { - SkipRuntime: true, - }, - "deprecated": { - SkipRuntime: true, - }, - }, + Directives: map[string]DirectiveConfig{}, } } @@ -87,6 +77,18 @@ func LoadConfig(filename string) (*Config, error) { return nil, errors.Wrap(err, "unable to parse config") } + defaultDirectives := map[string]DirectiveConfig{ + "skip": {SkipRuntime: true}, + "include": {SkipRuntime: true}, + "deprecated": {SkipRuntime: true}, + } + + for key, value := range defaultDirectives { + if _, defined := config.Directives[key]; !defined { + config.Directives[key] = value + } + } + preGlobbing := config.SchemaFilename config.SchemaFilename = StringList{} for _, f := range preGlobbing { @@ -308,10 +310,10 @@ func (tm TypeMap) ReferencedPackages() []string { return pkgs } -func (tm TypeMap) Add(Name string, goType string) { - modelCfg := tm[Name] +func (tm TypeMap) Add(name string, goType string) { + modelCfg := tm[name] modelCfg.Model = append(modelCfg.Model, goType) - tm[Name] = modelCfg + tm[name] = modelCfg } type DirectiveConfig struct { @@ -457,9 +459,9 @@ func (c *Config) InjectBuiltins(s *ast.Schema) { func (c *Config) LoadSchema() (*ast.Schema, map[string]string, error) { schemaStrings := map[string]string{} - var sources []*ast.Source + sources := make([]*ast.Source, len(c.SchemaFilename)) - for _, filename := range c.SchemaFilename { + for i, filename := range c.SchemaFilename { filename = filepath.ToSlash(filename) var err error var schemaRaw []byte @@ -469,7 +471,7 @@ func (c *Config) LoadSchema() (*ast.Schema, map[string]string, error) { os.Exit(1) } schemaStrings[filename] = string(schemaRaw) - sources = append(sources, &ast.Source{Name: filename, Input: schemaStrings[filename]}) + sources[i] = &ast.Source{Name: filename, Input: schemaStrings[filename]} } schema, err := gqlparser.LoadSchema(sources...) diff --git a/vendor/github.com/99designs/gqlgen/codegen/data.go b/vendor/github.com/99designs/gqlgen/codegen/data.go index 98d2ec88..f743dee3 100644 --- a/vendor/github.com/99designs/gqlgen/codegen/data.go +++ b/vendor/github.com/99designs/gqlgen/codegen/data.go @@ -123,10 +123,7 @@ func BuildData(cfg *config.Config) (*Data, error) { return nil, err } - s.ReferencedTypes, err = b.buildTypes() - if err != nil { - return nil, err - } + s.ReferencedTypes = b.buildTypes() sort.Slice(s.Objects, func(i, j int) bool { return s.Objects[i].Definition.Name < s.Objects[j].Definition.Name diff --git a/vendor/github.com/99designs/gqlgen/codegen/field.go b/vendor/github.com/99designs/gqlgen/codegen/field.go index 264b59ce..fab26f2b 100644 --- a/vendor/github.com/99designs/gqlgen/codegen/field.go +++ b/vendor/github.com/99designs/gqlgen/codegen/field.go @@ -384,16 +384,16 @@ func (f *Field) ComplexitySignature() string { } func (f *Field) ComplexityArgs() string { - var args []string - for _, arg := range f.Args { - args = append(args, "args["+strconv.Quote(arg.Name)+"].("+templates.CurrentImports.LookupType(arg.TypeReference.GO)+")") + args := make([]string, len(f.Args)) + for i, arg := range f.Args { + args[i] = "args[" + strconv.Quote(arg.Name) + "].(" + templates.CurrentImports.LookupType(arg.TypeReference.GO) + ")" } return strings.Join(args, ", ") } func (f *Field) CallArgs() string { - var args []string + args := make([]string, 0, len(f.Args)+2) if f.IsResolver { args = append(args, "rctx") @@ -401,10 +401,8 @@ func (f *Field) CallArgs() string { if !f.Object.Root { args = append(args, "obj") } - } else { - if f.MethodHasContext { - args = append(args, "ctx") - } + } else if f.MethodHasContext { + args = append(args, "ctx") } for _, arg := range f.Args { diff --git a/vendor/github.com/99designs/gqlgen/codegen/field.gotpl b/vendor/github.com/99designs/gqlgen/codegen/field.gotpl index c0f6fcae..1970614b 100644 --- a/vendor/github.com/99designs/gqlgen/codegen/field.gotpl +++ b/vendor/github.com/99designs/gqlgen/codegen/field.gotpl @@ -107,6 +107,11 @@ if data, ok := tmp.({{ .TypeReference.GO | ref }}) ; ok { return data, nil } + {{- if .TypeReference.IsNilable -}} + else if tmp == nil { + return nil, nil + } + {{- end }} return nil, fmt.Errorf(`unexpected type %T from directive, should be {{ .TypeReference.GO }}`, tmp) {{- else -}} ctx = rctx // use context from middleware stack in children diff --git a/vendor/github.com/99designs/gqlgen/codegen/input.gotpl b/vendor/github.com/99designs/gqlgen/codegen/input.gotpl index b51d53a2..bdf3622c 100644 --- a/vendor/github.com/99designs/gqlgen/codegen/input.gotpl +++ b/vendor/github.com/99designs/gqlgen/codegen/input.gotpl @@ -25,6 +25,10 @@ } if data, ok := tmp.({{ $field.TypeReference.GO | ref }}) ; ok { it.{{$field.GoFieldName}} = data + {{- if $field.TypeReference.IsNilable }} + } else if tmp == nil { + it.{{$field.GoFieldName}} = nil + {{- end }} } else { return it, fmt.Errorf(`unexpected type %T from directive, should be {{ $field.TypeReference.GO }}`, tmp) } diff --git a/vendor/github.com/99designs/gqlgen/codegen/object.go b/vendor/github.com/99designs/gqlgen/codegen/object.go index 539c3164..08ae09aa 100644 --- a/vendor/github.com/99designs/gqlgen/codegen/object.go +++ b/vendor/github.com/99designs/gqlgen/codegen/object.go @@ -114,8 +114,7 @@ func (o *Object) HasUnmarshal() bool { return true } for i := 0; i < o.Type.(*types.Named).NumMethods(); i++ { - switch o.Type.(*types.Named).Method(i).Name() { - case "UnmarshalGQL": + if o.Type.(*types.Named).Method(i).Name() == "UnmarshalGQL" { return true } } diff --git a/vendor/github.com/99designs/gqlgen/codegen/templates/import.go b/vendor/github.com/99designs/gqlgen/codegen/templates/import.go index effe9a0d..d5bd16a6 100644 --- a/vendor/github.com/99designs/gqlgen/codegen/templates/import.go +++ b/vendor/github.com/99designs/gqlgen/codegen/templates/import.go @@ -4,6 +4,7 @@ import ( "fmt" "go/types" "strconv" + "strings" "github.com/99designs/gqlgen/internal/code" ) @@ -20,7 +21,7 @@ type Imports struct { } func (i *Import) String() string { - if i.Alias == i.Name { + if strings.HasSuffix(i.Path, i.Alias) { return strconv.Quote(i.Path) } diff --git a/vendor/github.com/99designs/gqlgen/codegen/templates/templates.go b/vendor/github.com/99designs/gqlgen/codegen/templates/templates.go index f2fcb568..5d5f69bf 100644 --- a/vendor/github.com/99designs/gqlgen/codegen/templates/templates.go +++ b/vendor/github.com/99designs/gqlgen/codegen/templates/templates.go @@ -285,7 +285,8 @@ func ToGoPrivate(name string) string { first := true wordWalker(name, func(info *wordInfo) { word := info.Word - if first { + switch { + case first: if strings.ToUpper(word) == word || strings.ToLower(word) == word { // ID → id, CAMEL → camel word = strings.ToLower(info.Word) @@ -294,9 +295,9 @@ func ToGoPrivate(name string) string { word = lcFirst(info.Word) } first = false - } else if info.MatchCommonInitial { + case info.MatchCommonInitial: word = strings.ToUpper(word) - } else if !info.HasCommonInitial { + case !info.HasCommonInitial: word = ucFirst(strings.ToLower(word)) } runes = append(runes, []rune(word)...) @@ -319,9 +320,10 @@ func wordWalker(str string, f func(*wordInfo)) { hasCommonInitial := false for i+1 <= len(runes) { eow := false // whether we hit the end of a word - if i+1 == len(runes) { + switch { + case i+1 == len(runes): eow = true - } else if isDelimiter(runes[i+1]) { + case isDelimiter(runes[i+1]): // underscore; shift the remainder forward over any run of underscores eow = true n := 1 @@ -336,7 +338,7 @@ func wordWalker(str string, f func(*wordInfo)) { copy(runes[i+1:], runes[i+n+1:]) runes = runes[:len(runes)-n] - } else if unicode.IsLower(runes[i]) && !unicode.IsLower(runes[i+1]) { + case unicode.IsLower(runes[i]) && !unicode.IsLower(runes[i+1]): // lower->non-lower eow = true } diff --git a/vendor/github.com/99designs/gqlgen/codegen/type.go b/vendor/github.com/99designs/gqlgen/codegen/type.go index e0083732..4a14454c 100644 --- a/vendor/github.com/99designs/gqlgen/codegen/type.go +++ b/vendor/github.com/99designs/gqlgen/codegen/type.go @@ -4,7 +4,7 @@ import ( "github.com/99designs/gqlgen/codegen/config" ) -func (b *builder) buildTypes() (map[string]*config.TypeReference, error) { +func (b *builder) buildTypes() map[string]*config.TypeReference { ret := map[string]*config.TypeReference{} for _, ref := range b.Binder.References { @@ -14,5 +14,5 @@ func (b *builder) buildTypes() (map[string]*config.TypeReference, error) { ref = ref.Elem() } } - return ret, nil + return ret } diff --git a/vendor/github.com/99designs/gqlgen/graphql/introspection/schema.go b/vendor/github.com/99designs/gqlgen/graphql/introspection/schema.go index b5d2c482..a57272d5 100644 --- a/vendor/github.com/99designs/gqlgen/graphql/introspection/schema.go +++ b/vendor/github.com/99designs/gqlgen/graphql/introspection/schema.go @@ -11,7 +11,7 @@ type Schema struct { } func (s *Schema) Types() []Type { - var types []Type + types := make([]Type, 0, len(s.schema.Types)) for _, typ := range s.schema.Types { if strings.HasPrefix(typ.Name, "__") { continue @@ -34,7 +34,7 @@ func (s *Schema) SubscriptionType() *Type { } func (s *Schema) Directives() []Directive { - var res []Directive + res := make([]Directive, 0, len(s.schema.Directives)) for _, d := range s.schema.Directives { res = append(res, s.directiveFromDef(d)) @@ -44,19 +44,19 @@ func (s *Schema) Directives() []Directive { } func (s *Schema) directiveFromDef(d *ast.DirectiveDefinition) Directive { - var locs []string - for _, loc := range d.Locations { - locs = append(locs, string(loc)) + locs := make([]string, len(d.Locations)) + for i, loc := range d.Locations { + locs[i] = string(loc) } - var args []InputValue - for _, arg := range d.Arguments { - args = append(args, InputValue{ + args := make([]InputValue, len(d.Arguments)) + for i, arg := range d.Arguments { + args[i] = InputValue{ Name: arg.Name, Description: arg.Description, DefaultValue: defaultValue(arg.DefaultValue), Type: WrapTypeFromType(s.schema, arg.Type), - }) + } } return Directive{ diff --git a/vendor/github.com/99designs/gqlgen/graphql/version.go b/vendor/github.com/99designs/gqlgen/graphql/version.go index 3c5e65d6..ea211574 100644 --- a/vendor/github.com/99designs/gqlgen/graphql/version.go +++ b/vendor/github.com/99designs/gqlgen/graphql/version.go @@ -1,3 +1,3 @@ package graphql -const Version = "v0.9.1" +const Version = "v0.9.2" diff --git a/vendor/github.com/99designs/gqlgen/handler/websocket.go b/vendor/github.com/99designs/gqlgen/handler/websocket.go index 07a1a8c2..0637cfb1 100644 --- a/vendor/github.com/99designs/gqlgen/handler/websocket.go +++ b/vendor/github.com/99designs/gqlgen/handler/websocket.go @@ -103,6 +103,7 @@ func (c *wsConnection) init() bool { } c.write(&operationMessage{Type: connectionAckMsg}) + c.write(&operationMessage{Type: connectionKeepAliveMsg}) case connectionTerminateMsg: c.close(websocket.CloseNormalClosure, "terminated") return false @@ -279,9 +280,9 @@ func (c *wsConnection) sendData(id string, response *graphql.Response) { } func (c *wsConnection) sendError(id string, errors ...*gqlerror.Error) { - var errs []error - for _, err := range errors { - errs = append(errs, err) + errs := make([]error, len(errors)) + for i, err := range errors { + errs[i] = err } b, err := json.Marshal(errs) if err != nil { diff --git a/vendor/github.com/99designs/gqlgen/internal/code/imports.go b/vendor/github.com/99designs/gqlgen/internal/code/imports.go index 75c30fe1..ad62f7c5 100644 --- a/vendor/github.com/99designs/gqlgen/internal/code/imports.go +++ b/vendor/github.com/99designs/gqlgen/internal/code/imports.go @@ -62,22 +62,23 @@ func ImportPathForDir(dir string) (res string) { modDir := dir assumedPart := "" for { - f, err := ioutil.ReadFile(filepath.Join(modDir, "/", "go.mod")) + f, err := ioutil.ReadFile(filepath.Join(modDir, "go.mod")) if err == nil { // found it, stop searching return string(modregex.FindSubmatch(f)[1]) + assumedPart } assumedPart = "/" + filepath.Base(modDir) + assumedPart - modDir, err = filepath.Abs(filepath.Join(modDir, "..")) + parentDir, err := filepath.Abs(filepath.Join(modDir, "..")) if err != nil { panic(err) } - // Walked all the way to the root and didnt find anything :'( - if modDir == "/" { + if parentDir == modDir { + // Walked all the way to the root and didnt find anything :'( break } + modDir = parentDir } for _, gopath := range gopaths { diff --git a/vendor/github.com/99designs/gqlgen/internal/imports/prune.go b/vendor/github.com/99designs/gqlgen/internal/imports/prune.go index d678870e..27ac94ac 100644 --- a/vendor/github.com/99designs/gqlgen/internal/imports/prune.go +++ b/vendor/github.com/99designs/gqlgen/internal/imports/prune.go @@ -32,10 +32,7 @@ func Prune(filename string, src []byte) ([]byte, error) { return nil, err } - unused, err := getUnusedImports(file, filename) - if err != nil { - return nil, err - } + unused := getUnusedImports(file) for ipath, name := range unused { astutil.DeleteNamedImport(fset, file, name, ipath) } @@ -49,7 +46,7 @@ func Prune(filename string, src []byte) ([]byte, error) { return imports.Process(filename, buf.Bytes(), &imports.Options{FormatOnly: true, Comments: true, TabIndent: true, TabWidth: 8}) } -func getUnusedImports(file ast.Node, filename string) (map[string]string, error) { +func getUnusedImports(file ast.Node) map[string]string { imported := map[string]*ast.ImportSpec{} used := map[string]bool{} @@ -99,5 +96,5 @@ func getUnusedImports(file ast.Node, filename string) (map[string]string, error) } } - return unusedImport, nil + return unusedImport } diff --git a/vendor/github.com/99designs/gqlgen/plugin/modelgen/models.gotpl b/vendor/github.com/99designs/gqlgen/plugin/modelgen/models.gotpl index 6df200ee..a4579f87 100644 --- a/vendor/github.com/99designs/gqlgen/plugin/modelgen/models.gotpl +++ b/vendor/github.com/99designs/gqlgen/plugin/modelgen/models.gotpl @@ -36,7 +36,7 @@ {{- end}} {{ range $enum := .Enums }} - {{ with .Description|go }} {{.|prefixLines "// "}} {{end}} + {{ with .Description }} {{.|prefixLines "// "}} {{end}} type {{.Name|go }} string const ( {{- range $value := .Values}} -- cgit