Skip to content

Commit 198035a

Browse files
committed
uniform re-exporting of sentinel errors and values
1 parent 07c93d0 commit 198035a

8 files changed

Lines changed: 28 additions & 15 deletions

File tree

v2/pkg/engine/datasource/graphql_datasource/subscriptionclient/exports.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package client
33
import (
44
"github.com/wundergraph/graphql-go-tools/v2/pkg/engine/datasource/graphql_datasource/subscriptionclient/common"
55
"github.com/wundergraph/graphql-go-tools/v2/pkg/engine/datasource/graphql_datasource/subscriptionclient/protocol"
6+
"github.com/wundergraph/graphql-go-tools/v2/pkg/engine/datasource/graphql_datasource/subscriptionclient/transport"
67
)
78

89
// Re-export common types for single-import convenience.
@@ -18,6 +19,7 @@ type (
1819
)
1920

2021
// Re-export constants.
22+
2123
const (
2224
TransportWS = common.TransportWS
2325
TransportSSE = common.TransportSSE
@@ -31,8 +33,19 @@ const (
3133
SSEMethodGET = common.SSEMethodGET
3234
)
3335

36+
// Re-export error types.
37+
38+
type (
39+
ErrFailedUpgrade = transport.ErrFailedUpgrade
40+
ErrInvalidSubprotocol = transport.ErrInvalidSubprotocol
41+
)
42+
3443
// Re-export sentinel errors.
44+
3545
var (
36-
ErrConnectionClosed = common.ErrConnectionClosed
37-
ErrConnectionError = protocol.ErrConnectionError
46+
ErrConnectionClosed = common.ErrConnectionClosed
47+
ErrConnectionError = protocol.ErrConnectionError
48+
ErrAckTimeout = protocol.ErrAckTimeout
49+
ErrAckNotReceived = protocol.ErrAckNotReceived
50+
ErrSubscriptionExists = transport.ErrSubscriptionExists
3851
)

v2/pkg/engine/datasource/graphql_datasource/subscriptionclient/protocol/graphql_transport_ws.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (p *GraphQLTransportWS) Init(ctx context.Context, conn *websocket.Conn, pay
6868
var ackMessage incomingMessage
6969
if err := wsjson.Read(ackCtx, conn, &ackMessage); err != nil {
7070
if errors.Is(err, context.DeadlineExceeded) {
71-
return errAckTimeout
71+
return ErrAckTimeout
7272
}
7373
return fmt.Errorf("read connection_ack: %w", err)
7474
}
@@ -82,7 +82,7 @@ func (p *GraphQLTransportWS) Init(ctx context.Context, conn *websocket.Conn, pay
8282
}
8383
continue
8484
default:
85-
return fmt.Errorf("%w: got %q", errAckNotReceived, ackMessage.Type)
85+
return fmt.Errorf("%w: got %q", ErrAckNotReceived, ackMessage.Type)
8686
}
8787
}
8888
}

v2/pkg/engine/datasource/graphql_datasource/subscriptionclient/protocol/graphql_transport_ws_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func TestGraphQLTransportWS_Init(t *testing.T) {
5656
p := &GraphQLTransportWS{AckTimeout: 50 * time.Millisecond}
5757
err := p.Init(t.Context(), conn, nil)
5858

59-
require.ErrorIs(t, err, errAckTimeout)
59+
require.ErrorIs(t, err, ErrAckTimeout)
6060
})
6161

6262
t.Run("handles ping before ack", func(t *testing.T) {
@@ -106,7 +106,7 @@ func TestGraphQLTransportWS_Init(t *testing.T) {
106106
p := NewGraphQLTransportWS()
107107
err := p.Init(t.Context(), conn, nil)
108108

109-
assert.ErrorIs(t, err, errAckNotReceived)
109+
assert.ErrorIs(t, err, ErrAckNotReceived)
110110
})
111111
}
112112

v2/pkg/engine/datasource/graphql_datasource/subscriptionclient/protocol/graphql_ws.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (p *GraphQLWS) Init(ctx context.Context, conn *websocket.Conn, payload map[
5959
var ackMessage incomingMessage
6060
if err := wsjson.Read(ackCtx, conn, &ackMessage); err != nil {
6161
if errors.Is(err, context.DeadlineExceeded) {
62-
return errAckTimeout
62+
return ErrAckTimeout
6363
}
6464
return fmt.Errorf("read connection_ack: %w", err)
6565
}
@@ -78,7 +78,7 @@ func (p *GraphQLWS) Init(ctx context.Context, conn *websocket.Conn, payload map[
7878
}
7979
return fmt.Errorf("%w: %v", ErrConnectionError, errPayload)
8080
default:
81-
return fmt.Errorf("%w: got %q", errAckNotReceived, ackMessage.Type)
81+
return fmt.Errorf("%w: got %q", ErrAckNotReceived, ackMessage.Type)
8282
}
8383
}
8484
}

v2/pkg/engine/datasource/graphql_datasource/subscriptionclient/protocol/graphql_ws_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func TestGraphQLWS_Init(t *testing.T) {
5656
p := &GraphQLWS{AckTimeout: 50 * time.Millisecond}
5757
err := p.Init(t.Context(), conn, nil)
5858

59-
require.ErrorIs(t, err, errAckTimeout)
59+
require.ErrorIs(t, err, ErrAckTimeout)
6060
})
6161

6262
t.Run("handles keep-alive before ack", func(t *testing.T) {
@@ -115,7 +115,7 @@ func TestGraphQLWS_Init(t *testing.T) {
115115
p := NewGraphQLWS()
116116
err := p.Init(t.Context(), conn, nil)
117117

118-
assert.ErrorIs(t, err, errAckNotReceived)
118+
assert.ErrorIs(t, err, ErrAckNotReceived)
119119
})
120120
}
121121

v2/pkg/engine/datasource/graphql_datasource/subscriptionclient/protocol/protocol.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ type Protocol interface {
2424
}
2525

2626
var (
27-
errAckTimeout = errors.New("connection_ack timeout")
28-
errAckNotReceived = errors.New("expected connection_ack")
27+
ErrAckTimeout = errors.New("connection_ack timeout")
28+
ErrAckNotReceived = errors.New("expected connection_ack")
2929
ErrConnectionError = errors.New("connection error from server")
3030
)
3131

v2/pkg/engine/datasource/graphql_datasource/subscriptionclient/transport/ws_conn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
)
1717

1818
var (
19-
errSubscriptionExists = errors.New("subscription ID already exists")
19+
ErrSubscriptionExists = errors.New("subscription ID already exists")
2020

2121
defaultWriteTimeout = 5 * time.Second
2222
defaultReadLimit = int64(1024 * 1024) // 1MB
@@ -121,7 +121,7 @@ func (c *wsConnection) subscribe(ctx context.Context, id string, req *common.Req
121121

122122
if _, exists := c.subs[id]; exists {
123123
c.subsMu.Unlock()
124-
return nil, nil, errSubscriptionExists
124+
return nil, nil, ErrSubscriptionExists
125125
}
126126

127127
c.subs[id] = ch

v2/pkg/engine/datasource/graphql_datasource/subscriptionclient/transport/ws_conn_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestWSConnection_Subscribe(t *testing.T) {
5252

5353
_, _, err = wsc.subscribe(context.Background(), "sub-1", &common.Request{})
5454

55-
assert.ErrorIs(t, err, errSubscriptionExists)
55+
assert.ErrorIs(t, err, ErrSubscriptionExists)
5656
})
5757

5858
t.Run("returns error when connection is closed", func(t *testing.T) {

0 commit comments

Comments
 (0)