@@ -9,17 +9,21 @@ final class TypeInfo {
9
9
var parentTypeStack : [ GraphQLCompositeType ? ]
10
10
var inputTypeStack : [ GraphQLInputType ? ]
11
11
var fieldDefStack : [ GraphQLFieldDefinition ? ]
12
+ var defaultValueStack : [ Map ]
12
13
var directive : GraphQLDirective ?
13
14
var argument : GraphQLArgumentDefinition ?
15
+ var enumValue : GraphQLEnumValueDefinition ?
14
16
15
17
init ( schema: GraphQLSchema ) {
16
18
self . schema = schema
17
19
typeStack = [ ]
18
20
parentTypeStack = [ ]
19
21
inputTypeStack = [ ]
20
22
fieldDefStack = [ ]
23
+ defaultValueStack = [ ]
21
24
directive = nil
22
25
argument = nil
26
+ enumValue = nil
23
27
}
24
28
25
29
var type : GraphQLOutputType ? {
@@ -50,6 +54,13 @@ final class TypeInfo {
50
54
return nil
51
55
}
52
56
57
+ var defaultValue : Map ? {
58
+ if !defaultValueStack. isEmpty {
59
+ return defaultValueStack [ defaultValueStack. count - 1 ]
60
+ }
61
+ return nil
62
+ }
63
+
53
64
func enter( node: Node ) {
54
65
switch node {
55
66
case is SelectionSet :
@@ -64,13 +75,17 @@ final class TypeInfo {
64
75
65
76
case let node as Field :
66
77
var fieldDef : GraphQLFieldDefinition ?
78
+ var fieldType : GraphQLType ?
67
79
68
80
if let parentType = parentType {
69
81
fieldDef = getFieldDef ( schema: schema, parentType: parentType, fieldAST: node)
82
+ if let fieldDef = fieldDef {
83
+ fieldType = fieldDef. type
84
+ }
70
85
}
71
86
72
87
fieldDefStack. append ( fieldDef)
73
- typeStack. append ( fieldDef ? . type )
88
+ typeStack. append ( fieldType as? GraphQLOutputType )
74
89
75
90
case let node as Directive :
76
91
directive = schema. getDirective ( name: node. name. value)
@@ -94,7 +109,7 @@ final class TypeInfo {
94
109
if let typeConditionAST = node. typeCondition {
95
110
outputType = typeFromAST ( schema: schema, inputTypeAST: typeConditionAST)
96
111
} else {
97
- outputType = type
112
+ outputType = getNamedType ( type: type )
98
113
}
99
114
typeStack. append ( outputType as? GraphQLOutputType )
100
115
@@ -107,33 +122,59 @@ final class TypeInfo {
107
122
inputTypeStack. append ( inputType as? GraphQLInputType )
108
123
109
124
case let node as Argument :
110
- var argType : GraphQLInputType ?
125
+ var argDef : GraphQLArgumentDefinition ?
111
126
112
127
if let directive = directive {
113
- if let argDef = directive. args. find ( { $0. name == node. name. value } ) {
114
- argType = argDef. type
115
- argument = argDef
128
+ if let argDefinition = directive. args. find ( { $0. name == node. name. value } ) {
129
+ argDef = argDefinition
116
130
}
117
131
} else if let fieldDef = fieldDef {
118
- if let argDef = fieldDef. args. find ( { $0. name == node. name. value } ) {
119
- argType = argDef. type
120
- argument = argDef
132
+ if let argDefinition = fieldDef. args. find ( { $0. name == node. name. value } ) {
133
+ argDef = argDefinition
121
134
}
122
135
}
123
136
124
- inputTypeStack. append ( argType)
137
+ argument = argDef
138
+ defaultValueStack. append ( argDef? . defaultValue ?? . undefined)
139
+ inputTypeStack. append ( argDef? . type)
140
+
141
+ case is ListType , is ListValue :
142
+ let listType = getNullableType ( type: inputType)
143
+ let itemType : GraphQLType ?
125
144
126
- case is ListType : // could be ListValue
127
- if let listType = getNullableType ( type: inputType) as? GraphQLList {
128
- inputTypeStack. append ( listType. ofType as? GraphQLInputType )
145
+ if let listType = listType as? GraphQLList {
146
+ itemType = listType. ofType
147
+ } else {
148
+ itemType = listType
129
149
}
150
+ defaultValueStack. append ( . undefined)
130
151
131
- inputTypeStack. append ( nil )
152
+ if let itemType = itemType as? GraphQLInputType {
153
+ inputTypeStack. append ( itemType)
154
+ } else {
155
+ inputTypeStack. append ( nil )
156
+ }
132
157
133
158
case let node as ObjectField :
134
- if let objectType = getNamedType ( type: inputType) as? GraphQLInputObjectType {
135
- let inputField = objectType. fields [ node. name. value]
136
- inputTypeStack. append ( inputField? . type)
159
+ let objectType = getNamedType ( type: inputType)
160
+ var inputFieldType : GraphQLInputType ?
161
+ var inputField : InputObjectFieldDefinition ?
162
+
163
+ if let objectType = objectType as? GraphQLInputObjectType {
164
+ inputField = objectType. fields [ node. name. value]
165
+ if let inputField = inputField {
166
+ inputFieldType = inputField. type
167
+ }
168
+ }
169
+
170
+ defaultValueStack. append ( inputField? . defaultValue ?? . undefined)
171
+ inputTypeStack. append ( inputFieldType)
172
+
173
+ case let node as EnumValue :
174
+ if let enumType = getNamedType ( type: inputType) as? GraphQLEnumType {
175
+ enumValue = enumType. nameLookup [ node. value]
176
+ } else {
177
+ enumValue = nil
137
178
}
138
179
139
180
default :
@@ -161,11 +202,16 @@ final class TypeInfo {
161
202
162
203
case is Argument :
163
204
argument = nil
205
+ _ = defaultValueStack. popLast ( )
164
206
_ = inputTypeStack. popLast ( )
165
207
166
- case is ListType /* could be listValue */, is ObjectField :
208
+ case is ListType , is ListValue , is ObjectField :
209
+ _ = defaultValueStack. popLast ( )
167
210
_ = inputTypeStack. popLast ( )
168
211
212
+ case is EnumValue :
213
+ enumValue = nil
214
+
169
215
default :
170
216
break
171
217
}
0 commit comments