11import Foundation
22import NIO
3+ import OrderedCollections
34
45/**
56 * These are all of the possible kinds of types.
@@ -171,35 +172,22 @@ public final class GraphQLScalarType {
171172 public let kind : TypeKind = . scalar
172173
173174 let serialize : ( Any ) throws -> Map
174- let parseValue : ( ( Map ) throws -> Map ) ?
175- let parseLiteral : ( ( Value ) throws -> Map ) ?
176-
177- public init (
178- name: String ,
179- description: String ? = nil ,
180- serialize: @escaping ( Any ) throws -> Map
181- ) throws {
182- try assertValid ( name: name)
183- self . name = name
184- self . description = description
185- self . serialize = serialize
186- parseValue = nil
187- parseLiteral = nil
188- }
175+ let parseValue : ( Map ) throws -> Map
176+ let parseLiteral : ( Value ) throws -> Map
189177
190178 public init (
191179 name: String ,
192180 description: String ? = nil ,
193181 serialize: @escaping ( Any ) throws -> Map ,
194- parseValue: @escaping ( Map ) throws -> Map ,
195- parseLiteral: @escaping ( Value ) throws -> Map
182+ parseValue: ( ( Map ) throws -> Map ) ? = nil ,
183+ parseLiteral: ( ( Value ) throws -> Map ) ? = nil
196184 ) throws {
197185 try assertValid ( name: name)
198186 self . name = name
199187 self . description = description
200188 self . serialize = serialize
201- self . parseValue = parseValue
202- self . parseLiteral = parseLiteral
189+ self . parseValue = parseValue ?? defaultParseValue
190+ self . parseLiteral = parseLiteral ?? defaultParseLiteral
203191 }
204192
205193 // Serializes an internal value to include in a response.
@@ -209,15 +197,23 @@ public final class GraphQLScalarType {
209197
210198 // Parses an externally provided value to use as an input.
211199 public func parseValue( value: Map ) throws -> Map {
212- return try parseValue ? ( value) ?? Map . null
200+ return try parseValue ( value)
213201 }
214202
215203 // Parses an externally provided literal value to use as an input.
216204 public func parseLiteral( valueAST: Value ) throws -> Map {
217- return try parseLiteral ? ( valueAST) ?? Map . null
205+ return try parseLiteral ( valueAST)
218206 }
219207}
220208
209+ let defaultParseValue : ( ( Map ) throws -> Map ) = { value in
210+ value
211+ }
212+
213+ let defaultParseLiteral : ( ( Value ) throws -> Map ) = { value in
214+ try valueFromASTUntyped ( valueAST: value)
215+ }
216+
221217extension GraphQLScalarType : Encodable {
222218 private enum CodingKeys : String , CodingKey {
223219 case name
@@ -513,7 +509,7 @@ public struct GraphQLResolveInfo {
513509 public let variableValues : [ String : Any ]
514510}
515511
516- public typealias GraphQLFieldMap = [ String : GraphQLField ]
512+ public typealias GraphQLFieldMap = OrderedDictionary < String , GraphQLField >
517513
518514public struct GraphQLField {
519515 public let type : GraphQLOutputType
@@ -573,7 +569,7 @@ public struct GraphQLField {
573569 }
574570}
575571
576- public typealias GraphQLFieldDefinitionMap = [ String : GraphQLFieldDefinition ]
572+ public typealias GraphQLFieldDefinitionMap = OrderedDictionary < String , GraphQLFieldDefinition >
577573
578574public final class GraphQLFieldDefinition {
579575 public let name : String
@@ -659,7 +655,7 @@ extension GraphQLFieldDefinition: KeySubscriptable {
659655 }
660656}
661657
662- public typealias GraphQLArgumentConfigMap = [ String : GraphQLArgument ]
658+ public typealias GraphQLArgumentConfigMap = OrderedDictionary < String , GraphQLArgument >
663659
664660public struct GraphQLArgument {
665661 public let type : GraphQLInputType
@@ -1018,7 +1014,7 @@ public final class GraphQLEnumType {
10181014 let mapValue = try map ( from: value)
10191015 guard let enumValue = valueLookup [ mapValue] else {
10201016 throw GraphQLError (
1021- message: " Enum ' \ ( name) ' cannot represent value ' \( mapValue) ' ."
1017+ message: " Enum \" \ ( name) \" cannot represent value: \( mapValue) . "
10221018 )
10231019 }
10241020 return . string( enumValue. name)
@@ -1027,13 +1023,13 @@ public final class GraphQLEnumType {
10271023 public func parseValue( value: Map ) throws -> Map {
10281024 guard let valueStr = value. string else {
10291025 throw GraphQLError (
1030- message: " Enum ' \ ( name) ' cannot represent non-string value ' \( value) ' ." +
1026+ message: " Enum \" \ ( name) \" cannot represent non-string value: \( value) . " +
10311027 didYouMeanEnumValue( unknownValueStr: value. description)
10321028 )
10331029 }
10341030 guard let enumValue = nameLookup [ valueStr] else {
10351031 throw GraphQLError (
1036- message: " Value ' \ ( valueStr) ' does not exist in ' \ ( name) ' enum." +
1032+ message: " Value \" \ ( valueStr) \" does not exist in \" \ ( name) \" enum. " +
10371033 didYouMeanEnumValue( unknownValueStr: valueStr)
10381034 )
10391035 }
@@ -1043,14 +1039,14 @@ public final class GraphQLEnumType {
10431039 public func parseLiteral( valueAST: Value ) throws -> Map {
10441040 guard let enumNode = valueAST as? EnumValue else {
10451041 throw GraphQLError (
1046- message: " Enum ' \ ( name) ' cannot represent non-enum value ' \( valueAST) ' ." +
1047- didYouMeanEnumValue( unknownValueStr: " \( valueAST) " ) ,
1042+ message: " Enum \" \ ( name) \" cannot represent non-enum value: \( print ( ast : valueAST) ) . " +
1043+ didYouMeanEnumValue( unknownValueStr: print ( ast : valueAST) ) ,
10481044 nodes: [ valueAST]
10491045 )
10501046 }
10511047 guard let enumValue = nameLookup [ enumNode. value] else {
10521048 throw GraphQLError (
1053- message: " Value ' \ ( enumNode) ' does not exist in ' \ ( name) ' enum." +
1049+ message: " Value \" \ ( enumNode. value ) \" does not exist in \" \ ( name) \" enum. " +
10541050 didYouMeanEnumValue( unknownValueStr: enumNode. value) ,
10551051 nodes: [ valueAST]
10561052 )
@@ -1136,7 +1132,7 @@ func defineEnumValues(
11361132 return definitions
11371133}
11381134
1139- public typealias GraphQLEnumValueMap = [ String : GraphQLEnumValue ]
1135+ public typealias GraphQLEnumValueMap = OrderedDictionary < String , GraphQLEnumValue >
11401136
11411137public struct GraphQLEnumValue {
11421138 public let value : Map
@@ -1317,7 +1313,7 @@ public struct InputObjectField {
13171313 }
13181314}
13191315
1320- public typealias InputObjectFieldMap = [ String : InputObjectField ]
1316+ public typealias InputObjectFieldMap = OrderedDictionary < String , InputObjectField >
13211317
13221318public final class InputObjectFieldDefinition {
13231319 public let name : String
@@ -1384,7 +1380,14 @@ extension InputObjectFieldDefinition: KeySubscriptable {
13841380 }
13851381}
13861382
1387- public typealias InputObjectFieldDefinitionMap = [ String : InputObjectFieldDefinition ]
1383+ public func isRequiredInputField( _ field: InputObjectFieldDefinition ) -> Bool {
1384+ return field. type is GraphQLNonNull && field. defaultValue == nil
1385+ }
1386+
1387+ public typealias InputObjectFieldDefinitionMap = OrderedDictionary <
1388+ String ,
1389+ InputObjectFieldDefinition
1390+ >
13881391
13891392/**
13901393 * List Modifier
0 commit comments