@@ -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
@@ -499,20 +499,20 @@ func defineInterfaces(ttype *Object, interfaces []*Interface) ([]*Interface, err
499
499
return ifaces , nil
500
500
}
501
501
for _ , iface := range interfaces {
502
- err := invariant (
502
+ err := invariantf (
503
503
iface != nil ,
504
- fmt . Sprintf ( `%v may only implement Interface types, it cannot implement: %v.` , ttype , iface ) ,
504
+ `%v may only implement Interface types, it cannot implement: %v.` , ttype , iface ,
505
505
)
506
506
if err != nil {
507
507
return ifaces , err
508
508
}
509
509
if iface .ResolveType != nil {
510
- err = invariant (
510
+ err = invariantf (
511
511
iface .ResolveType != nil ,
512
- fmt . Sprintf ( `Interface Type %v does not provide a "resolveType" function ` +
512
+ `Interface Type %v does not provide a "resolveType" function ` +
513
513
`and implementing Type %v does not provide a "isTypeOf" ` +
514
514
`function. There is no way to resolve this implementing type ` +
515
- `during execution.` , iface , ttype ) ,
515
+ `during execution.` , iface , ttype ,
516
516
)
517
517
if err != nil {
518
518
return ifaces , err
@@ -527,9 +527,9 @@ func defineInterfaces(ttype *Object, interfaces []*Interface) ([]*Interface, err
527
527
func defineFieldMap (ttype Named , fieldMap Fields ) (FieldDefinitionMap , error ) {
528
528
resultFieldMap := FieldDefinitionMap {}
529
529
530
- err := invariant (
530
+ err := invariantf (
531
531
len (fieldMap ) > 0 ,
532
- fmt . Sprintf ( `%v fields must be an object with field names as keys or a function which return such an object.` , ttype ) ,
532
+ `%v fields must be an object with field names as keys or a function which return such an object.` , ttype ,
533
533
)
534
534
if err != nil {
535
535
return resultFieldMap , err
@@ -539,9 +539,9 @@ func defineFieldMap(ttype Named, fieldMap Fields) (FieldDefinitionMap, error) {
539
539
if field == nil {
540
540
continue
541
541
}
542
- err = invariant (
542
+ err = invariantf (
543
543
field .Type != nil ,
544
- fmt . Sprintf ( `%v.%v field type must be Output Type but got: %v.` , ttype , fieldName , field .Type ) ,
544
+ `%v.%v field type must be Output Type but got: %v.` , ttype , fieldName , field .Type ,
545
545
)
546
546
if err != nil {
547
547
return resultFieldMap , err
@@ -567,16 +567,16 @@ func defineFieldMap(ttype Named, fieldMap Fields) (FieldDefinitionMap, error) {
567
567
if err != nil {
568
568
return resultFieldMap , err
569
569
}
570
- err = invariant (
570
+ err = invariantf (
571
571
arg != nil ,
572
- fmt . Sprintf ( `%v.%v args must be an object with argument names as keys.` , ttype , fieldName ) ,
572
+ `%v.%v args must be an object with argument names as keys.` , ttype , fieldName ,
573
573
)
574
574
if err != nil {
575
575
return resultFieldMap , err
576
576
}
577
- err = invariant (
577
+ err = invariantf (
578
578
arg .Type != nil ,
579
- fmt . Sprintf ( `%v.%v(%v:) argument type must be Input Type but got: %v.` , ttype , fieldName , argName , arg .Type ) ,
579
+ `%v.%v(%v:) argument type must be Input Type but got: %v.` , ttype , fieldName , argName , arg .Type ,
580
580
)
581
581
if err != nil {
582
582
return resultFieldMap , err
@@ -856,30 +856,30 @@ func NewUnion(config UnionConfig) *Union {
856
856
objectType .PrivateDescription = config .Description
857
857
objectType .ResolveType = config .ResolveType
858
858
859
- err = invariant (
859
+ err = invariantf (
860
860
len (config .Types ) > 0 ,
861
- fmt . Sprintf ( `Must provide Array of types for Union %v.` , config .Name ) ,
861
+ `Must provide Array of types for Union %v.` , config .Name ,
862
862
)
863
863
if err != nil {
864
864
objectType .err = err
865
865
return objectType
866
866
}
867
867
for _ , ttype := range config .Types {
868
- err := invariant (
868
+ err := invariantf (
869
869
ttype != nil ,
870
- fmt . Sprintf ( `%v may only contain Object types, it cannot contain: %v.` , objectType , ttype ) ,
870
+ `%v may only contain Object types, it cannot contain: %v.` , objectType , ttype ,
871
871
)
872
872
if err != nil {
873
873
objectType .err = err
874
874
return objectType
875
875
}
876
876
if objectType .ResolveType == nil {
877
- err = invariant (
877
+ err = invariantf (
878
878
ttype .IsTypeOf != nil ,
879
- fmt . Sprintf ( `Union Type %v does not provide a "resolveType" function ` +
879
+ `Union Type %v does not provide a "resolveType" function ` +
880
880
`and possible Type %v does not provide a "isTypeOf" ` +
881
881
`function. There is no way to resolve this possible type ` +
882
- `during execution.` , objectType , ttype ) ,
882
+ `during execution.` , objectType , ttype ,
883
883
)
884
884
if err != nil {
885
885
objectType .err = err
@@ -980,19 +980,19 @@ func NewEnum(config EnumConfig) *Enum {
980
980
func (gt * Enum ) defineEnumValues (valueMap EnumValueConfigMap ) ([]* EnumValueDefinition , error ) {
981
981
values := []* EnumValueDefinition {}
982
982
983
- err := invariant (
983
+ err := invariantf (
984
984
len (valueMap ) > 0 ,
985
- fmt . Sprintf ( `%v values must be an object with value names as keys.` , gt ) ,
985
+ `%v values must be an object with value names as keys.` , gt ,
986
986
)
987
987
if err != nil {
988
988
return values , err
989
989
}
990
990
991
991
for valueName , valueConfig := range valueMap {
992
- err := invariant (
992
+ err := invariantf (
993
993
valueConfig != nil ,
994
- fmt . Sprintf ( `%v.%v must refer to an object with a "value" key ` +
995
- `representing an internal value but got: %v.` , gt , valueName , valueConfig ) ,
994
+ `%v.%v must refer to an object with a "value" key ` +
995
+ `representing an internal value but got: %v.` , gt , valueName , valueConfig ,
996
996
)
997
997
if err != nil {
998
998
return values , err
@@ -1173,9 +1173,9 @@ func (gt *InputObject) defineFieldMap() InputObjectFieldMap {
1173
1173
}
1174
1174
resultFieldMap := InputObjectFieldMap {}
1175
1175
1176
- err := invariant (
1176
+ err := invariantf (
1177
1177
len (fieldMap ) > 0 ,
1178
- fmt . Sprintf ( `%v fields must be an object with field names as keys or a function which return such an object.` , gt ) ,
1178
+ `%v fields must be an object with field names as keys or a function which return such an object.` , gt ,
1179
1179
)
1180
1180
if err != nil {
1181
1181
gt .err = err
@@ -1190,9 +1190,9 @@ func (gt *InputObject) defineFieldMap() InputObjectFieldMap {
1190
1190
if err != nil {
1191
1191
continue
1192
1192
}
1193
- err = invariant (
1193
+ err = invariantf (
1194
1194
fieldConfig .Type != nil ,
1195
- fmt . Sprintf ( `%v.%v field type must be Input Type but got: %v.` , gt , fieldName , fieldConfig .Type ) ,
1195
+ `%v.%v field type must be Input Type but got: %v.` , gt , fieldName , fieldConfig .Type ,
1196
1196
)
1197
1197
if err != nil {
1198
1198
gt .err = err
@@ -1253,7 +1253,7 @@ type List struct {
1253
1253
func NewList (ofType Type ) * List {
1254
1254
gl := & List {}
1255
1255
1256
- err := invariant (ofType != nil , fmt . Sprintf ( `Can only create List of a Type but got: %v.` , ofType ) )
1256
+ err := invariantf (ofType != nil , `Can only create List of a Type but got: %v.` , ofType )
1257
1257
if err != nil {
1258
1258
gl .err = err
1259
1259
return gl
@@ -1306,7 +1306,7 @@ func NewNonNull(ofType Type) *NonNull {
1306
1306
gl := & NonNull {}
1307
1307
1308
1308
_ , isOfTypeNonNull := ofType .(* NonNull )
1309
- err := invariant (ofType != nil && ! isOfTypeNonNull , fmt . Sprintf ( `Can only create NonNull of a Nullable Type but got: %v.` , ofType ) )
1309
+ err := invariantf (ofType != nil && ! isOfTypeNonNull , `Can only create NonNull of a Nullable Type but got: %v.` , ofType )
1310
1310
if err != nil {
1311
1311
gl .err = err
1312
1312
return gl
@@ -1333,8 +1333,8 @@ func (gl *NonNull) Error() error {
1333
1333
var NameRegExp , _ = regexp .Compile ("^[_a-zA-Z][_a-zA-Z0-9]*$" )
1334
1334
1335
1335
func assertValidName (name string ) error {
1336
- return invariant (
1336
+ return invariantf (
1337
1337
NameRegExp .MatchString (name ),
1338
- fmt . Sprintf ( `Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "%v" does not.` , name ),
1339
- )
1338
+ `Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "%v" does not.` , name )
1339
+
1340
1340
}
0 commit comments