@@ -2,8 +2,8 @@ import Foundation
22import GraphQL
33import GraphQLGeneratorRuntime
44
5- // Must be created by user and named `Context `.
6- public class Context : @unchecked Sendable {
5+ // Must be created by user and named `GraphQLContext `.
6+ public class GraphQLContext : @unchecked Sendable {
77 // User can choose structure
88 var users : [ String : User ]
99 var posts : [ String : Post ]
@@ -80,23 +80,23 @@ struct User: UserProtocol {
8080 let role : Role ?
8181
8282 // Required implementations
83- func id( context _: Context , info _: GraphQL . GraphQLResolveInfo ) async throws -> String {
83+ func id( context _: GraphQLContext , info _: GraphQL . GraphQLResolveInfo ) async throws -> String {
8484 return id
8585 }
8686
87- func name( context _: Context , info _: GraphQL . GraphQLResolveInfo ) async throws -> String {
87+ func name( context _: GraphQLContext , info _: GraphQL . GraphQLResolveInfo ) async throws -> String {
8888 return name
8989 }
9090
91- func email( context _: Context , info _: GraphQL . GraphQLResolveInfo ) async throws -> EmailAddress {
91+ func email( context _: GraphQLContext , info _: GraphQL . GraphQLResolveInfo ) async throws -> EmailAddress {
9292 return EmailAddress ( email: email)
9393 }
9494
95- func age( context _: Context , info _: GraphQL . GraphQLResolveInfo ) async throws -> Int ? {
95+ func age( context _: GraphQLContext , info _: GraphQL . GraphQLResolveInfo ) async throws -> Int ? {
9696 return age
9797 }
9898
99- func role( context _: Context , info _: GraphQL . GraphQLResolveInfo ) async throws -> Role ? {
99+ func role( context _: GraphQLContext , info _: GraphQL . GraphQLResolveInfo ) async throws -> Role ? {
100100 return role
101101 }
102102}
@@ -106,7 +106,7 @@ struct Contact: ContactProtocol {
106106 let email : String
107107
108108 // Required implementations
109- func email( context _: Context , info _: GraphQL . GraphQLResolveInfo ) async throws -> EmailAddress {
109+ func email( context _: GraphQLContext , info _: GraphQL . GraphQLResolveInfo ) async throws -> EmailAddress {
110110 return EmailAddress ( email: email)
111111 }
112112}
@@ -119,49 +119,49 @@ struct Post: PostProtocol {
119119 let authorId : String
120120
121121 // Required implementations
122- func id( context _: Context , info _: GraphQL . GraphQLResolveInfo ) async throws -> String {
122+ func id( context _: GraphQLContext , info _: GraphQL . GraphQLResolveInfo ) async throws -> String {
123123 return id
124124 }
125125
126- func title( context _: Context , info _: GraphQL . GraphQLResolveInfo ) async throws -> String {
126+ func title( context _: GraphQLContext , info _: GraphQL . GraphQLResolveInfo ) async throws -> String {
127127 return title
128128 }
129129
130- func content( context _: Context , info _: GraphQL . GraphQLResolveInfo ) async throws -> String {
130+ func content( context _: GraphQLContext , info _: GraphQL . GraphQLResolveInfo ) async throws -> String {
131131 return content
132132 }
133133
134- func author( context: Context , info _: GraphQL . GraphQLResolveInfo ) async throws -> any UserProtocol {
134+ func author( context: GraphQLContext , info _: GraphQL . GraphQLResolveInfo ) async throws -> any UserProtocol {
135135 return context. users [ authorId] !
136136 }
137137}
138138
139139struct Query : QueryProtocol {
140140 // Required implementations
141- static func user( id: String , context: Context , info _: GraphQL . GraphQLResolveInfo ) async throws -> ( any UserProtocol ) ? {
141+ static func user( id: String , context: GraphQLContext , info _: GraphQL . GraphQLResolveInfo ) async throws -> ( any UserProtocol ) ? {
142142 return context. users [ id]
143143 }
144144
145- static func users( context: Context , info _: GraphQL . GraphQLResolveInfo ) async throws -> [ any UserProtocol ] {
145+ static func users( context: GraphQLContext , info _: GraphQL . GraphQLResolveInfo ) async throws -> [ any UserProtocol ] {
146146 return context. users. values. map { $0 as any UserProtocol }
147147 }
148148
149- static func post( id: String , context: Context , info _: GraphQL . GraphQLResolveInfo ) async throws -> ( any PostProtocol ) ? {
149+ static func post( id: String , context: GraphQLContext , info _: GraphQL . GraphQLResolveInfo ) async throws -> ( any PostProtocol ) ? {
150150 return context. posts [ id]
151151 }
152152
153- static func posts( limit _: Int ? , context: Context , info _: GraphQL . GraphQLResolveInfo ) async throws -> [ any PostProtocol ] {
153+ static func posts( limit _: Int ? , context: GraphQLContext , info _: GraphQL . GraphQLResolveInfo ) async throws -> [ any PostProtocol ] {
154154 return context. posts. values. map { $0 as any PostProtocol }
155155 }
156156
157- static func userOrPost( id: String , context: Context , info _: GraphQLResolveInfo ) async throws -> ( any UserOrPostUnion ) ? {
157+ static func userOrPost( id: String , context: GraphQLContext , info _: GraphQLResolveInfo ) async throws -> ( any UserOrPostUnion ) ? {
158158 return context. users [ id] ?? context. posts [ id]
159159 }
160160}
161161
162162struct Mutation : MutationProtocol {
163163 // Required implementations
164- static func upsertUser( userInfo: UserInfoInput , context: Context , info _: GraphQLResolveInfo ) -> any UserProtocol {
164+ static func upsertUser( userInfo: UserInfoInput , context: GraphQLContext , info _: GraphQLResolveInfo ) -> any UserProtocol {
165165 let user = User (
166166 id: userInfo. id,
167167 name: userInfo. name,
@@ -176,7 +176,7 @@ struct Mutation: MutationProtocol {
176176
177177struct Subscription : SubscriptionProtocol {
178178 // Required implementations
179- static func watchUser( id: String , context: Context , info _: GraphQLResolveInfo ) async throws -> AnyAsyncSequence < ( any UserProtocol ) ? > {
179+ static func watchUser( id: String , context: GraphQLContext , info _: GraphQLResolveInfo ) async throws -> AnyAsyncSequence < ( any UserProtocol ) ? > {
180180 return AsyncStream < ( any UserProtocol ) ? > { continuation in
181181 context. onTriggerWatch = { [ weak context] in
182182 continuation. yield ( context? . users [ id] )
0 commit comments