aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/99designs/gqlgen/codegen
diff options
context:
space:
mode:
authorAmine Hilaly <hilalyamine@gmail.com>2019-08-17 00:48:08 +0200
committerAmine Hilaly <hilalyamine@gmail.com>2019-08-17 00:48:08 +0200
commitd571deef57b682f92e71f9374c2c59893db811af (patch)
treeb17be26cfd358b1518010c9d7073fdbf0caa1561 /vendor/github.com/99designs/gqlgen/codegen
parenta89355e7fbcaaa5efb07d43c1f19a4be2e2c1537 (diff)
downloadgit-bug-d571deef57b682f92e71f9374c2c59893db811af.tar.gz
vendor: upgrade github.com/99designs/gqlgen to v0.9.2
Diffstat (limited to 'vendor/github.com/99designs/gqlgen/codegen')
-rw-r--r--vendor/github.com/99designs/gqlgen/codegen/args.gotpl4
-rw-r--r--vendor/github.com/99designs/gqlgen/codegen/config/config.go38
-rw-r--r--vendor/github.com/99designs/gqlgen/codegen/data.go5
-rw-r--r--vendor/github.com/99designs/gqlgen/codegen/field.go14
-rw-r--r--vendor/github.com/99designs/gqlgen/codegen/field.gotpl5
-rw-r--r--vendor/github.com/99designs/gqlgen/codegen/input.gotpl4
-rw-r--r--vendor/github.com/99designs/gqlgen/codegen/object.go3
-rw-r--r--vendor/github.com/99designs/gqlgen/codegen/templates/import.go3
-rw-r--r--vendor/github.com/99designs/gqlgen/codegen/templates/templates.go14
-rw-r--r--vendor/github.com/99designs/gqlgen/codegen/type.go4
10 files changed, 53 insertions, 41 deletions
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
}