Skip to content

Commit

Permalink
Merge pull request #375 from Quasilyte/singleCaseSwitch
Browse files Browse the repository at this point in the history
simplify single case type switches
  • Loading branch information
chris-ramon committed Jul 28, 2018
2 parents 657726d + 9fe8436 commit 0403491
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
9 changes: 3 additions & 6 deletions introspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,7 @@ func init() {
TypeType.AddFieldConfig("interfaces", &Field{
Type: NewList(NewNonNull(TypeType)),
Resolve: func(p ResolveParams) (interface{}, error) {
switch ttype := p.Source.(type) {
case *Object:
if ttype, ok := p.Source.(*Object); ok {
return ttype.Interfaces(), nil
}
return nil, nil
Expand Down Expand Up @@ -579,8 +578,7 @@ func init() {
},
Resolve: func(p ResolveParams) (interface{}, error) {
includeDeprecated, _ := p.Args["includeDeprecated"].(bool)
switch ttype := p.Source.(type) {
case *Enum:
if ttype, ok := p.Source.(*Enum); ok {
if includeDeprecated {
return ttype.Values(), nil
}
Expand All @@ -599,8 +597,7 @@ func init() {
TypeType.AddFieldConfig("inputFields", &Field{
Type: NewList(NewNonNull(InputValueType)),
Resolve: func(p ResolveParams) (interface{}, error) {
switch ttype := p.Source.(type) {
case *InputObject:
if ttype, ok := p.Source.(*InputObject); ok {
fields := []*InputObjectField{}
for _, field := range ttype.Fields() {
fields = append(fields, field)
Expand Down
30 changes: 15 additions & 15 deletions language/visitor/visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,19 +609,20 @@ func VisitInParallel(visitorOptsSlice ...*VisitorOptions) *VisitorOptions {
Enter: func(p VisitFuncParams) (string, interface{}) {
for i, visitorOpts := range visitorOptsSlice {
if _, ok := skipping[i]; !ok {
switch node := p.Node.(type) {
case ast.Node:
kind := node.GetKind()
fn := GetVisitFn(visitorOpts, kind, false)
if fn != nil {
action, result := fn(p)
if action == ActionSkip {
skipping[i] = node
} else if action == ActionBreak {
skipping[i] = ActionBreak
} else if action == ActionUpdate {
return ActionUpdate, result
}
node, ok := p.Node.(ast.Node)
if !ok {
continue
}
kind := node.GetKind()
fn := GetVisitFn(visitorOpts, kind, false)
if fn != nil {
action, result := fn(p)
if action == ActionSkip {
skipping[i] = node
} else if action == ActionBreak {
skipping[i] = ActionBreak
} else if action == ActionUpdate {
return ActionUpdate, result
}
}
}
Expand All @@ -632,8 +633,7 @@ func VisitInParallel(visitorOptsSlice ...*VisitorOptions) *VisitorOptions {
for i, visitorOpts := range visitorOptsSlice {
skippedNode, ok := skipping[i]
if !ok {
switch node := p.Node.(type) {
case ast.Node:
if node, ok := p.Node.(ast.Node); ok {
kind := node.GetKind()
fn := GetVisitFn(visitorOpts, kind, true)
if fn != nil {
Expand Down

0 comments on commit 0403491

Please sign in to comment.