Merge pull request #194 from MichaelMure/dependabot/dep/github.com/99designs/gqlgen-0.9.2

Amine created

build(deps): bump github.com/99designs/gqlgen from 0.9.1 to 0.9.2

Change summary

Gopkg.lock                                                         |  6 
Gopkg.toml                                                         |  2 
vendor/github.com/99designs/gqlgen/codegen/args.gotpl              |  4 
vendor/github.com/99designs/gqlgen/codegen/config/config.go        | 38 
vendor/github.com/99designs/gqlgen/codegen/data.go                 |  5 
vendor/github.com/99designs/gqlgen/codegen/field.go                | 14 
vendor/github.com/99designs/gqlgen/codegen/field.gotpl             |  5 
vendor/github.com/99designs/gqlgen/codegen/input.gotpl             |  4 
vendor/github.com/99designs/gqlgen/codegen/object.go               |  3 
vendor/github.com/99designs/gqlgen/codegen/templates/import.go     |  3 
vendor/github.com/99designs/gqlgen/codegen/templates/templates.go  | 14 
vendor/github.com/99designs/gqlgen/codegen/type.go                 |  4 
vendor/github.com/99designs/gqlgen/graphql/introspection/schema.go | 18 
vendor/github.com/99designs/gqlgen/graphql/version.go              |  2 
vendor/github.com/99designs/gqlgen/handler/websocket.go            |  7 
vendor/github.com/99designs/gqlgen/internal/code/imports.go        |  9 
vendor/github.com/99designs/gqlgen/internal/imports/prune.go       |  9 
vendor/github.com/99designs/gqlgen/plugin/modelgen/models.gotpl    |  2 
18 files changed, 80 insertions(+), 69 deletions(-)

Detailed changes

Gopkg.lock 🔗

@@ -2,7 +2,7 @@
 
 
 [[projects]]
-  digest = "1:5038f1f51cfeed48d9643aeb573ecf62393a50ba3165322462e86e6a6d290a19"
+  digest = "1:25c825a120e8ae421b807f06eaa30f4d30ad3700fc103b7aaa24af8358498d31"
   name = "github.com/99designs/gqlgen"
   packages = [
     "api",
@@ -21,8 +21,8 @@
     "plugin/schemaconfig",
   ]
   pruneopts = "UT"
-  revision = "b128a29122e8ca8ada5f34cc18338fa7c10fc5b4"
-  version = "v0.9.1"
+  revision = "4eeacc6e4cb7bedc7c5312b6a3947697ad5cfb55"
+  version = "v0.9.2"
 
 [[projects]]
   branch = "master"

Gopkg.toml 🔗

@@ -58,7 +58,7 @@
 
 [[constraint]]
   name = "github.com/99designs/gqlgen"
-  version = "0.9.1"
+  version = "0.9.2"
 
 [[constraint]]
   name = "github.com/MichaelMure/gocui"

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)
 				}

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...)

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

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 {

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

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)
 					}

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
 		}
 	}

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)
 	}
 

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
 		}

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
 }

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{

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 {

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 {

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
 }