@@ -77,8 +77,9 @@ protocol GraphQLTypeReferenceContainer : GraphQLNamedType {
77
77
func replaceTypeReferences( typeMap: TypeMap ) throws
78
78
}
79
79
80
- extension GraphQLObjectType : GraphQLTypeReferenceContainer { }
81
- extension GraphQLInterfaceType : GraphQLTypeReferenceContainer { }
80
+ extension GraphQLObjectType : GraphQLTypeReferenceContainer { }
81
+ extension GraphQLInterfaceType : GraphQLTypeReferenceContainer { }
82
+ extension GraphQLInputObjectType : GraphQLTypeReferenceContainer { }
82
83
83
84
/**
84
85
* These types may describe the parent context of a selection set.
@@ -1171,13 +1172,13 @@ extension GraphQLEnumValueDefinition : KeySubscriptable {
1171
1172
public final class GraphQLInputObjectType {
1172
1173
public let name : String
1173
1174
public let description : String ?
1174
- public let fields : InputObjectFieldMap
1175
+ public let fields : InputObjectFieldDefinitionMap
1175
1176
public let kind : TypeKind = . inputObject
1176
1177
1177
1178
public init (
1178
1179
name: String ,
1179
1180
description: String ? = nil ,
1180
- fields: InputObjectConfigFieldMap
1181
+ fields: InputObjectFieldMap = [ : ]
1181
1182
) throws {
1182
1183
try assertValid ( name: name)
1183
1184
self . name = name
@@ -1187,6 +1188,12 @@ public final class GraphQLInputObjectType {
1187
1188
fields: fields
1188
1189
)
1189
1190
}
1191
+
1192
+ func replaceTypeReferences( typeMap: TypeMap ) throws {
1193
+ for field in fields {
1194
+ try field. value. replaceTypeReferences ( typeMap: typeMap)
1195
+ }
1196
+ }
1190
1197
}
1191
1198
1192
1199
extension GraphQLInputObjectType : Encodable {
@@ -1233,32 +1240,32 @@ extension GraphQLInputObjectType : Hashable {
1233
1240
1234
1241
func defineInputObjectFieldMap(
1235
1242
name: String ,
1236
- fields: InputObjectConfigFieldMap
1237
- ) throws -> InputObjectFieldMap {
1243
+ fields: InputObjectFieldMap
1244
+ ) throws -> InputObjectFieldDefinitionMap {
1238
1245
guard !fields. isEmpty else {
1239
1246
throw GraphQLError (
1240
1247
message:
1241
- " \( name) fields must be an object with field names as keys or a " +
1242
- " function which returns such an object. "
1248
+ " \( name) fields must be an object with field names as " +
1249
+ " keys or a function which returns such an object."
1243
1250
)
1244
1251
}
1245
1252
1246
- var resultFieldMap = InputObjectFieldMap ( )
1253
+ var definitionMap = InputObjectFieldDefinitionMap ( )
1247
1254
1248
- for (fieldName , field) in fields {
1249
- try assertValid ( name: fieldName )
1255
+ for (name , field) in fields {
1256
+ try assertValid ( name: name )
1250
1257
1251
- let newField = InputObjectFieldDefinition (
1252
- name: fieldName,
1253
- description: field. description,
1258
+ let definition = InputObjectFieldDefinition (
1259
+ name: name,
1254
1260
type: field. type,
1261
+ description: field. description,
1255
1262
defaultValue: field. defaultValue
1256
1263
)
1257
1264
1258
- resultFieldMap [ fieldName ] = newField
1265
+ definitionMap [ name ] = definition
1259
1266
}
1260
1267
1261
- return resultFieldMap
1268
+ return definitionMap
1262
1269
}
1263
1270
1264
1271
public struct InputObjectField {
@@ -1273,13 +1280,37 @@ public struct InputObjectField {
1273
1280
}
1274
1281
}
1275
1282
1276
- public typealias InputObjectConfigFieldMap = [ String : InputObjectField ]
1283
+ public typealias InputObjectFieldMap = [ String : InputObjectField ]
1277
1284
1278
- public struct InputObjectFieldDefinition {
1285
+ public final class InputObjectFieldDefinition {
1279
1286
public let name : String
1287
+ public internal( set) var type : GraphQLInputType
1280
1288
public let description : String ?
1281
- public let type : GraphQLInputType
1282
1289
public let defaultValue : String ?
1290
+
1291
+ init (
1292
+ name: String ,
1293
+ type: GraphQLInputType ,
1294
+ description: String ? = nil ,
1295
+ defaultValue: String ? = nil
1296
+ ) {
1297
+ self . name = name
1298
+ self . type = type
1299
+ self . description = description
1300
+ self . defaultValue = defaultValue
1301
+ }
1302
+
1303
+ func replaceTypeReferences( typeMap: TypeMap ) throws {
1304
+ let resolvedType = try resolveTypeReference ( type: type, typeMap: typeMap)
1305
+
1306
+ guard let inputType = resolvedType as? GraphQLInputType else {
1307
+ throw GraphQLError (
1308
+ message: " Resolved type \" \( resolvedType) \" is not a valid input type. "
1309
+ )
1310
+ }
1311
+
1312
+ self . type = inputType
1313
+ }
1283
1314
}
1284
1315
1285
1316
extension InputObjectFieldDefinition : Encodable {
@@ -1316,7 +1347,7 @@ extension InputObjectFieldDefinition : KeySubscriptable {
1316
1347
}
1317
1348
}
1318
1349
1319
- public typealias InputObjectFieldMap = [ String : InputObjectFieldDefinition ]
1350
+ public typealias InputObjectFieldDefinitionMap = [ String : InputObjectFieldDefinition ]
1320
1351
1321
1352
/**
1322
1353
* List Modifier
@@ -1492,10 +1523,10 @@ extension GraphQLNonNull : Hashable {
1492
1523
}
1493
1524
1494
1525
/**
1495
- * A special type to allow object/interface types to reference itself. It's replaced with the real type
1526
+ * A special type to allow object/interface/input types to reference itself. It's replaced with the real type
1496
1527
* object when the schema is built.
1497
1528
*/
1498
- public final class GraphQLTypeReference : GraphQLType , GraphQLOutputType , GraphQLNullableType , GraphQLNamedType {
1529
+ public final class GraphQLTypeReference : GraphQLType , GraphQLOutputType , GraphQLInputType , GraphQLNullableType , GraphQLNamedType {
1499
1530
public let name : String
1500
1531
public let kind : TypeKind = . typeReference
1501
1532
0 commit comments