@@ -71,32 +71,43 @@ public final class GraphQLSchema {
71
71
self . directives = directives. isEmpty ? specifiedDirectives : directives
72
72
73
73
// Build type map now to detect any errors within this schema.
74
- var initialTypes : [ GraphQLNamedType ] = [ ]
75
74
75
+ var typeMap = TypeMap ( )
76
+
77
+ // To preserve order of user-provided types, we add first to add them to
78
+ // the set of "collected" types, so `collectReferencedTypes` ignore them.
79
+ for type in types {
80
+ typeMap [ type. name] = type
81
+ }
76
82
if !types. isEmpty {
77
- initialTypes. append ( contentsOf: types)
83
+ for type in types {
84
+ // When we ready to process this type, we remove it from "collected" types
85
+ // and then add it together with all dependent types in the correct position.
86
+ typeMap [ type. name] = nil
87
+ typeMap = try typeMapReducer ( typeMap: typeMap, type: type)
88
+ }
78
89
}
79
90
80
91
if let query = queryType {
81
- initialTypes . append ( query)
92
+ typeMap = try typeMapReducer ( typeMap : typeMap , type : query)
82
93
}
83
94
84
95
if let mutation = mutationType {
85
- initialTypes . append ( mutation)
96
+ typeMap = try typeMapReducer ( typeMap : typeMap , type : mutation)
86
97
}
87
98
88
99
if let subscription = subscriptionType {
89
- initialTypes . append ( subscription)
100
+ typeMap = try typeMapReducer ( typeMap : typeMap , type : subscription)
90
101
}
91
102
92
- initialTypes. append ( __Schema)
93
-
94
- var typeMap = TypeMap ( )
95
-
96
- for type in initialTypes {
97
- typeMap = try typeMapReducer ( typeMap: typeMap, type: type)
103
+ for directive in self . directives {
104
+ for arg in directive. args {
105
+ typeMap = try typeMapReducer ( typeMap: typeMap, type: arg. type)
106
+ }
98
107
}
99
108
109
+ typeMap = try typeMapReducer ( typeMap: typeMap, type: __Schema)
110
+
100
111
self . typeMap = typeMap
101
112
try replaceTypeReferences ( typeMap: typeMap)
102
113
0 commit comments