Skip to content

Commit 9fe8436

Browse files
authored
Merge branch 'master' into singleCaseSwitch
2 parents 21e7fb4 + 657726d commit 9fe8436

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

definition.go

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,8 @@ func (gt *Object) AddFieldConfig(fieldName string, fieldConfig *Field) {
403403
if fieldName == "" || fieldConfig == nil {
404404
return
405405
}
406-
switch gt.typeConfig.Fields.(type) {
407-
case Fields:
408-
gt.typeConfig.Fields.(Fields)[fieldName] = fieldConfig
406+
if fields, ok := gt.typeConfig.Fields.(Fields); ok {
407+
fields[fieldName] = fieldConfig
409408
gt.initialisedFields = false
410409
}
411410
}
@@ -424,11 +423,11 @@ func (gt *Object) Fields() FieldDefinitionMap {
424423
}
425424

426425
var configureFields Fields
427-
switch gt.typeConfig.Fields.(type) {
426+
switch fields := gt.typeConfig.Fields.(type) {
428427
case Fields:
429-
configureFields = gt.typeConfig.Fields.(Fields)
428+
configureFields = fields
430429
case FieldsThunk:
431-
configureFields = gt.typeConfig.Fields.(FieldsThunk)()
430+
configureFields = fields()
432431
}
433432

434433
gt.fields, gt.err = defineFieldMap(gt, configureFields)
@@ -442,11 +441,11 @@ func (gt *Object) Interfaces() []*Interface {
442441
}
443442

444443
var configInterfaces []*Interface
445-
switch gt.typeConfig.Interfaces.(type) {
444+
switch iface := gt.typeConfig.Interfaces.(type) {
446445
case InterfacesThunk:
447-
configInterfaces = gt.typeConfig.Interfaces.(InterfacesThunk)()
446+
configInterfaces = iface()
448447
case []*Interface:
449-
configInterfaces = gt.typeConfig.Interfaces.([]*Interface)
448+
configInterfaces = iface
450449
case nil:
451450
default:
452451
gt.err = fmt.Errorf("Unknown Object.Interfaces type: %T", gt.typeConfig.Interfaces)
@@ -721,9 +720,8 @@ func (it *Interface) AddFieldConfig(fieldName string, fieldConfig *Field) {
721720
if fieldName == "" || fieldConfig == nil {
722721
return
723722
}
724-
switch it.typeConfig.Fields.(type) {
725-
case Fields:
726-
it.typeConfig.Fields.(Fields)[fieldName] = fieldConfig
723+
if fields, ok := it.typeConfig.Fields.(Fields); ok {
724+
fields[fieldName] = fieldConfig
727725
it.initialisedFields = false
728726
}
729727
}
@@ -742,11 +740,11 @@ func (it *Interface) Fields() (fields FieldDefinitionMap) {
742740
}
743741

744742
var configureFields Fields
745-
switch it.typeConfig.Fields.(type) {
743+
switch fields := it.typeConfig.Fields.(type) {
746744
case Fields:
747-
configureFields = it.typeConfig.Fields.(Fields)
745+
configureFields = fields
748746
case FieldsThunk:
749-
configureFields = it.typeConfig.Fields.(FieldsThunk)()
747+
configureFields = fields()
750748
}
751749

752750
it.fields, it.err = defineFieldMap(it, configureFields)
@@ -1113,11 +1111,11 @@ func (gt *InputObject) defineFieldMap() InputObjectFieldMap {
11131111
fieldMap InputObjectConfigFieldMap
11141112
err error
11151113
)
1116-
switch gt.typeConfig.Fields.(type) {
1114+
switch fields := gt.typeConfig.Fields.(type) {
11171115
case InputObjectConfigFieldMap:
1118-
fieldMap = gt.typeConfig.Fields.(InputObjectConfigFieldMap)
1116+
fieldMap = fields
11191117
case InputObjectConfigFieldMapThunk:
1120-
fieldMap = gt.typeConfig.Fields.(InputObjectConfigFieldMapThunk)()
1118+
fieldMap = fields()
11211119
}
11221120
resultFieldMap := InputObjectFieldMap{}
11231121

@@ -1283,7 +1281,7 @@ func (gl *NonNull) Error() error {
12831281
return gl.err
12841282
}
12851283

1286-
var NameRegExp, _ = regexp.Compile("^[_a-zA-Z][_a-zA-Z0-9]*$")
1284+
var NameRegExp = regexp.MustCompile("^[_a-zA-Z][_a-zA-Z0-9]*$")
12871285

12881286
func assertValidName(name string) error {
12891287
return invariantf(

language/parser/parser.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ type Parser struct {
6161

6262
func Parse(p ParseParams) (*ast.Document, error) {
6363
var sourceObj *source.Source
64-
switch p.Source.(type) {
64+
switch src := p.Source.(type) {
6565
case *source.Source:
66-
sourceObj = p.Source.(*source.Source)
66+
sourceObj = src
6767
default:
6868
body, _ := p.Source.(string)
6969
sourceObj = source.NewSource(&source.Source{Body: []byte(body)})
@@ -83,9 +83,9 @@ func Parse(p ParseParams) (*ast.Document, error) {
8383
func parseValue(p ParseParams) (ast.Value, error) {
8484
var value ast.Value
8585
var sourceObj *source.Source
86-
switch p.Source.(type) {
86+
switch src := p.Source.(type) {
8787
case *source.Source:
88-
sourceObj = p.Source.(*source.Source)
88+
sourceObj = src
8989
default:
9090
body, _ := p.Source.(string)
9191
sourceObj = source.NewSource(&source.Source{Body: []byte(body)})
@@ -1600,7 +1600,7 @@ func reverse(parser *Parser, openKind int, parseFn parseFn, closeKind int, zinte
16001600
}
16011601
nodes = append(nodes, node)
16021602
}
1603-
if zinteger && len(nodes) <= 0 {
1603+
if zinteger && len(nodes) == 0 {
16041604
return nodes, unexpectedEmpty(parser, token.Start, openKind, closeKind)
16051605
}
16061606
return nodes, nil

0 commit comments

Comments
 (0)