@@ -266,20 +266,20 @@ func NewScalar(config ScalarConfig) *Scalar {
266
266
st .PrivateName = config .Name
267
267
st .PrivateDescription = config .Description
268
268
269
- err = invariant (
269
+ err = invariantf (
270
270
config .Serialize != nil ,
271
- fmt . Sprintf ( `%v must provide "serialize" function. If this custom Scalar is ` +
271
+ `%v must provide "serialize" function. If this custom Scalar is ` +
272
272
`also used as an input type, ensure "parseValue" and "parseLiteral" ` +
273
- `functions are also provided.` , st ) ,
273
+ `functions are also provided.` , st ,
274
274
)
275
275
if err != nil {
276
276
st .err = err
277
277
return st
278
278
}
279
279
if config .ParseValue != nil || config .ParseLiteral != nil {
280
- err = invariant (
280
+ err = invariantf (
281
281
config .ParseValue != nil && config .ParseLiteral != nil ,
282
- fmt . Sprintf ( `%v must provide both "parseValue" and "parseLiteral" functions.` , st ) ,
282
+ `%v must provide both "parseValue" and "parseLiteral" functions.` , st ,
283
283
)
284
284
if err != nil {
285
285
st .err = err
@@ -478,20 +478,20 @@ func defineInterfaces(ttype *Object, interfaces []*Interface) ([]*Interface, err
478
478
return ifaces , nil
479
479
}
480
480
for _ , iface := range interfaces {
481
- err := invariant (
481
+ err := invariantf (
482
482
iface != nil ,
483
- fmt . Sprintf ( `%v may only implement Interface types, it cannot implement: %v.` , ttype , iface ) ,
483
+ `%v may only implement Interface types, it cannot implement: %v.` , ttype , iface ,
484
484
)
485
485
if err != nil {
486
486
return ifaces , err
487
487
}
488
488
if iface .ResolveType != nil {
489
- err = invariant (
489
+ err = invariantf (
490
490
iface .ResolveType != nil ,
491
- fmt . Sprintf ( `Interface Type %v does not provide a "resolveType" function ` +
491
+ `Interface Type %v does not provide a "resolveType" function ` +
492
492
`and implementing Type %v does not provide a "isTypeOf" ` +
493
493
`function. There is no way to resolve this implementing type ` +
494
- `during execution.` , iface , ttype ) ,
494
+ `during execution.` , iface , ttype ,
495
495
)
496
496
if err != nil {
497
497
return ifaces , err
@@ -507,9 +507,9 @@ func defineFieldMap(ttype Named, fields Fields) (FieldDefinitionMap, error) {
507
507
508
508
resultFieldMap := FieldDefinitionMap {}
509
509
510
- err := invariant (
510
+ err := invariantf (
511
511
len (fields ) > 0 ,
512
- fmt . Sprintf ( `%v fields must be an object with field names as keys or a function which return such an object.` , ttype ) ,
512
+ `%v fields must be an object with field names as keys or a function which return such an object.` , ttype ,
513
513
)
514
514
if err != nil {
515
515
return resultFieldMap , err
@@ -519,9 +519,9 @@ func defineFieldMap(ttype Named, fields Fields) (FieldDefinitionMap, error) {
519
519
if field == nil {
520
520
continue
521
521
}
522
- err = invariant (
522
+ err = invariantf (
523
523
field .Type != nil ,
524
- fmt . Sprintf ( `%v.%v field type must be Output Type but got: %v.` , ttype , fieldName , field .Type ) ,
524
+ `%v.%v field type must be Output Type but got: %v.` , ttype , fieldName , field .Type ,
525
525
)
526
526
if err != nil {
527
527
return resultFieldMap , err
@@ -547,16 +547,16 @@ func defineFieldMap(ttype Named, fields Fields) (FieldDefinitionMap, error) {
547
547
if err != nil {
548
548
return resultFieldMap , err
549
549
}
550
- err = invariant (
550
+ err = invariantf (
551
551
arg != nil ,
552
- fmt . Sprintf ( `%v.%v args must be an object with argument names as keys.` , ttype , fieldName ) ,
552
+ `%v.%v args must be an object with argument names as keys.` , ttype , fieldName ,
553
553
)
554
554
if err != nil {
555
555
return resultFieldMap , err
556
556
}
557
- err = invariant (
557
+ err = invariantf (
558
558
arg .Type != nil ,
559
- fmt . Sprintf ( `%v.%v(%v:) argument type must be Input Type but got: %v.` , ttype , fieldName , argName , arg .Type ) ,
559
+ `%v.%v(%v:) argument type must be Input Type but got: %v.` , ttype , fieldName , argName , arg .Type ,
560
560
)
561
561
if err != nil {
562
562
return resultFieldMap , err
@@ -823,30 +823,30 @@ func NewUnion(config UnionConfig) *Union {
823
823
objectType .PrivateDescription = config .Description
824
824
objectType .ResolveType = config .ResolveType
825
825
826
- err = invariant (
826
+ err = invariantf (
827
827
len (config .Types ) > 0 ,
828
- fmt . Sprintf ( `Must provide Array of types for Union %v.` , config .Name ) ,
828
+ `Must provide Array of types for Union %v.` , config .Name ,
829
829
)
830
830
if err != nil {
831
831
objectType .err = err
832
832
return objectType
833
833
}
834
834
for _ , ttype := range config .Types {
835
- err := invariant (
835
+ err := invariantf (
836
836
ttype != nil ,
837
- fmt . Sprintf ( `%v may only contain Object types, it cannot contain: %v.` , objectType , ttype ) ,
837
+ `%v may only contain Object types, it cannot contain: %v.` , objectType , ttype ,
838
838
)
839
839
if err != nil {
840
840
objectType .err = err
841
841
return objectType
842
842
}
843
843
if objectType .ResolveType == nil {
844
- err = invariant (
844
+ err = invariantf (
845
845
ttype .IsTypeOf != nil ,
846
- fmt . Sprintf ( `Union Type %v does not provide a "resolveType" function ` +
846
+ `Union Type %v does not provide a "resolveType" function ` +
847
847
`and possible Type %v does not provide a "isTypeOf" ` +
848
848
`function. There is no way to resolve this possible type ` +
849
- `during execution.` , objectType , ttype ) ,
849
+ `during execution.` , objectType , ttype ,
850
850
)
851
851
if err != nil {
852
852
objectType .err = err
@@ -947,19 +947,19 @@ func NewEnum(config EnumConfig) *Enum {
947
947
func (gt * Enum ) defineEnumValues (valueMap EnumValueConfigMap ) ([]* EnumValueDefinition , error ) {
948
948
values := []* EnumValueDefinition {}
949
949
950
- err := invariant (
950
+ err := invariantf (
951
951
len (valueMap ) > 0 ,
952
- fmt . Sprintf ( `%v values must be an object with value names as keys.` , gt ) ,
952
+ `%v values must be an object with value names as keys.` , gt ,
953
953
)
954
954
if err != nil {
955
955
return values , err
956
956
}
957
957
958
958
for valueName , valueConfig := range valueMap {
959
- err := invariant (
959
+ err := invariantf (
960
960
valueConfig != nil ,
961
- fmt . Sprintf ( `%v.%v must refer to an object with a "value" key ` +
962
- `representing an internal value but got: %v.` , gt , valueName , valueConfig ) ,
961
+ `%v.%v must refer to an object with a "value" key ` +
962
+ `representing an internal value but got: %v.` , gt , valueName , valueConfig ,
963
963
)
964
964
if err != nil {
965
965
return values , err
@@ -1130,9 +1130,9 @@ func (gt *InputObject) defineFieldMap() InputObjectFieldMap {
1130
1130
}
1131
1131
resultFieldMap := InputObjectFieldMap {}
1132
1132
1133
- err := invariant (
1133
+ err := invariantf (
1134
1134
len (fieldMap ) > 0 ,
1135
- fmt . Sprintf ( `%v fields must be an object with field names as keys or a function which return such an object.` , gt ) ,
1135
+ `%v fields must be an object with field names as keys or a function which return such an object.` , gt ,
1136
1136
)
1137
1137
if err != nil {
1138
1138
gt .err = err
@@ -1147,9 +1147,9 @@ func (gt *InputObject) defineFieldMap() InputObjectFieldMap {
1147
1147
if err != nil {
1148
1148
continue
1149
1149
}
1150
- err = invariant (
1150
+ err = invariantf (
1151
1151
fieldConfig .Type != nil ,
1152
- fmt . Sprintf ( `%v.%v field type must be Input Type but got: %v.` , gt , fieldName , fieldConfig .Type ) ,
1152
+ `%v.%v field type must be Input Type but got: %v.` , gt , fieldName , fieldConfig .Type ,
1153
1153
)
1154
1154
if err != nil {
1155
1155
gt .err = err
@@ -1205,7 +1205,7 @@ type List struct {
1205
1205
func NewList (ofType Type ) * List {
1206
1206
gl := & List {}
1207
1207
1208
- err := invariant (ofType != nil , fmt . Sprintf ( `Can only create List of a Type but got: %v.` , ofType ) )
1208
+ err := invariantf (ofType != nil , `Can only create List of a Type but got: %v.` , ofType )
1209
1209
if err != nil {
1210
1210
gl .err = err
1211
1211
return gl
@@ -1259,7 +1259,7 @@ func NewNonNull(ofType Type) *NonNull {
1259
1259
gl := & NonNull {}
1260
1260
1261
1261
_ , isOfTypeNonNull := ofType .(* NonNull )
1262
- err := invariant (ofType != nil && ! isOfTypeNonNull , fmt . Sprintf ( `Can only create NonNull of a Nullable Type but got: %v.` , ofType ) )
1262
+ err := invariantf (ofType != nil && ! isOfTypeNonNull , `Can only create NonNull of a Nullable Type but got: %v.` , ofType )
1263
1263
if err != nil {
1264
1264
gl .err = err
1265
1265
return gl
@@ -1286,8 +1286,8 @@ func (gl *NonNull) Error() error {
1286
1286
var NameRegExp , _ = regexp .Compile ("^[_a-zA-Z][_a-zA-Z0-9]*$" )
1287
1287
1288
1288
func assertValidName (name string ) error {
1289
- return invariant (
1289
+ return invariantf (
1290
1290
NameRegExp .MatchString (name ),
1291
- fmt . Sprintf ( `Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "%v" does not.` , name ) ,
1291
+ `Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "%v" does not.` , name ,
1292
1292
)
1293
1293
}
0 commit comments