Skip to content

Commit

Permalink
migrate nhooyr.io/websocket to github.com/coder/websocket (#153)
Browse files Browse the repository at this point in the history
* migrate nhooyr.io/websocket to github.com/coder/websocket
  • Loading branch information
cpouldev authored Sep 23, 2024
1 parent 1d68c4a commit d4c8fea
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

**Preface:** This is a fork of `https://github.com/shurcooL/graphql` with extended features (subscription client, named operation)

The subscription client follows Apollo client specification https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md, using WebSocket protocol with https://github.com/nhooyr/websocket, a minimal and idiomatic WebSocket library for Go.
The subscription client follows Apollo client specification https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md, using WebSocket protocol with https://github.com/coder/websocket, a minimal and idiomatic WebSocket library for Go.

Package `graphql` provides a GraphQL client implementation.

Expand Down Expand Up @@ -672,7 +672,7 @@ client.WithWebSocketOptions(WebsocketOptions{
#### Custom WebSocket client
By default, the subscription client uses [nhooyr WebSocket client](https://github.com/nhooyr/websocket). If you need to customize the client or prefer using [Gorilla WebSocket](https://github.com/gorilla/websocket), let's follow the WebSocket interface and replace the constructor with `WithWebSocket` method:
By default, the subscription client uses [coder WebSocket client](https://github.com/coder/websocket). If you need to customize the client or prefer using [Gorilla WebSocket](https://github.com/gorilla/websocket), let's follow the WebSocket interface and replace the constructor with `WithWebSocket` method:
```go
// WebsocketHandler abstracts WebSocket connection functions
Expand Down Expand Up @@ -706,7 +706,7 @@ func newWebsocketConn(sc *SubscriptionClient) (WebsocketConn, error) {
return nil, err
}

// The default WebsocketHandler implementation using nhooyr's
// The default WebsocketHandler implementation using coder's
return &WebsocketHandler{
ctx: sc.GetContext(),
Conn: c,
Expand Down Expand Up @@ -992,7 +992,7 @@ Because the GraphQL query string is generated in runtime using reflection, it is
- https://github.com/shurcooL/graphql
- https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md
- https://github.com/nhooyr/websocket
- https://github.com/coder/websocket
## License
Expand Down
2 changes: 1 addition & 1 deletion example/subscription/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ require (
)

require (
github.com/coder/websocket v1.8.12 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.4.1 // indirect
nhooyr.io/websocket v1.8.10 // indirect
)

replace github.com/hasura/go-graphql-client => ../../
4 changes: 2 additions & 2 deletions example/subscription/go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/coder/websocket v1.8.12 h1:5bUXkEPPIbewrnkU8LTCLVaxi4N4J8ahufH2vlo4NAo=
github.com/coder/websocket v1.8.12/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
Expand Down Expand Up @@ -26,5 +28,3 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
nhooyr.io/websocket v1.8.10 h1:mv4p+MnGrLDcPlBoWsvPP7XCzTYMXP9F9eIGoKbgx7Q=
nhooyr.io/websocket v1.8.10/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c=
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/hasura/go-graphql-client
go 1.20

require (
github.com/coder/websocket v1.8.12
github.com/google/uuid v1.6.0
nhooyr.io/websocket v1.8.11
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github.com/coder/websocket v1.8.12 h1:5bUXkEPPIbewrnkU8LTCLVaxi4N4J8ahufH2vlo4NAo=
github.com/coder/websocket v1.8.12/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
nhooyr.io/websocket v1.8.11 h1:f/qXNc2/3DpoSZkHt1DQu6rj4zGC8JmkkLkWss0MgN0=
nhooyr.io/websocket v1.8.11/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c=
10 changes: 5 additions & 5 deletions subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"sync/atomic"
"time"

"github.com/coder/websocket"
"github.com/coder/websocket/wsjson"
"github.com/google/uuid"
"nhooyr.io/websocket"
"nhooyr.io/websocket/wsjson"
)

// SubscriptionProtocolType represents the protocol specification enum of the subscription
Expand Down Expand Up @@ -419,7 +419,7 @@ func (sc *SubscriptionClient) GetSubscription(id string) *Subscription {
}

// WithWebSocket replaces customized websocket client constructor
// In default, subscription client uses https://github.com/nhooyr/websocket
// In default, subscription client uses https://github.com/coder/websocket
func (sc *SubscriptionClient) WithWebSocket(fn func(sc *SubscriptionClient) (WebsocketConn, error)) *SubscriptionClient {
sc.createConn = fn
return sc
Expand Down Expand Up @@ -1014,7 +1014,7 @@ func parseInt32Ranges(codes []string) ([][]int32, error) {
return statusCodes, nil
}

// default websocket handler implementation using https://github.com/nhooyr/websocket
// default websocket handler implementation using https://github.com/coder/websocket
type WebsocketHandler struct {
ctx context.Context
timeout time.Duration
Expand Down Expand Up @@ -1069,7 +1069,7 @@ func (wh *WebsocketHandler) GetCloseStatus(err error) int32 {
}

// the default constructor function to create a websocket client
// which uses https://github.com/nhooyr/websocket library
// which uses https://github.com/coder/websocket library
func newWebsocketConn(sc *SubscriptionClient) (WebsocketConn, error) {

options := &websocket.DialOptions{
Expand Down
2 changes: 1 addition & 1 deletion subscription_graphql_ws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"testing"
"time"

"nhooyr.io/websocket"
"github.com/coder/websocket"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion subscriptions_transport_ws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"
"time"

"nhooyr.io/websocket"
"github.com/coder/websocket"
)

func TestSubscription_WithRetryStatusCodes(t *testing.T) {
Expand Down

0 comments on commit d4c8fea

Please sign in to comment.