Skip to content

Commit f481254

Browse files
authored
Merge pull request Shopify#5353 from Shopify/app-versions-list-pagination
App versions list pagination
2 parents 160315c + 8a6d3d6 commit f481254

File tree

4 files changed

+183
-51
lines changed

4 files changed

+183
-51
lines changed

packages/app/src/cli/api/graphql/app-management/generated/app-versions.ts

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@ export type AppVersionsQueryVariables = Types.Exact<{
88
}>
99

1010
export type AppVersionsQuery = {
11-
app: {id: string; activeRelease: {id: string; version: {id: string}}}
12-
versions: {
11+
app: {
1312
id: string
14-
createdAt: string
15-
createdBy?: string | null
16-
metadata: {message?: string | null; versionTag?: string | null}
17-
}[]
13+
versionsCount: number
14+
activeRelease: {id: string; version: {id: string}}
15+
versions?: {
16+
edges: {
17+
node: {
18+
id: string
19+
createdAt: string
20+
createdBy?: string | null
21+
metadata: {message?: string | null; versionTag?: string | null}
22+
}
23+
}[]
24+
} | null
25+
}
1826
}
1927

2028
export const AppVersions = {
@@ -70,38 +78,55 @@ export const AppVersions = {
7078
],
7179
},
7280
},
73-
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
74-
],
75-
},
76-
},
77-
{
78-
kind: 'Field',
79-
name: {kind: 'Name', value: 'versions'},
80-
arguments: [
81-
{
82-
kind: 'Argument',
83-
name: {kind: 'Name', value: 'appId'},
84-
value: {kind: 'Variable', name: {kind: 'Name', value: 'appId'}},
85-
},
86-
],
87-
selectionSet: {
88-
kind: 'SelectionSet',
89-
selections: [
90-
{kind: 'Field', name: {kind: 'Name', value: 'id'}},
91-
{kind: 'Field', name: {kind: 'Name', value: 'createdAt'}},
92-
{kind: 'Field', name: {kind: 'Name', value: 'createdBy'}},
9381
{
9482
kind: 'Field',
95-
name: {kind: 'Name', value: 'metadata'},
83+
name: {kind: 'Name', value: 'versions'},
84+
arguments: [
85+
{kind: 'Argument', name: {kind: 'Name', value: 'first'}, value: {kind: 'IntValue', value: '20'}},
86+
],
9687
selectionSet: {
9788
kind: 'SelectionSet',
9889
selections: [
99-
{kind: 'Field', name: {kind: 'Name', value: 'message'}},
100-
{kind: 'Field', name: {kind: 'Name', value: 'versionTag'}},
90+
{
91+
kind: 'Field',
92+
name: {kind: 'Name', value: 'edges'},
93+
selectionSet: {
94+
kind: 'SelectionSet',
95+
selections: [
96+
{
97+
kind: 'Field',
98+
name: {kind: 'Name', value: 'node'},
99+
selectionSet: {
100+
kind: 'SelectionSet',
101+
selections: [
102+
{kind: 'Field', name: {kind: 'Name', value: 'id'}},
103+
{kind: 'Field', name: {kind: 'Name', value: 'createdAt'}},
104+
{kind: 'Field', name: {kind: 'Name', value: 'createdBy'}},
105+
{
106+
kind: 'Field',
107+
name: {kind: 'Name', value: 'metadata'},
108+
selectionSet: {
109+
kind: 'SelectionSet',
110+
selections: [
111+
{kind: 'Field', name: {kind: 'Name', value: 'message'}},
112+
{kind: 'Field', name: {kind: 'Name', value: 'versionTag'}},
113+
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
114+
],
115+
},
116+
},
117+
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
118+
],
119+
},
120+
},
121+
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
122+
],
123+
},
124+
},
101125
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
102126
],
103127
},
104128
},
129+
{kind: 'Field', name: {kind: 'Name', value: 'versionsCount'}},
105130
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
106131
],
107132
},

packages/app/src/cli/api/graphql/app-management/queries/app-versions.graphql

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ query AppVersions($appId: ID!) {
77
id
88
}
99
}
10-
}
11-
versions(appId: $appId) {
12-
id
13-
createdAt
14-
createdBy
15-
metadata {
16-
message
17-
versionTag
10+
versions(first: 20) {
11+
edges {
12+
node {
13+
id
14+
createdAt
15+
createdBy
16+
metadata {
17+
message
18+
versionTag
19+
}
20+
}
21+
}
1822
}
23+
versionsCount
1924
}
2025
}

packages/app/src/cli/utilities/developer-platform-client/app-management-client.test.ts

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import {AvailableTopicsQuery} from '../../api/graphql/webhooks/generated/availab
2020
import {CliTesting, CliTestingMutation} from '../../api/graphql/webhooks/generated/cli-testing.js'
2121
import {SendSampleWebhookVariables} from '../../services/webhook/request-sample.js'
2222
import {CreateApp} from '../../api/graphql/app-management/generated/create-app.js'
23+
import {AppVersions, AppVersionsQuery} from '../../api/graphql/app-management/generated/app-versions.js'
24+
import {AppVersionsQuerySchema} from '../../api/graphql/get_versions_list.js'
2325
import {BrandingSpecIdentifier} from '../../models/extensions/specifications/app_config_branding.js'
2426
import {describe, expect, test, vi} from 'vitest'
2527
import {CLI_KIT_VERSION} from '@shopify/cli-kit/common/version'
@@ -753,4 +755,102 @@ describe('deploy', () => {
753755
expect(result.appDeploy.userErrors).toHaveLength(1)
754756
expect(result.appDeploy.userErrors[0]?.message).toBe('Invalid version')
755757
})
758+
759+
test('queries for versions list', async () => {
760+
// Given
761+
const appId = 'gid://shopify/App/123'
762+
const client = new AppManagementClient()
763+
client.token = () => Promise.resolve('token')
764+
const mockResponse: AppVersionsQuery = {
765+
app: {
766+
id: appId,
767+
versionsCount: 77,
768+
activeRelease: {
769+
id: 'gid://shopify/Release/1',
770+
version: {
771+
id: 'gid://shopify/Version/1',
772+
},
773+
},
774+
versions: {
775+
edges: [
776+
{
777+
node: {
778+
id: 'gid://shopify/Version/1',
779+
metadata: {
780+
versionTag: '1.0.0',
781+
message: 'Test deploy',
782+
},
783+
createdAt: '2021-01-01T00:00:00Z',
784+
createdBy: '[email protected]',
785+
},
786+
},
787+
{
788+
node: {
789+
id: 'gid://shopify/Version/2',
790+
metadata: {
791+
versionTag: '1.0.1',
792+
message: 'Test deploy 2',
793+
},
794+
createdAt: '2021-01-02T00:00:00Z',
795+
createdBy: '[email protected]',
796+
},
797+
},
798+
],
799+
},
800+
},
801+
}
802+
vi.mocked(appManagementRequestDoc).mockResolvedValueOnce(mockResponse)
803+
804+
// When
805+
const result: AppVersionsQuerySchema = await client.appVersions({
806+
apiKey: 'api-key',
807+
organizationId: 'gid://shopify/Organization/123',
808+
id: appId,
809+
title: 'Test App',
810+
})
811+
812+
// Then
813+
expect(appManagementRequestDoc).toHaveBeenCalledWith(
814+
'gid://shopify/Organization/123',
815+
AppVersions,
816+
'token',
817+
expect.objectContaining({appId}),
818+
)
819+
expect(result).toEqual({
820+
app: {
821+
id: appId,
822+
organizationId: 'gid://shopify/Organization/123',
823+
title: 'Test App',
824+
appVersions: {
825+
nodes: [
826+
{
827+
createdAt: '2021-01-01T00:00:00Z',
828+
createdBy: {
829+
displayName: '[email protected]',
830+
},
831+
versionTag: '1.0.0',
832+
// Version 1 is active because it's the same as the active release
833+
status: 'active',
834+
versionId: 'gid://shopify/Version/1',
835+
message: 'Test deploy',
836+
},
837+
{
838+
createdAt: '2021-01-02T00:00:00Z',
839+
createdBy: {
840+
displayName: '[email protected]',
841+
},
842+
versionTag: '1.0.1',
843+
// Version 2 is inactive because it's a different version
844+
status: 'inactive',
845+
versionId: 'gid://shopify/Version/2',
846+
message: 'Test deploy 2',
847+
},
848+
],
849+
pageInfo: {
850+
totalResults: 77,
851+
},
852+
},
853+
},
854+
})
855+
})
756856
})

packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ export class AppManagementClient implements DeveloperPlatformClient {
459459
}
460460
}
461461

462-
async appVersions({id, organizationId, title}: OrganizationApp): Promise<AppVersionsQuerySchemaInterface> {
462+
async appVersions({id, organizationId, title}: MinimalOrganizationApp): Promise<AppVersionsQuerySchemaInterface> {
463463
const query = AppVersions
464464
const variables = {appId: id}
465465
const result = await appManagementRequestDoc(organizationId, query, await this.token(), variables)
@@ -469,20 +469,22 @@ export class AppManagementClient implements DeveloperPlatformClient {
469469
organizationId,
470470
title,
471471
appVersions: {
472-
nodes: result.versions.map((version) => {
473-
return {
474-
createdAt: version.createdAt,
475-
createdBy: {
476-
displayName: version.createdBy,
477-
},
478-
versionTag: version.metadata.versionTag,
479-
status: version.id === result.app.activeRelease.version.id ? 'active' : 'inactive',
480-
versionId: version.id,
481-
message: version.metadata.message,
482-
}
483-
}),
472+
nodes:
473+
result.app.versions?.edges.map((edge) => {
474+
const version = edge.node
475+
return {
476+
createdAt: version.createdAt,
477+
createdBy: {
478+
displayName: version.createdBy,
479+
},
480+
versionTag: version.metadata.versionTag,
481+
status: version.id === result.app.activeRelease.version.id ? 'active' : 'inactive',
482+
versionId: version.id,
483+
message: version.metadata.message,
484+
}
485+
}) ?? [],
484486
pageInfo: {
485-
totalResults: result.versions.length,
487+
totalResults: result.app.versionsCount,
486488
},
487489
},
488490
},

0 commit comments

Comments
 (0)