@@ -169,33 +169,27 @@ type GraphQLWebSocketMiddleware<'Root>
169
169
let sendMsg = sendMessageViaSocket serializerOptions socket
170
170
let rcv () = socket |> rcvMsgViaSocket serializerOptions
171
171
172
- let sendOutput id ( output : Output ) =
173
- match output.TryGetValue " errors" with
174
- | true , theValue ->
175
- // The specification says: "This message terminates the operation and no further messages will be sent."
176
- subscriptions
177
- |> GraphQLSubscriptionsManagement.removeSubscription ( id)
178
- sendMsg ( Error ( id, unbox theValue))
179
- | false , _ -> sendMsg ( Next ( id, output))
172
+ let sendOutput id ( output : SubscriptionExecutionResult ) =
173
+ sendMsg ( Next ( id, output))
180
174
181
175
let sendSubscriptionResponseOutput id subscriptionResult =
182
176
match subscriptionResult with
183
- | SubscriptionResult output -> output |> sendOutput id
177
+ | SubscriptionResult output -> { Data = ValueSome output; Errors = [] } |> sendOutput id
184
178
| SubscriptionErrors ( output, errors) ->
185
179
logger.LogWarning ( " Subscription errors: {subscriptionErrors}" , ( String.Join ( '\n' , errors |> Seq.map ( fun x -> $" - %s {x.Message}" ))))
186
- Task.FromResult ()
180
+ { Data = ValueNone ; Errors = errors } |> sendOutput id
187
181
188
182
let sendDeferredResponseOutput id deferredResult =
189
183
match deferredResult with
190
184
| DeferredResult ( obj, path) ->
191
185
let output = obj :?> Dictionary< string, obj>
192
- output |> sendOutput id
186
+ { Data = ValueSome output; Errors = [] } |> sendOutput id
193
187
| DeferredErrors ( obj, errors, _) ->
194
188
logger.LogWarning (
195
189
" Deferred response errors: {deferredErrors}" ,
196
190
( String.Join ( '\n' , errors |> Seq.map ( fun x -> $" - %s {x.Message}" )))
197
191
)
198
- Task.FromResult ()
192
+ { Data = ValueNone ; Errors = errors } |> sendOutput id
199
193
200
194
let sendDeferredResultDelayedBy ( ct : CancellationToken ) ( ms : int ) id deferredResult : Task = task {
201
195
do ! Task.Delay ( ms, ct)
@@ -208,16 +202,16 @@ type GraphQLWebSocketMiddleware<'Root>
208
202
( subscriptions, socket, observableOutput, serializerOptions)
209
203
|> addClientSubscription id sendSubscriptionResponseOutput
210
204
| Deferred ( data, errors, observableOutput) ->
211
- do ! data |> sendOutput id
205
+ do ! { Data = ValueSome data; Errors = [] } |> sendOutput id
212
206
if errors.IsEmpty then
213
207
( subscriptions, socket, observableOutput, serializerOptions)
214
208
|> addClientSubscription id ( sendDeferredResultDelayedBy cancellationToken 5000 )
215
209
else
216
210
()
217
- | Direct ( data, _) -> do ! data |> sendOutput id
211
+ | Direct ( data, _) -> do ! { Data = ValueSome data; Errors = [] } |> sendOutput id
218
212
| RequestError problemDetails ->
219
213
logger.LogWarning( " Request errors:\n {errors}" , problemDetails)
220
-
214
+ do ! { Data = ValueNone ; Errors = problemDetails } |> sendOutput id
221
215
}
222
216
223
217
let logMsgReceivedWithOptionalPayload optionalPayload ( msgAsStr : string ) =
0 commit comments