...
1 package transport
2
3 import (
4 "context"
5
6 "github.com/vektah/gqlparser/v2/gqlerror"
7 )
8
9
10
11 var wsSubscriptionErrorCtxKey = &wsSubscriptionErrorContextKey{"subscription-error"}
12
13 type wsSubscriptionErrorContextKey struct {
14 name string
15 }
16
17 type subscriptionError struct {
18 errs []*gqlerror.Error
19 }
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 func AddSubscriptionError(ctx context.Context, err *gqlerror.Error) {
54 subscriptionErrStruct := getSubscriptionErrorStruct(ctx)
55 subscriptionErrStruct.errs = append(subscriptionErrStruct.errs, err)
56 }
57
58 func withSubscriptionErrorContext(ctx context.Context) context.Context {
59 return context.WithValue(ctx, wsSubscriptionErrorCtxKey, &subscriptionError{})
60 }
61
62 func getSubscriptionErrorStruct(ctx context.Context) *subscriptionError {
63 v, _ := ctx.Value(wsSubscriptionErrorCtxKey).(*subscriptionError)
64 return v
65 }
66
67 func getSubscriptionError(ctx context.Context) []*gqlerror.Error {
68 return getSubscriptionErrorStruct(ctx).errs
69 }
70
View as plain text