@@ -21,6 +21,7 @@ public class Context: @unchecked Sendable {
2121 onTriggerWatch ( )
2222 }
2323}
24+
2425// Scalars must be represented by a Swift type of the same name, conforming to the Scalar protocol
2526public struct EmailAddress : Scalar {
2627 let email : String
@@ -31,16 +32,18 @@ public struct EmailAddress: Scalar {
3132
3233 // Codability conformance. Required for usage in InputObject
3334 public init ( from decoder: any Decoder ) throws {
34- self . email = try decoder. singleValueContainer ( ) . decode ( String . self)
35+ email = try decoder. singleValueContainer ( ) . decode ( String . self)
3536 }
37+
3638 public func encode( to encoder: any Encoder ) throws {
37- try self . email. encode ( to: encoder)
39+ try email. encode ( to: encoder)
3840 }
3941
4042 // Scalar conformance. Not necessary, but default methods are very inefficient.
4143 public static func serialize( this: Self ) throws -> Map {
4244 return . string( this. email)
4345 }
46+
4447 public static func parseValue( map: Map ) throws -> Map {
4548 switch map {
4649 case . string:
@@ -49,6 +52,7 @@ public struct EmailAddress: Scalar {
4952 throw GraphQLError ( message: " EmailAddress cannot represent non-string value: \( map) " )
5053 }
5154 }
55+
5256 public static func parseLiteral( value: any Value ) throws -> Map {
5357 guard let ast = value as? StringValue else {
5458 throw GraphQLError (
@@ -66,6 +70,7 @@ struct Resolvers: ResolversProtocol {
6670 typealias Mutation = HelloWorldServer . Mutation
6771 typealias Subscription = HelloWorldServer . Subscription
6872}
73+
6974struct User : UserProtocol {
7075 // User can choose structure
7176 let id : String
@@ -75,31 +80,37 @@ struct User: UserProtocol {
7580 let role : Role ?
7681
7782 // Required implementations
78- func id( context: Context , info: GraphQL . GraphQLResolveInfo ) async throws -> String {
83+ func id( context _ : Context , info _ : GraphQL . GraphQLResolveInfo ) async throws -> String {
7984 return id
8085 }
81- func name( context: Context , info: GraphQL . GraphQLResolveInfo ) async throws -> String {
86+
87+ func name( context _: Context , info _: GraphQL . GraphQLResolveInfo ) async throws -> String {
8288 return name
8389 }
84- func email( context: Context , info: GraphQL . GraphQLResolveInfo ) async throws -> EmailAddress {
90+
91+ func email( context _: Context , info _: GraphQL . GraphQLResolveInfo ) async throws -> EmailAddress {
8592 return EmailAddress ( email: email)
8693 }
87- func age( context: Context , info: GraphQL . GraphQLResolveInfo ) async throws -> Int ? {
94+
95+ func age( context _: Context , info _: GraphQL . GraphQLResolveInfo ) async throws -> Int ? {
8896 return age
8997 }
90- func role( context: Context , info: GraphQL . GraphQLResolveInfo ) async throws -> Role ? {
98+
99+ func role( context _: Context , info _: GraphQL . GraphQLResolveInfo ) async throws -> Role ? {
91100 return role
92101 }
93102}
103+
94104struct Contact : ContactProtocol {
95105 // User can choose structure
96106 let email : String
97107
98108 // Required implementations
99- func email( context: Context , info: GraphQL . GraphQLResolveInfo ) async throws -> EmailAddress {
109+ func email( context _ : Context , info _ : GraphQL . GraphQLResolveInfo ) async throws -> EmailAddress {
100110 return EmailAddress ( email: email)
101111 }
102112}
113+
103114struct Post : PostProtocol {
104115 // User can choose structure
105116 let id : String
@@ -108,42 +119,49 @@ struct Post: PostProtocol {
108119 let authorId : String
109120
110121 // Required implementations
111- func id( context: Context , info: GraphQL . GraphQLResolveInfo ) async throws -> String {
122+ func id( context _ : Context , info _ : GraphQL . GraphQLResolveInfo ) async throws -> String {
112123 return id
113124 }
114- func title( context: Context , info: GraphQL . GraphQLResolveInfo ) async throws -> String {
125+
126+ func title( context _: Context , info _: GraphQL . GraphQLResolveInfo ) async throws -> String {
115127 return title
116128 }
117- func content( context: Context , info: GraphQL . GraphQLResolveInfo ) async throws -> String {
129+
130+ func content( context _: Context , info _: GraphQL . GraphQLResolveInfo ) async throws -> String {
118131 return content
119132 }
120- func author( context: Context , info: GraphQL . GraphQLResolveInfo ) async throws -> any UserProtocol {
133+
134+ func author( context: Context , info _: GraphQL . GraphQLResolveInfo ) async throws -> any UserProtocol {
121135 return context. users [ authorId] !
122136 }
123137}
124138
125139struct Query : QueryProtocol {
126140 // Required implementations
127- static func user( id: String , context: Context , info: GraphQL . GraphQLResolveInfo ) async throws -> ( any UserProtocol ) ? {
141+ static func user( id: String , context: Context , info _ : GraphQL . GraphQLResolveInfo ) async throws -> ( any UserProtocol ) ? {
128142 return context. users [ id]
129143 }
130- static func users( context: Context , info: GraphQL . GraphQLResolveInfo ) async throws -> [ any UserProtocol ] {
144+
145+ static func users( context: Context , info _: GraphQL . GraphQLResolveInfo ) async throws -> [ any UserProtocol ] {
131146 return context. users. values. map { $0 as any UserProtocol }
132147 }
133- static func post( id: String , context: Context , info: GraphQL . GraphQLResolveInfo ) async throws -> ( any PostProtocol ) ? {
148+
149+ static func post( id: String , context: Context , info _: GraphQL . GraphQLResolveInfo ) async throws -> ( any PostProtocol ) ? {
134150 return context. posts [ id]
135151 }
136- static func posts( limit: Int ? , context: Context , info: GraphQL . GraphQLResolveInfo ) async throws -> [ any PostProtocol ] {
152+
153+ static func posts( limit _: Int ? , context: Context , info _: GraphQL . GraphQLResolveInfo ) async throws -> [ any PostProtocol ] {
137154 return context. posts. values. map { $0 as any PostProtocol }
138155 }
139- static func userOrPost( id: String , context: Context , info: GraphQLResolveInfo ) async throws -> ( any UserOrPostUnion ) ? {
156+
157+ static func userOrPost( id: String , context: Context , info _: GraphQLResolveInfo ) async throws -> ( any UserOrPostUnion ) ? {
140158 return context. users [ id] ?? context. posts [ id]
141159 }
142160}
143161
144162struct Mutation : MutationProtocol {
145163 // Required implementations
146- static func upsertUser( userInfo: UserInfoInput , context: Context , info: GraphQLResolveInfo ) -> any UserProtocol {
164+ static func upsertUser( userInfo: UserInfoInput , context: Context , info _ : GraphQLResolveInfo ) -> any UserProtocol {
147165 let user = User (
148166 id: userInfo. id,
149167 name: userInfo. name,
@@ -158,7 +176,7 @@ struct Mutation: MutationProtocol {
158176
159177struct Subscription : SubscriptionProtocol {
160178 // Required implementations
161- static func watchUser( id: String , context: Context , info: GraphQLResolveInfo ) async throws -> AnyAsyncSequence < ( any UserProtocol ) ? > {
179+ static func watchUser( id: String , context: Context , info _ : GraphQLResolveInfo ) async throws -> AnyAsyncSequence < ( any UserProtocol ) ? > {
162180 return AsyncStream < ( any UserProtocol ) ? > { continuation in
163181 context. onTriggerWatch = { [ weak context] in
164182 continuation. yield ( context? . users [ id] )
0 commit comments