Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vektah committed Feb 5, 2018
1 parent a9352e3 commit 39a8090
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 137 deletions.
10 changes: 6 additions & 4 deletions cmd/ggraphqlc/dumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ func (w *writer) lf() {
}

func (w *writer) writePackage() {
w.line("// This file was generated by github.com/vektah/graphql-go, DO NOT EDIT")
w.lf()
w.line("package %s", w.PackageName)
w.lf()
}
Expand Down Expand Up @@ -122,7 +124,7 @@ func (w *writer) writeVars() {

func (w *writer) writeObjectResolver(object object) {
w.line("// nolint: gocyclo, errcheck, gas, goconst")
w.begin("func _%s(ec *executionContext, sel []query.Selection, it *%s) {", lcFirst(object.Type.GraphQLName), object.Type.Local())
w.begin("func (ec *executionContext) _%s(sel []query.Selection, it *%s) {", lcFirst(object.Type.GraphQLName), object.Type.Local())

w.line("groupedFieldSet := ec.collectFields(sel, %sSatisfies, map[string]bool{})", lcFirst(object.Type.GraphQLName))
w.line("ec.json.BeginObject()")
Expand Down Expand Up @@ -255,9 +257,9 @@ func (w *writer) doWriteJsonType(t kind, val string, remainingMods []string, isP
w.line(" ec.json.Null()")
for _, implementor := range t.Implementors {
w.line("case %s:", implementor.Local())
w.line(" _%s(ec, field.Selections, &it)", lcFirst(implementor.GraphQLName))
w.line(" ec._%s(field.Selections, &it)", lcFirst(implementor.GraphQLName))
w.line("case *%s:", implementor.Local())
w.line(" _%s(ec, field.Selections, it)", lcFirst(implementor.GraphQLName))
w.line(" ec._%s(field.Selections, it)", lcFirst(implementor.GraphQLName))
}

w.line("default:")
Expand All @@ -267,7 +269,7 @@ func (w *writer) doWriteJsonType(t kind, val string, remainingMods []string, isP
if !isPtr {
val = "&" + val
}
w.line("_%s(ec, field.Selections, %s)", lcFirst(t.GraphQLName), val)
w.line("ec._%s(field.Selections, %s)", lcFirst(t.GraphQLName), val)
}
}

Expand Down
20 changes: 10 additions & 10 deletions cmd/ggraphqlc/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ func NewResolver(resolvers Resolvers) relay.Resolver {
c.json.ObjectKey("data")
if op.Type == query.Query {
{{.RootQuery}}(&c, op.Selections, nil)
c.{{.RootQuery}}(op.Selections, nil)
} else if op.Type == query.Mutation {
{{.RootMutation}}(&c, op.Selections, nil)
c.{{.RootMutation}}(op.Selections, nil)
} else {
c.Errorf("unsupported operation %s", op.Type)
c.json.Null()
Expand All @@ -81,11 +81,11 @@ type executionContext struct {
ctx context.Context
}
func (c *executionContext) introspectSchema() *introspection.Schema {
func (ec *executionContext) introspectSchema() *introspection.Schema {
return introspection.WrapSchema(parsedSchema)
}
func (c *executionContext) introspectType(name string) *introspection.Type {
func (ec *executionContext) introspectType(name string) *introspection.Type {
t := parsedSchema.Resolve(name)
if t == nil {
return nil
Expand All @@ -102,7 +102,7 @@ func instanceOf(val string, satisfies []string) bool {
return false
}
func (c *executionContext) collectFields(selSet []query.Selection, satisfies []string, visited map[string]bool) []collectedField {
func (ec *executionContext) collectFields(selSet []query.Selection, satisfies []string, visited map[string]bool) []collectedField {
var groupedFields []collectedField
for _, sel := range selSet {
Expand All @@ -116,7 +116,7 @@ func (c *executionContext) collectFields(selSet []query.Selection, satisfies []s
if len(sel.Arguments) > 0 {
f.Args = map[string]interface{}{}
for _, arg := range sel.Arguments {
f.Args[arg.Name.Name] = arg.Value.Value(c.variables)
f.Args[arg.Name.Name] = arg.Value.Value(ec.variables)
}
}
return f
Expand All @@ -128,7 +128,7 @@ func (c *executionContext) collectFields(selSet []query.Selection, satisfies []s
continue
}
for _, childField := range c.collectFields(sel.Selections, satisfies, visited) {
for _, childField := range ec.collectFields(sel.Selections, satisfies, visited) {
f := getOrCreateField(&groupedFields, childField.Name, func() collectedField { return childField })
f.Selections = append(f.Selections, childField.Selections...)
}
Expand All @@ -140,17 +140,17 @@ func (c *executionContext) collectFields(selSet []query.Selection, satisfies []s
}
visited[fragmentName] = true
fragment := c.doc.Fragments.Get(fragmentName)
fragment := ec.doc.Fragments.Get(fragmentName)
if fragment == nil {
c.Errorf("missing fragment %s", fragmentName)
ec.Errorf("missing fragment %s", fragmentName)
continue
}
if !instanceOf(fragment.On.Ident.Name, satisfies) {
continue
}
for _, childField := range c.collectFields(fragment.Selections, satisfies, visited) {
for _, childField := range ec.collectFields(fragment.Selections, satisfies, visited) {
f := getOrCreateField(&groupedFields, childField.Name, func() collectedField { return childField })
f.Selections = append(f.Selections, childField.Selections...)
}
Expand Down
Loading

0 comments on commit 39a8090

Please sign in to comment.