aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/vektah/gqlgen/codegen/type.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-14 12:40:31 +0200
committerMichael Muré <batolettre@gmail.com>2018-09-14 12:41:59 +0200
commitb478cd1bcb4756b20f7f4b15fcf81f23e1a60a02 (patch)
tree8ce232dcab3dd00708f8ba66c334472457e5980d /vendor/github.com/vektah/gqlgen/codegen/type.go
parenta3fc9abb921f5ce7084d6ab7473442d0b72b1d78 (diff)
downloadgit-bug-b478cd1bcb4756b20f7f4b15fcf81f23e1a60a02.tar.gz
graphql: update gqlgen to 0.5.1
fix #6
Diffstat (limited to 'vendor/github.com/vektah/gqlgen/codegen/type.go')
-rw-r--r--vendor/github.com/vektah/gqlgen/codegen/type.go162
1 files changed, 0 insertions, 162 deletions
diff --git a/vendor/github.com/vektah/gqlgen/codegen/type.go b/vendor/github.com/vektah/gqlgen/codegen/type.go
deleted file mode 100644
index 7af24b3c..00000000
--- a/vendor/github.com/vektah/gqlgen/codegen/type.go
+++ /dev/null
@@ -1,162 +0,0 @@
-package codegen
-
-import (
- "strconv"
- "strings"
-)
-
-type NamedTypes map[string]*NamedType
-
-type NamedType struct {
- Ref
- IsScalar bool
- IsInterface bool
- IsInput bool
- GQLType string // Name of the graphql type
- Marshaler *Ref // If this type has an external marshaler this will be set
-}
-
-type Ref struct {
- GoType string // Name of the go type
- Package string // the package the go type lives in
- Import *Import // the resolved import with alias
- IsUserDefined bool // does the type exist in the typemap
-}
-
-type Type struct {
- *NamedType
-
- Modifiers []string
- CastType *Ref // the type to cast to when unmarshalling
-}
-
-const (
- modList = "[]"
- modPtr = "*"
-)
-
-func (t Ref) FullName() string {
- return t.PkgDot() + t.GoType
-}
-
-func (t Ref) PkgDot() string {
- if t.Import == nil || t.Import.Alias() == "" {
- return ""
- }
- return t.Import.Alias() + "."
-}
-
-func (t Type) Signature() string {
- return strings.Join(t.Modifiers, "") + t.FullName()
-}
-
-func (t Type) FullSignature() string {
- pkg := ""
- if t.Package != "" {
- pkg = t.Package + "."
- }
-
- return strings.Join(t.Modifiers, "") + pkg + t.GoType
-}
-
-func (t Type) IsPtr() bool {
- return len(t.Modifiers) > 0 && t.Modifiers[0] == modPtr
-}
-
-func (t *Type) StripPtr() {
- if !t.IsPtr() {
- return
- }
- t.Modifiers = t.Modifiers[0 : len(t.Modifiers)-1]
-}
-
-func (t Type) IsSlice() bool {
- return len(t.Modifiers) > 0 && t.Modifiers[0] == modList ||
- len(t.Modifiers) > 1 && t.Modifiers[0] == modPtr && t.Modifiers[1] == modList
-}
-
-func (t NamedType) IsMarshaled() bool {
- return t.Marshaler != nil
-}
-
-func (t Type) Unmarshal(result, raw string) string {
- return t.unmarshal(result, raw, t.Modifiers, 1)
-}
-
-func (t Type) unmarshal(result, raw string, remainingMods []string, depth int) string {
- switch {
- case len(remainingMods) > 0 && remainingMods[0] == modPtr:
- ptr := "ptr" + strconv.Itoa(depth)
- return tpl(`var {{.ptr}} {{.mods}}{{.t.FullName}}
- if {{.raw}} != nil {
- {{.next}}
- {{.result}} = &{{.ptr -}}
- }
- `, map[string]interface{}{
- "ptr": ptr,
- "t": t,
- "raw": raw,
- "result": result,
- "mods": strings.Join(remainingMods[1:], ""),
- "next": t.unmarshal(ptr, raw, remainingMods[1:], depth+1),
- })
-
- case len(remainingMods) > 0 && remainingMods[0] == modList:
- var rawIf = "rawIf" + strconv.Itoa(depth)
- var index = "idx" + strconv.Itoa(depth)
-
- return tpl(`var {{.rawSlice}} []interface{}
- if {{.raw}} != nil {
- if tmp1, ok := {{.raw}}.([]interface{}); ok {
- {{.rawSlice}} = tmp1
- }
- }
- {{.result}} = make({{.type}}, len({{.rawSlice}}))
- for {{.index}} := range {{.rawSlice}} {
- {{ .next -}}
- }`, map[string]interface{}{
- "raw": raw,
- "rawSlice": rawIf,
- "index": index,
- "result": result,
- "type": strings.Join(remainingMods, "") + t.NamedType.FullName(),
- "next": t.unmarshal(result+"["+index+"]", rawIf+"["+index+"]", remainingMods[1:], depth+1),
- })
- }
-
- realResult := result
- if t.CastType != nil {
- result = "castTmp"
- }
-
- return tpl(`{{- if .t.CastType }}
- var castTmp {{.t.FullName}}
- {{ end }}
- {{- if eq .t.GoType "map[string]interface{}" }}
- {{- .result }} = {{.raw}}.(map[string]interface{})
- {{- else if .t.Marshaler }}
- {{- .result }}, err = {{ .t.Marshaler.PkgDot }}Unmarshal{{.t.Marshaler.GoType}}({{.raw}})
- {{- else -}}
- err = (&{{.result}}).UnmarshalGQL({{.raw}})
- {{- end }}
- {{- if .t.CastType }}
- {{ .realResult }} = {{.t.CastType.FullName}}(castTmp)
- {{- end }}`, map[string]interface{}{
- "realResult": realResult,
- "result": result,
- "raw": raw,
- "t": t,
- })
-}
-
-func (t Type) Marshal(val string) string {
- if t.CastType != nil {
- val = t.GoType + "(" + val + ")"
- }
-
- if t.Marshaler != nil {
- return "return " + t.Marshaler.PkgDot() + "Marshal" + t.Marshaler.GoType + "(" + val + ")"
- }
-
- return "return " + val
-}