Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/api-client-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@urql/core": "^4.0.10",
"cross-fetch": "^4.0.0",
"graphql": "^16.8.1",
"graphql-ws": "^5.13.1",
"graphql-ws": "^6.0.6",
"isomorphic-ws": "^5.0.0",
"klona": "^2.0.6",
"tiny-graphql-query-compiler": "^0.2.2",
Expand Down
19 changes: 11 additions & 8 deletions packages/api-client-core/src/GadgetConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,15 @@ export class GadgetConnection {
let transaction;
try {
// The server will error if it receives any operations before the auth dance has been completed, so we block on that happening before sending our first operation. It's important that this happens synchronously after instantiating the client so we don't miss any messages

const shouldRetry = (errorOrCloseEvent: unknown) => {
// any interruption of the transaction is fatal to the transaction
console.warn("Transport error encountered during transaction processing", errorOrCloseEvent);
return false;
};

subscriptionClient = await this.waitForOpenedConnection({
isFatalConnectionProblem(errorOrCloseEvent) {
// any interruption of the transaction is fatal to the transaction
console.warn("Transport error encountered during transaction processing", errorOrCloseEvent);
return true;
},
shouldRetry,
connectionAckWaitTimeout: DEFAULT_CONN_ACK_TIMEOUT,
...options,
lazy: false,
Expand Down Expand Up @@ -496,7 +499,7 @@ export class GadgetConnection {
// we catch this outside in the runner function
},
on: {
connected: (socket, payload) => {
connected: (socket, payload, wasRetry) => {
// If we're using session token authorization, we don't use request headers to exchange the session token, we use graphql-ws' ConnectionAck payload to persist the token. When the subscription client first starts, the server will send us session token identifying this client, and we persist it to the session token store
if (this.authenticationMode == AuthenticationMode.BrowserSession && payload?.sessionToken) {
const browserSession = this.options.authenticationMode?.browserSession;
Expand All @@ -505,8 +508,8 @@ export class GadgetConnection {
this.sessionTokenStore!.setItem(this.sessionStorageKey, payload.sessionToken as string);
}
}
this.subscriptionClientOptions?.on?.connected?.(socket, payload);
overrides?.on?.connected?.(socket, payload);
this.subscriptionClientOptions?.on?.connected?.(socket, payload, wasRetry);
overrides?.on?.connected?.(socket, payload, wasRetry);
activeSocket = socket as globalThis.WebSocket;
},
ping: (received) => {
Expand Down
6 changes: 6 additions & 0 deletions packages/react/.changeset/clean-spiders-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@gadgetinc/api-client-core": patch
"@gadgetinc/react": patch
---

Upgrade to latest graphql-ws websocket transport
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"date-fns-tz": "^2.0.0",
"execa": "^5.1.1",
"graphql": "^16.8.1",
"graphql-ws": "^5.13.1",
"graphql-ws": "^6.0.6",
"libnpmpack": "^7.0.4",
"lodash-es": "^4.17.21",
"lucide-react": "^0.471.0",
Expand Down
36 changes: 25 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.