@@ -8,42 +8,40 @@ import GraphQLTransportWS
88class GraphqlTransportWSTests : XCTestCase {
99 var clientMessenger : TestMessenger !
1010 var serverMessenger : TestMessenger !
11- var server : Server < TokenInitPayload , AsyncThrowingStream < GraphQLResult , Error > > !
12- var context : TestContext !
1311 var subscribeReady : Bool ! = false
12+
13+ let context = TestContext ( )
14+ let api = TestAPI ( )
1415
1516 override func setUp( ) {
1617 // Point the client and server at each other
1718 clientMessenger = TestMessenger ( )
1819 serverMessenger = TestMessenger ( )
1920 clientMessenger. other = serverMessenger
2021 serverMessenger. other = clientMessenger
22+ }
2123
22- let api = TestAPI ( )
23- let context = TestContext ( )
24-
25- server = . init(
24+ /// Tests that trying to run methods before `connection_init` is not allowed
25+ func testInitialize( ) async throws {
26+ _ = Server < TokenInitPayload , Void , AsyncThrowingStream < GraphQLResult , Error > > (
2627 messenger: serverMessenger,
27- onExecute: { graphQLRequest in
28- try await api. execute (
28+ onInit: { _ in } ,
29+ onExecute: { graphQLRequest, _ in
30+ try await self . api. execute (
2931 request: graphQLRequest. query,
30- context: context
32+ context: self . context
3133 )
3234 } ,
33- onSubscribe: { graphQLRequest in
34- let subscription = try await api. subscribe (
35+ onSubscribe: { graphQLRequest, _ in
36+ let subscription = try await self . api. subscribe (
3537 request: graphQLRequest. query,
36- context: context
38+ context: self . context
3739 ) . get ( )
3840 self . subscribeReady = true
3941 return subscription
4042 }
4143 )
42- self . context = context
43- }
44-
45- /// Tests that trying to run methods before `connection_init` is not allowed
46- func testInitialize( ) async throws {
44+
4745 let client = Client < TokenInitPayload > ( messenger: clientMessenger)
4846 let messageStream = AsyncThrowingStream < String , any Error > { continuation in
4947 client. onMessage { message, _ in
@@ -78,9 +76,26 @@ class GraphqlTransportWSTests: XCTestCase {
7876
7977 /// Tests that throwing in the authorization callback forces an unauthorized error
8078 func testAuthWithThrow( ) async throws {
81- server. auth { _ in
82- throw TestError . couldBeAnything
83- }
79+ _ = Server < TokenInitPayload , Void , AsyncThrowingStream < GraphQLResult , Error > > (
80+ messenger: serverMessenger,
81+ onInit: { _ in
82+ throw TestError . couldBeAnything
83+ } ,
84+ onExecute: { graphQLRequest, _ in
85+ try await self . api. execute (
86+ request: graphQLRequest. query,
87+ context: self . context
88+ )
89+ } ,
90+ onSubscribe: { graphQLRequest, _ in
91+ let subscription = try await self . api. subscribe (
92+ request: graphQLRequest. query,
93+ context: self . context
94+ ) . get ( )
95+ self . subscribeReady = true
96+ return subscription
97+ }
98+ )
8499
85100 let client = Client < TokenInitPayload > ( messenger: clientMessenger)
86101 let messageStream = AsyncThrowingStream < String , any Error > { continuation in
@@ -111,6 +126,25 @@ class GraphqlTransportWSTests: XCTestCase {
111126
112127 /// Tests a single-op conversation
113128 func testSingleOp( ) async throws {
129+ _ = Server < TokenInitPayload , Void , AsyncThrowingStream < GraphQLResult , Error > > (
130+ messenger: serverMessenger,
131+ onInit: { _ in } ,
132+ onExecute: { graphQLRequest, _ in
133+ try await self . api. execute (
134+ request: graphQLRequest. query,
135+ context: self . context
136+ )
137+ } ,
138+ onSubscribe: { graphQLRequest, _ in
139+ let subscription = try await self . api. subscribe (
140+ request: graphQLRequest. query,
141+ context: self . context
142+ ) . get ( )
143+ self . subscribeReady = true
144+ return subscription
145+ }
146+ )
147+
114148 let id = UUID ( ) . description
115149
116150 let client = Client < TokenInitPayload > ( messenger: clientMessenger)
@@ -156,6 +190,25 @@ class GraphqlTransportWSTests: XCTestCase {
156190
157191 /// Tests a streaming conversation
158192 func testStreaming( ) async throws {
193+ _ = Server < TokenInitPayload , Void , AsyncThrowingStream < GraphQLResult , Error > > (
194+ messenger: serverMessenger,
195+ onInit: { _ in } ,
196+ onExecute: { graphQLRequest, _ in
197+ try await self . api. execute (
198+ request: graphQLRequest. query,
199+ context: self . context
200+ )
201+ } ,
202+ onSubscribe: { graphQLRequest, _ in
203+ let subscription = try await self . api. subscribe (
204+ request: graphQLRequest. query,
205+ context: self . context
206+ ) . get ( )
207+ self . subscribeReady = true
208+ return subscription
209+ }
210+ )
211+
159212 let id = UUID ( ) . description
160213
161214 var dataIndex = 1
0 commit comments