-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose transport options on the graphqlws package (#37)
- Loading branch information
Showing
2 changed files
with
26 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,29 +93,31 @@ func (o *operationMap) delete(name string) { | |
o.mtx.Unlock() | ||
} | ||
|
||
type Option func(conn *connection) | ||
|
||
// ReadLimit limits the maximum size of incoming messages | ||
func ReadLimit(limit int64) func(conn *connection) { | ||
func ReadLimit(limit int64) Option { | ||
return func(conn *connection) { | ||
conn.ws.SetReadLimit(limit) | ||
} | ||
} | ||
|
||
// WriteTimeout sets a timeout for outgoing messages | ||
func WriteTimeout(d time.Duration) func(conn *connection) { | ||
func WriteTimeout(d time.Duration) Option { | ||
return func(conn *connection) { | ||
conn.writeTimeout = d | ||
} | ||
} | ||
|
||
// Connect implements the apollographql subscriptions-transport-ws [email protected] | ||
// https://github.com/apollographql/subscriptions-transport-ws/blob/v0.9.4/PROTOCOL.md | ||
func Connect(ctx context.Context, ws wsConnection, service GraphQLService, options ...func(conn *connection)) func() { | ||
func Connect(ctx context.Context, ws wsConnection, service GraphQLService, options ...Option) func() { | ||
conn := &connection{ | ||
service: service, | ||
ws: ws, | ||
} | ||
|
||
defaultOpts := []func(conn *connection){ | ||
defaultOpts := []Option{ | ||
ReadLimit(4096), | ||
WriteTimeout(time.Second), | ||
} | ||
|
@@ -202,7 +204,7 @@ func (conn *connection) addSubscription(ctx context.Context, | |
case <-t: | ||
// setup timed out | ||
ops.delete(message.ID) | ||
ep := errPayload(errors.New("subscription connect timeout")) | ||
ep := errPayload(fmt.Errorf("server subscription connect timeout after %s", conn.writeTimeout)) | ||
send(message.ID, typeError, ep) | ||
send(message.ID, typeComplete, nil) | ||
kill <- true | ||
|