Skip to content

Commit 7d48df5

Browse files
Send websocketUrl on Dev session create/update
1 parent b6967c9 commit 7d48df5

File tree

12 files changed

+74
-35
lines changed

12 files changed

+74
-35
lines changed

packages/app/src/cli/api/graphql/app-dev/generated/dev-session-create.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {TypedDocumentNode as DocumentNode} from '@graphql-typed-document-node/co
77
export type DevSessionCreateMutationVariables = Types.Exact<{
88
appId: Types.Scalars['String']['input']
99
assetsUrl: Types.Scalars['String']['input']
10+
websocketUrl?: Types.InputMaybe<Types.Scalars['String']['input']>
1011
}>
1112

1213
export type DevSessionCreateMutation = {
@@ -15,7 +16,7 @@ export type DevSessionCreateMutation = {
1516
} | null
1617
}
1718

18-
export const DevSessionCreate = {
19+
export const DevSessionCreateDocument = {
1920
kind: 'Document',
2021
definitions: [
2122
{
@@ -33,6 +34,11 @@ export const DevSessionCreate = {
3334
variable: {kind: 'Variable', name: {kind: 'Name', value: 'assetsUrl'}},
3435
type: {kind: 'NonNullType', type: {kind: 'NamedType', name: {kind: 'Name', value: 'String'}}},
3536
},
37+
{
38+
kind: 'VariableDefinition',
39+
variable: {kind: 'Variable', name: {kind: 'Name', value: 'websocketUrl'}},
40+
type: {kind: 'NamedType', name: {kind: 'Name', value: 'String'}},
41+
},
3642
],
3743
selectionSet: {
3844
kind: 'SelectionSet',
@@ -51,6 +57,11 @@ export const DevSessionCreate = {
5157
name: {kind: 'Name', value: 'assetsUrl'},
5258
value: {kind: 'Variable', name: {kind: 'Name', value: 'assetsUrl'}},
5359
},
60+
{
61+
kind: 'Argument',
62+
name: {kind: 'Name', value: 'websocketUrl'},
63+
value: {kind: 'Variable', name: {kind: 'Name', value: 'websocketUrl'}},
64+
},
5465
],
5566
selectionSet: {
5667
kind: 'SelectionSet',

packages/app/src/cli/api/graphql/app-dev/generated/dev-session-delete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export type DevSessionDeleteMutationVariables = Types.Exact<{
99

1010
export type DevSessionDeleteMutation = {devSessionDelete?: {userErrors: {message: string}[]} | null}
1111

12-
export const DevSessionDelete = {
12+
export const DevSessionDeleteDocument = {
1313
kind: 'Document',
1414
definitions: [
1515
{

packages/app/src/cli/api/graphql/app-dev/generated/dev-session-update.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {TypedDocumentNode as DocumentNode} from '@graphql-typed-document-node/co
77
export type DevSessionUpdateMutationVariables = Types.Exact<{
88
appId: Types.Scalars['String']['input']
99
assetsUrl?: Types.InputMaybe<Types.Scalars['String']['input']>
10+
websocketUrl?: Types.InputMaybe<Types.Scalars['String']['input']>
1011
manifest?: Types.InputMaybe<Types.Scalars['JSON']['input']>
1112
inheritedModuleUids: Types.Scalars['String']['input'][] | Types.Scalars['String']['input']
1213
}>
@@ -17,7 +18,7 @@ export type DevSessionUpdateMutation = {
1718
} | null
1819
}
1920

20-
export const DevSessionUpdate = {
21+
export const DevSessionUpdateDocument = {
2122
kind: 'Document',
2223
definitions: [
2324
{
@@ -35,6 +36,11 @@ export const DevSessionUpdate = {
3536
variable: {kind: 'Variable', name: {kind: 'Name', value: 'assetsUrl'}},
3637
type: {kind: 'NamedType', name: {kind: 'Name', value: 'String'}},
3738
},
39+
{
40+
kind: 'VariableDefinition',
41+
variable: {kind: 'Variable', name: {kind: 'Name', value: 'websocketUrl'}},
42+
type: {kind: 'NamedType', name: {kind: 'Name', value: 'String'}},
43+
},
3844
{
3945
kind: 'VariableDefinition',
4046
variable: {kind: 'Variable', name: {kind: 'Name', value: 'manifest'}},
@@ -69,6 +75,11 @@ export const DevSessionUpdate = {
6975
name: {kind: 'Name', value: 'assetsUrl'},
7076
value: {kind: 'Variable', name: {kind: 'Name', value: 'assetsUrl'}},
7177
},
78+
{
79+
kind: 'Argument',
80+
name: {kind: 'Name', value: 'websocketUrl'},
81+
value: {kind: 'Variable', name: {kind: 'Name', value: 'websocketUrl'}},
82+
},
7283
{
7384
kind: 'Argument',
7485
name: {kind: 'Name', value: 'manifest'},

packages/app/src/cli/api/graphql/app-dev/queries/dev-session-create.graphql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
mutation DevSessionCreate($appId: String!, $assetsUrl: String!) {
2-
devSessionCreate(appId: $appId, assetsUrl: $assetsUrl) {
1+
mutation DevSessionCreate($appId: String!, $assetsUrl: String!, $websocketUrl: String) {
2+
devSessionCreate(appId: $appId, assetsUrl: $assetsUrl, websocketUrl: $websocketUrl) {
33
userErrors {
44
message
55
on

packages/app/src/cli/api/graphql/app-dev/queries/dev-session-update.graphql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
mutation DevSessionUpdate($appId: String!, $assetsUrl: String, $manifest: JSON, $inheritedModuleUids: [String!]!) {
2-
devSessionUpdate(appId: $appId, assetsUrl: $assetsUrl, manifest: $manifest, inheritedModuleUids: $inheritedModuleUids) {
1+
mutation DevSessionUpdate($appId: String!, $assetsUrl: String, $websocketUrl: String, $manifest: JSON, $inheritedModuleUids: [String!]!) {
2+
devSessionUpdate(appId: $appId, assetsUrl: $assetsUrl, websocketUrl: $websocketUrl, manifest: $manifest, inheritedModuleUids: $inheritedModuleUids) {
33
userErrors {
44
message
55
on

packages/app/src/cli/api/graphql/business-platform-organizations/generated/types.d.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
/* eslint-disable @typescript-eslint/consistent-type-definitions, @typescript-eslint/naming-convention, @typescript-eslint/no-explicit-any */
2-
import {JsonMapType} from '@shopify/cli-kit/node/toml'
3-
42
export type Maybe<T> = T | null
53
export type InputMaybe<T> = Maybe<T>
64
export type Exact<T extends {[key: string]: unknown}> = {[K in keyof T]: T[K]}
@@ -42,8 +40,6 @@ export type Scalars = {
4240
ISO8601Date: {input: any; output: any}
4341
/** An ISO 8601-encoded datetime */
4442
ISO8601DateTime: {input: any; output: any}
45-
/** Represents untyped JSON */
46-
JSON: {input: JsonMapType | string; output: JsonMapType}
4743
/** The ID for a LegalEntity. */
4844
LegalEntityID: {input: any; output: any}
4945
/** The ID for a OrganizationDomain. */

packages/app/src/cli/services/dev/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export async function devUIExtensions(options: ExtensionDevOptions): Promise<voi
183183
})
184184
}
185185

186-
function getWebSocketUrl(url: ExtensionDevOptions['url']) {
186+
export function getWebSocketUrl(url: string) {
187187
const websocketURL = new URL('/extensions', url)
188188
websocketURL.protocol = 'wss:'
189189

packages/app/src/cli/services/dev/extension/server/middlewares.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {getExtensionPointRedirectUrl, getExtensionUrl, getRedirectUrl, sendError
22
import {GetExtensionsMiddlewareOptions} from './models.js'
33
import {getUIExtensionPayload} from '../payload.js'
44
import {getHTML} from '../templates.js'
5+
import {getWebSocketUrl} from '../../extension.js'
56
import {fileExists, isDirectory, readFile, findPathUp} from '@shopify/cli-kit/node/fs'
67
import {IncomingMessage, ServerResponse, sendRedirect, send} from 'h3'
78
import {joinPath, extname, moduleDirectory} from '@shopify/cli-kit/node/path'
@@ -199,7 +200,7 @@ export function getExtensionPayloadMiddleware({devOptions, getExtensions}: GetEx
199200
url: new URL('/extensions', devOptions.url).toString(),
200201
},
201202
socket: {
202-
url: getWebsocketUrl(devOptions),
203+
url: getWebSocketUrl(devOptions.url),
203204
},
204205
devConsole: {
205206
url: new URL('/extensions/dev-console', devOptions.url).toString(),
@@ -245,10 +246,3 @@ export function getExtensionPointMiddleware({devOptions, getExtensions}: GetExte
245246
await sendRedirect(response.event, url, 307)
246247
}
247248
}
248-
249-
function getWebsocketUrl(devOptions: GetExtensionsMiddlewareOptions['devOptions']) {
250-
const socket = new URL('/extensions', devOptions.url)
251-
socket.protocol = 'wss:'
252-
253-
return socket.toString()
254-
}

packages/app/src/cli/services/dev/processes/dev-session/dev-session-process.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,12 @@ describe('pushUpdatesForDevSession', () => {
9090
abortController = new AbortController()
9191
devSessionStatusManager = new DevSessionStatusManager()
9292
options = {
93+
app: {} as AppLinkedInterface,
94+
apiKey: 'test-api-key',
9395
developerPlatformClient,
9496
appWatcher,
9597
storeFqdn: 'test.myshopify.com',
98+
url: 'https://test.dev',
9699
appId: 'app123',
97100
organizationId: 'org123',
98101
appPreviewURL: 'https://test.preview.url',
@@ -404,6 +407,7 @@ describe('pushUpdatesForDevSession', () => {
404407
appId: 'app123',
405408
// Assets URL is empty because the affected extension has no assets
406409
assetsUrl: undefined,
410+
websocketUrl: 'wss://test.dev/extensions',
407411
manifest: {
408412
name: 'App',
409413
handle: '',
@@ -449,6 +453,7 @@ describe('pushUpdatesForDevSession', () => {
449453
shopFqdn: 'test.myshopify.com',
450454
appId: 'app123',
451455
assetsUrl: 'https://gcs.url',
456+
websocketUrl: 'wss://test.dev/extensions',
452457
manifest: expect.any(Object),
453458
inheritedModuleUids: [],
454459
})
@@ -469,8 +474,7 @@ describe('pushUpdatesForDevSession', () => {
469474
shopFqdn: 'test.myshopify.com',
470475
appId: 'app123',
471476
assetsUrl: 'https://gcs.url',
472-
manifest: expect.any(Object),
473-
inheritedModuleUids: [],
477+
websocketUrl: 'wss://test.dev/extensions',
474478
})
475479
})
476480

packages/app/src/cli/services/dev/processes/dev-session/dev-session.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {AppEvent, AppEventWatcher, ExtensionEvent} from '../../app-events/app-ev
55
import {compressBundle, getUploadURL, uploadToGCS, writeManifestToBundle} from '../../../bundle.js'
66
import {DevSessionCreateOptions, DevSessionUpdateOptions} from '../../../../utilities/developer-platform-client.js'
77
import {AppManifest} from '../../../../models/app/app.js'
8+
import {getWebSocketUrl} from '../../extension.js'
89
import {endHRTimeInMs, startHRTime} from '@shopify/cli-kit/node/hrtime'
910
import {ClientError} from 'graphql-request'
1011
import {JsonMapType} from '@shopify/cli-kit/node/toml'
@@ -276,16 +277,24 @@ export class DevSession {
276277
const {manifest, inheritedModuleUids, assets} = await this.createManifest(appEvent)
277278
const signedURL = await this.uploadAssetsIfNeeded(assets, !this.statusManager.status.isReady)
278279

279-
const payload = {
280-
shopFqdn: this.options.storeFqdn,
281-
appId: this.options.appId,
282-
assetsUrl: signedURL,
283-
manifest,
284-
inheritedModuleUids,
285-
}
280+
const websocketUrl = getWebSocketUrl(this.options.url)
286281
if (this.statusManager.status.isReady) {
282+
const payload: DevSessionUpdateOptions = {
283+
shopFqdn: this.options.storeFqdn,
284+
appId: this.options.appId,
285+
assetsUrl: signedURL,
286+
manifest,
287+
inheritedModuleUids,
288+
websocketUrl,
289+
}
287290
return this.devSessionUpdateWithRetry(payload)
288291
} else {
292+
const payload: DevSessionCreateOptions = {
293+
shopFqdn: this.options.storeFqdn,
294+
appId: this.options.appId,
295+
assetsUrl: signedURL,
296+
websocketUrl,
297+
}
289298
return this.devSessionCreateWithRetry(payload)
290299
}
291300
// eslint-disable-next-line @typescript-eslint/no-explicit-any

0 commit comments

Comments
 (0)