@@ -269,20 +269,20 @@ func NewScalar(config ScalarConfig) *Scalar {
269
269
st .PrivateName = config .Name
270
270
st .PrivateDescription = config .Description
271
271
272
- err = invariant (
272
+ err = invariantf (
273
273
config .Serialize != nil ,
274
- fmt . Sprintf ( `%v must provide "serialize" function. If this custom Scalar is ` +
274
+ `%v must provide "serialize" function. If this custom Scalar is ` +
275
275
`also used as an input type, ensure "parseValue" and "parseLiteral" ` +
276
- `functions are also provided.` , st ) ,
276
+ `functions are also provided.` , st ,
277
277
)
278
278
if err != nil {
279
279
st .err = err
280
280
return st
281
281
}
282
282
if config .ParseValue != nil || config .ParseLiteral != nil {
283
- err = invariant (
283
+ err = invariantf (
284
284
config .ParseValue != nil && config .ParseLiteral != nil ,
285
- fmt . Sprintf ( `%v must provide both "parseValue" and "parseLiteral" functions.` , st ) ,
285
+ `%v must provide both "parseValue" and "parseLiteral" functions.` , st ,
286
286
)
287
287
if err != nil {
288
288
st .err = err
@@ -482,20 +482,20 @@ func defineInterfaces(ttype *Object, interfaces []*Interface) ([]*Interface, err
482
482
return ifaces , nil
483
483
}
484
484
for _ , iface := range interfaces {
485
- err := invariant (
485
+ err := invariantf (
486
486
iface != nil ,
487
- fmt . Sprintf ( `%v may only implement Interface types, it cannot implement: %v.` , ttype , iface ) ,
487
+ `%v may only implement Interface types, it cannot implement: %v.` , ttype , iface ,
488
488
)
489
489
if err != nil {
490
490
return ifaces , err
491
491
}
492
492
if iface .ResolveType != nil {
493
- err = invariant (
493
+ err = invariantf (
494
494
iface .ResolveType != nil ,
495
- fmt . Sprintf ( `Interface Type %v does not provide a "resolveType" function ` +
495
+ `Interface Type %v does not provide a "resolveType" function ` +
496
496
`and implementing Type %v does not provide a "isTypeOf" ` +
497
497
`function. There is no way to resolve this implementing type ` +
498
- `during execution.` , iface , ttype ) ,
498
+ `during execution.` , iface , ttype ,
499
499
)
500
500
if err != nil {
501
501
return ifaces , err
@@ -518,9 +518,9 @@ func defineFieldMap(ttype Named, fields interface{}) (FieldDefinitionMap, error)
518
518
519
519
resultFieldMap := FieldDefinitionMap {}
520
520
521
- err := invariant (
521
+ err := invariantf (
522
522
len (fieldMap ) > 0 ,
523
- fmt . Sprintf ( `%v fields must be an object with field names as keys or a function which return such an object.` , ttype ) ,
523
+ `%v fields must be an object with field names as keys or a function which return such an object.` , ttype ,
524
524
)
525
525
if err != nil {
526
526
return resultFieldMap , err
@@ -530,9 +530,9 @@ func defineFieldMap(ttype Named, fields interface{}) (FieldDefinitionMap, error)
530
530
if field == nil {
531
531
continue
532
532
}
533
- err = invariant (
533
+ err = invariantf (
534
534
field .Type != nil ,
535
- fmt . Sprintf ( `%v.%v field type must be Output Type but got: %v.` , ttype , fieldName , field .Type ) ,
535
+ `%v.%v field type must be Output Type but got: %v.` , ttype , fieldName , field .Type ,
536
536
)
537
537
if err != nil {
538
538
return resultFieldMap , err
@@ -558,16 +558,16 @@ func defineFieldMap(ttype Named, fields interface{}) (FieldDefinitionMap, error)
558
558
if err != nil {
559
559
return resultFieldMap , err
560
560
}
561
- err = invariant (
561
+ err = invariantf (
562
562
arg != nil ,
563
- fmt . Sprintf ( `%v.%v args must be an object with argument names as keys.` , ttype , fieldName ) ,
563
+ `%v.%v args must be an object with argument names as keys.` , ttype , fieldName ,
564
564
)
565
565
if err != nil {
566
566
return resultFieldMap , err
567
567
}
568
- err = invariant (
568
+ err = invariantf (
569
569
arg .Type != nil ,
570
- fmt . Sprintf ( `%v.%v(%v:) argument type must be Input Type but got: %v.` , ttype , fieldName , argName , arg .Type ) ,
570
+ `%v.%v(%v:) argument type must be Input Type but got: %v.` , ttype , fieldName , argName , arg .Type ,
571
571
)
572
572
if err != nil {
573
573
return resultFieldMap , err
@@ -834,30 +834,30 @@ func NewUnion(config UnionConfig) *Union {
834
834
objectType .PrivateDescription = config .Description
835
835
objectType .ResolveType = config .ResolveType
836
836
837
- err = invariant (
837
+ err = invariantf (
838
838
len (config .Types ) > 0 ,
839
- fmt . Sprintf ( `Must provide Array of types for Union %v.` , config .Name ) ,
839
+ `Must provide Array of types for Union %v.` , config .Name ,
840
840
)
841
841
if err != nil {
842
842
objectType .err = err
843
843
return objectType
844
844
}
845
845
for _ , ttype := range config .Types {
846
- err := invariant (
846
+ err := invariantf (
847
847
ttype != nil ,
848
- fmt . Sprintf ( `%v may only contain Object types, it cannot contain: %v.` , objectType , ttype ) ,
848
+ `%v may only contain Object types, it cannot contain: %v.` , objectType , ttype ,
849
849
)
850
850
if err != nil {
851
851
objectType .err = err
852
852
return objectType
853
853
}
854
854
if objectType .ResolveType == nil {
855
- err = invariant (
855
+ err = invariantf (
856
856
ttype .IsTypeOf != nil ,
857
- fmt . Sprintf ( `Union Type %v does not provide a "resolveType" function ` +
857
+ `Union Type %v does not provide a "resolveType" function ` +
858
858
`and possible Type %v does not provide a "isTypeOf" ` +
859
859
`function. There is no way to resolve this possible type ` +
860
- `during execution.` , objectType , ttype ) ,
860
+ `during execution.` , objectType , ttype ,
861
861
)
862
862
if err != nil {
863
863
objectType .err = err
@@ -958,19 +958,19 @@ func NewEnum(config EnumConfig) *Enum {
958
958
func (gt * Enum ) defineEnumValues (valueMap EnumValueConfigMap ) ([]* EnumValueDefinition , error ) {
959
959
values := []* EnumValueDefinition {}
960
960
961
- err := invariant (
961
+ err := invariantf (
962
962
len (valueMap ) > 0 ,
963
- fmt . Sprintf ( `%v values must be an object with value names as keys.` , gt ) ,
963
+ `%v values must be an object with value names as keys.` , gt ,
964
964
)
965
965
if err != nil {
966
966
return values , err
967
967
}
968
968
969
969
for valueName , valueConfig := range valueMap {
970
- err := invariant (
970
+ err := invariantf (
971
971
valueConfig != nil ,
972
- fmt . Sprintf ( `%v.%v must refer to an object with a "value" key ` +
973
- `representing an internal value but got: %v.` , gt , valueName , valueConfig ) ,
972
+ `%v.%v must refer to an object with a "value" key ` +
973
+ `representing an internal value but got: %v.` , gt , valueName , valueConfig ,
974
974
)
975
975
if err != nil {
976
976
return values , err
@@ -1151,9 +1151,9 @@ func (gt *InputObject) defineFieldMap() InputObjectFieldMap {
1151
1151
}
1152
1152
resultFieldMap := InputObjectFieldMap {}
1153
1153
1154
- err := invariant (
1154
+ err := invariantf (
1155
1155
len (fieldMap ) > 0 ,
1156
- fmt . Sprintf ( `%v fields must be an object with field names as keys or a function which return such an object.` , gt ) ,
1156
+ `%v fields must be an object with field names as keys or a function which return such an object.` , gt ,
1157
1157
)
1158
1158
if err != nil {
1159
1159
gt .err = err
@@ -1168,9 +1168,9 @@ func (gt *InputObject) defineFieldMap() InputObjectFieldMap {
1168
1168
if err != nil {
1169
1169
continue
1170
1170
}
1171
- err = invariant (
1171
+ err = invariantf (
1172
1172
fieldConfig .Type != nil ,
1173
- fmt . Sprintf ( `%v.%v field type must be Input Type but got: %v.` , gt , fieldName , fieldConfig .Type ) ,
1173
+ `%v.%v field type must be Input Type but got: %v.` , gt , fieldName , fieldConfig .Type ,
1174
1174
)
1175
1175
if err != nil {
1176
1176
gt .err = err
@@ -1231,7 +1231,7 @@ type List struct {
1231
1231
func NewList (ofType Type ) * List {
1232
1232
gl := & List {}
1233
1233
1234
- err := invariant (ofType != nil , fmt . Sprintf ( `Can only create List of a Type but got: %v.` , ofType ) )
1234
+ err := invariantf (ofType != nil , `Can only create List of a Type but got: %v.` , ofType )
1235
1235
if err != nil {
1236
1236
gl .err = err
1237
1237
return gl
@@ -1284,7 +1284,7 @@ func NewNonNull(ofType Type) *NonNull {
1284
1284
gl := & NonNull {}
1285
1285
1286
1286
_ , isOfTypeNonNull := ofType .(* NonNull )
1287
- err := invariant (ofType != nil && ! isOfTypeNonNull , fmt . Sprintf ( `Can only create NonNull of a Nullable Type but got: %v.` , ofType ) )
1287
+ err := invariantf (ofType != nil && ! isOfTypeNonNull , `Can only create NonNull of a Nullable Type but got: %v.` , ofType )
1288
1288
if err != nil {
1289
1289
gl .err = err
1290
1290
return gl
@@ -1311,8 +1311,8 @@ func (gl *NonNull) Error() error {
1311
1311
var NameRegExp , _ = regexp .Compile ("^[_a-zA-Z][_a-zA-Z0-9]*$" )
1312
1312
1313
1313
func assertValidName (name string ) error {
1314
- return invariant (
1314
+ return invariantf (
1315
1315
NameRegExp .MatchString (name ),
1316
- fmt . Sprintf ( `Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "%v" does not.` , name ),
1317
- )
1316
+ `Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "%v" does not.` , name )
1317
+
1318
1318
}
0 commit comments