Skip to content

Commit 42591cb

Browse files
feat!: Deletes GraphQLTypeReference
1 parent f8709f4 commit 42591cb

File tree

7 files changed

+10
-223
lines changed

7 files changed

+10
-223
lines changed

Sources/GraphQL/Execution/Execute.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -969,21 +969,6 @@ func completeValue(
969969
)
970970
}
971971

972-
// If field type is a TypeReference, find the type itself.
973-
if
974-
let returnType = returnType as? GraphQLTypeReference,
975-
let referencedType = info.schema.typeMap[returnType.name]
976-
{
977-
return try completeValue(
978-
exeContext: exeContext,
979-
returnType: referencedType,
980-
fieldASTs: fieldASTs,
981-
info: info,
982-
path: path,
983-
result: .success(exeContext.eventLoopGroup.any().makeSucceededFuture(result))
984-
)
985-
}
986-
987972
// Not reachable. All possible output types have been considered.
988973
throw GraphQLError(
989974
message: "Cannot complete value of unexpected type \"\(returnType)\"."

Sources/GraphQL/Execution/Values.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,6 @@ func getVariableValue(
9191
var type = typeFromAST(schema: schema, inputTypeAST: definitionAST.type)
9292
let variable = definitionAST.variable
9393

94-
if let typeReference = type as? GraphQLTypeReference {
95-
guard let referencedType = schema.typeMap[typeReference.name] else {
96-
throw GraphQLError(message: "Referenced type \(typeReference.name) not found")
97-
}
98-
type = referencedType
99-
}
100-
10194
guard let inputType = type as? GraphQLInputType else {
10295
throw GraphQLError(
10396
message:

Sources/GraphQL/Type/Definition.swift

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,6 @@ extension GraphQLObjectType: GraphQLCompositeType {}
7777
extension GraphQLInterfaceType: GraphQLCompositeType {}
7878
extension GraphQLUnionType: GraphQLCompositeType {}
7979

80-
protocol GraphQLTypeReferenceContainer: GraphQLNamedType {
81-
func replaceTypeReferences(typeMap: TypeMap) throws
82-
}
83-
84-
extension GraphQLObjectType: GraphQLTypeReferenceContainer {}
85-
extension GraphQLInterfaceType: GraphQLTypeReferenceContainer {}
86-
extension GraphQLInputObjectType: GraphQLTypeReferenceContainer {}
87-
8880
/**
8981
* These types may describe the parent context of a selection set.
9082
*/
@@ -339,15 +331,6 @@ public final class GraphQLObjectType {
339331
func getInterfaces() throws -> [GraphQLInterfaceType] {
340332
return try interfaces()
341333
}
342-
343-
func replaceTypeReferences(typeMap: TypeMap) throws {
344-
for field in try getFields() {
345-
try field.value.replaceTypeReferences(typeMap: typeMap)
346-
}
347-
for interface in try getInterfaces() {
348-
try interface.replaceTypeReferences(typeMap: typeMap)
349-
}
350-
}
351334
}
352335

353336
extension GraphQLObjectType: CustomDebugStringConvertible {
@@ -570,18 +553,6 @@ public final class GraphQLFieldDefinition {
570553
self.astNode = astNode
571554
}
572555

573-
func replaceTypeReferences(typeMap: TypeMap) throws {
574-
let resolvedType = try resolveTypeReference(type: type, typeMap: typeMap)
575-
576-
guard let outputType = resolvedType as? GraphQLOutputType else {
577-
throw GraphQLError(
578-
message: "Resolved type \"\(resolvedType)\" is not a valid output type."
579-
)
580-
}
581-
582-
type = outputType
583-
}
584-
585556
func toField() -> GraphQLField {
586557
return .init(
587558
type: type,
@@ -742,12 +713,6 @@ public final class GraphQLInterfaceType {
742713
func getInterfaces() throws -> [GraphQLInterfaceType] {
743714
return try interfaces()
744715
}
745-
746-
func replaceTypeReferences(typeMap: TypeMap) throws {
747-
for field in try getFields() {
748-
try field.value.replaceTypeReferences(typeMap: typeMap)
749-
}
750-
}
751716
}
752717

753718
extension GraphQLInterfaceType: CustomDebugStringConvertible {
@@ -1144,12 +1109,6 @@ public final class GraphQLInputObjectType {
11441109
fields: fields()
11451110
)
11461111
}
1147-
1148-
func replaceTypeReferences(typeMap: TypeMap) throws {
1149-
for field in try getFields() {
1150-
try field.value.replaceTypeReferences(typeMap: typeMap)
1151-
}
1152-
}
11531112
}
11541113

11551114
extension GraphQLInputObjectType: CustomDebugStringConvertible {
@@ -1239,18 +1198,6 @@ public final class InputObjectFieldDefinition {
12391198
self.deprecationReason = deprecationReason
12401199
self.astNode = astNode
12411200
}
1242-
1243-
func replaceTypeReferences(typeMap: TypeMap) throws {
1244-
let resolvedType = try resolveTypeReference(type: type, typeMap: typeMap)
1245-
1246-
guard let inputType = resolvedType as? GraphQLInputType else {
1247-
throw GraphQLError(
1248-
message: "Resolved type \"\(resolvedType)\" is not a valid input type."
1249-
)
1250-
}
1251-
1252-
type = inputType
1253-
}
12541201
}
12551202

12561203
public func isRequiredInputField(_ field: InputObjectFieldDefinition) -> Bool {
@@ -1288,19 +1235,9 @@ public final class GraphQLList {
12881235
ofType = type
12891236
}
12901237

1291-
@available(*, deprecated, message: "Just reference type directly.")
1292-
public init(_ name: String) {
1293-
ofType = GraphQLTypeReference(name)
1294-
}
1295-
12961238
var wrappedType: GraphQLType {
12971239
return ofType
12981240
}
1299-
1300-
func replaceTypeReferences(typeMap: TypeMap) throws -> GraphQLList {
1301-
let resolvedType = try resolveTypeReference(type: ofType, typeMap: typeMap)
1302-
return GraphQLList(resolvedType)
1303-
}
13041241
}
13051242

13061243
extension GraphQLList: CustomDebugStringConvertible {
@@ -1354,26 +1291,9 @@ public final class GraphQLNonNull {
13541291
ofType = type
13551292
}
13561293

1357-
@available(*, deprecated, message: "Just reference type directly.")
1358-
public init(_ name: String) {
1359-
ofType = GraphQLTypeReference(name)
1360-
}
1361-
13621294
var wrappedType: GraphQLType {
13631295
return ofType
13641296
}
1365-
1366-
func replaceTypeReferences(typeMap: TypeMap) throws -> GraphQLNonNull {
1367-
let resolvedType = try resolveTypeReference(type: ofType, typeMap: typeMap)
1368-
1369-
guard let nullableType = resolvedType as? GraphQLNullableType else {
1370-
throw GraphQLError(
1371-
message: "Resolved type \"\(resolvedType)\" is not a valid nullable type."
1372-
)
1373-
}
1374-
1375-
return GraphQLNonNull(nullableType)
1376-
}
13771297
}
13781298

13791299
extension GraphQLNonNull: CustomDebugStringConvertible {
@@ -1391,25 +1311,3 @@ extension GraphQLNonNull: Hashable {
13911311
return lhs.hashValue == rhs.hashValue
13921312
}
13931313
}
1394-
1395-
/**
1396-
* A special type to allow object/interface/input types to reference itself. It's replaced with the real type
1397-
* object when the schema is built.
1398-
*/
1399-
@available(*, deprecated, message: "Use `fields` closure to lazily reference types.")
1400-
public final class GraphQLTypeReference: GraphQLType, GraphQLOutputType, GraphQLInputType,
1401-
GraphQLNullableType, GraphQLNamedType
1402-
{
1403-
public let name: String
1404-
public let kind: TypeKind = .typeReference
1405-
1406-
public init(_ name: String) {
1407-
self.name = name
1408-
}
1409-
}
1410-
1411-
extension GraphQLTypeReference: CustomDebugStringConvertible {
1412-
public var debugDescription: String {
1413-
return name
1414-
}
1415-
}

Sources/GraphQL/Type/Introspection.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,6 @@ public enum TypeKind: String, Encodable {
435435
case inputObject = "INPUT_OBJECT"
436436
case list = "LIST"
437437
case nonNull = "NON_NULL"
438-
case typeReference = "TYPE_REFERENCE"
439438
}
440439

441440
let __TypeKind = try! GraphQLEnumType(

Sources/GraphQL/Type/Schema.swift

Lines changed: 8 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ public final class GraphQLSchema {
104104
}
105105

106106
allReferencedTypes = try typeMapReducer(typeMap: allReferencedTypes, type: __Schema)
107-
try replaceTypeReferences(typeMap: allReferencedTypes)
108107

109108
// Storing the resulting map for reference by the schema.
110109
var typeMap = TypeMap()
@@ -326,26 +325,15 @@ func typeMapReducer(typeMap: TypeMap, type: GraphQLType) throws -> TypeMap {
326325
}
327326

328327
if let existingType = typeMap[type.name] {
329-
if existingType is GraphQLTypeReference {
330-
if type is GraphQLTypeReference {
331-
// Just short circuit because they're both type references
332-
return typeMap
333-
}
334-
// Otherwise, fall through and override the type reference
328+
if !(existingType == type) {
329+
throw GraphQLError(
330+
message:
331+
"Schema must contain unique named types but contains multiple " +
332+
"types named \"\(type.name)\"."
333+
)
335334
} else {
336-
if type is GraphQLTypeReference {
337-
// Just ignore the reference and keep the concrete one
338-
return typeMap
339-
} else if !(existingType == type) {
340-
throw GraphQLError(
341-
message:
342-
"Schema must contain unique named types but contains multiple " +
343-
"types named \"\(type.name)\"."
344-
)
345-
} else {
346-
// Otherwise, it's already been defined so short circuit
347-
return typeMap
348-
}
335+
// Otherwise, it's already been defined so short circuit
336+
return typeMap
349337
}
350338
}
351339

@@ -390,56 +378,6 @@ func typeMapReducer(typeMap: TypeMap, type: GraphQLType) throws -> TypeMap {
390378
return typeMap
391379
}
392380

393-
func replaceTypeReferences(typeMap: TypeMap) throws {
394-
for type in typeMap {
395-
if let typeReferenceContainer = type.value as? GraphQLTypeReferenceContainer {
396-
try typeReferenceContainer.replaceTypeReferences(typeMap: typeMap)
397-
}
398-
}
399-
400-
// Check that no type names map to TypeReferences. That is, they have all been resolved to
401-
// actual types.
402-
for (typeName, graphQLNamedType) in typeMap {
403-
if graphQLNamedType is GraphQLTypeReference {
404-
throw GraphQLError(
405-
message: "Type \"\(typeName)\" was referenced but not defined."
406-
)
407-
}
408-
}
409-
}
410-
411-
func resolveTypeReference(type: GraphQLType, typeMap: TypeMap) throws -> GraphQLType {
412-
if let type = type as? GraphQLTypeReference {
413-
guard let resolvedType = typeMap[type.name] else {
414-
throw GraphQLError(
415-
message: "Type \"\(type.name)\" not found in schema."
416-
)
417-
}
418-
419-
return resolvedType
420-
}
421-
422-
if let type = type as? GraphQLList {
423-
return try type.replaceTypeReferences(typeMap: typeMap)
424-
}
425-
426-
if let type = type as? GraphQLNonNull {
427-
return try type.replaceTypeReferences(typeMap: typeMap)
428-
}
429-
430-
return type
431-
}
432-
433-
func resolveTypeReferences(types: [GraphQLType], typeMap: TypeMap) throws -> [GraphQLType] {
434-
var resolvedTypes: [GraphQLType] = []
435-
436-
for type in types {
437-
try resolvedTypes.append(resolveTypeReference(type: type, typeMap: typeMap))
438-
}
439-
440-
return resolvedTypes
441-
}
442-
443381
class GraphQLSchemaNormalizedConfig {
444382
var description: String?
445383
var query: GraphQLObjectType?

Sources/GraphQL/Utilities/TypeComparators.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ func == (lhs: GraphQLType, rhs: GraphQLType) -> Bool {
5555
if let r = rhs as? GraphQLNonNull {
5656
return l == r
5757
}
58-
case let l as GraphQLTypeReference:
59-
if let r = rhs as? GraphQLTypeReference {
60-
return l.name == r.name
61-
}
6258
default:
6359
return false
6460
}

Tests/GraphQLTests/TypeTests/GraphQLSchemaTests.swift

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -153,30 +153,8 @@ class GraphQLSchemaTests: XCTestCase {
153153
]
154154
)
155155

156-
let schema = try GraphQLSchema(query: query, types: [object1, object2])
157-
for (_, graphQLNamedType) in schema.typeMap {
158-
XCTAssertFalse(graphQLNamedType is GraphQLTypeReference)
159-
}
160-
}
161-
162-
func testAssertSchemaFailsWhenObjectNotDefined() throws {
163-
let object1 = try GraphQLObjectType(
164-
name: "Object1",
165-
fields: [
166-
"object2": GraphQLField(
167-
type: GraphQLTypeReference("Object2")
168-
),
169-
]
170-
)
171-
let query = try GraphQLObjectType(
172-
name: "Query",
173-
fields: [
174-
"object1": GraphQLField(type: GraphQLTypeReference("Object1")),
175-
]
176-
)
177-
178-
XCTAssertThrowsError(
179-
_ = try GraphQLSchema(query: query, types: [object1])
156+
XCTAssertNoThrow(
157+
try GraphQLSchema(query: query, types: [object1, object2])
180158
)
181159
}
182160
}

0 commit comments

Comments
 (0)