@@ -71,32 +71,43 @@ public final class GraphQLSchema {
7171 self . directives = directives. isEmpty ? specifiedDirectives : directives
7272
7373 // Build type map now to detect any errors within this schema.
74- var initialTypes : [ GraphQLNamedType ] = [ ]
7574
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+ }
7682 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+ }
7889 }
7990
8091 if let query = queryType {
81- initialTypes . append ( query)
92+ typeMap = try typeMapReducer ( typeMap : typeMap , type : query)
8293 }
8394
8495 if let mutation = mutationType {
85- initialTypes . append ( mutation)
96+ typeMap = try typeMapReducer ( typeMap : typeMap , type : mutation)
8697 }
8798
8899 if let subscription = subscriptionType {
89- initialTypes . append ( subscription)
100+ typeMap = try typeMapReducer ( typeMap : typeMap , type : subscription)
90101 }
91102
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+ }
98107 }
99108
109+ typeMap = try typeMapReducer ( typeMap: typeMap, type: __Schema)
110+
100111 self . typeMap = typeMap
101112 try replaceTypeReferences ( typeMap: typeMap)
102113
0 commit comments