From d18e79771016aa6023f2446374702e4c3b991d01 Mon Sep 17 00:00:00 2001 From: Quinlan Jung Date: Mon, 24 Jul 2023 16:39:29 -0700 Subject: [PATCH 1/2] [eas-cli] unify channel graphql query types --- packages/eas-cli/graphql.schema.json | 146 +----------------- packages/eas-cli/src/channel/queries.ts | 6 +- packages/eas-cli/src/commands/channel/edit.ts | 9 +- .../eas-cli/src/commands/channel/rollout.ts | 10 +- packages/eas-cli/src/graphql/generated.ts | 29 ++-- .../src/graphql/queries/ChannelQuery.ts | 78 ++++++++-- .../types/UpdateBranchWithCurrentUpdate.ts | 16 ++ .../graphql/types/UpdateChannelBasicInfo.ts | 9 ++ 8 files changed, 119 insertions(+), 184 deletions(-) create mode 100644 packages/eas-cli/src/graphql/types/UpdateBranchWithCurrentUpdate.ts create mode 100644 packages/eas-cli/src/graphql/types/UpdateChannelBasicInfo.ts diff --git a/packages/eas-cli/graphql.schema.json b/packages/eas-cli/graphql.schema.json index a16fad0e07..79d6c3cb46 100644 --- a/packages/eas-cli/graphql.schema.json +++ b/packages/eas-cli/graphql.schema.json @@ -2572,18 +2572,6 @@ "name": "AccountSSOConfiguration", "description": "Auth configuration data for an SSO account.", "fields": [ - { - "name": "authEndpoint", - "description": null, - "args": [], - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null - }, { "name": "authProtocol", "description": null, @@ -2664,18 +2652,6 @@ "isDeprecated": false, "deprecationReason": null }, - { - "name": "endSessionEndpoint", - "description": null, - "args": [], - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null - }, { "name": "id", "description": null, @@ -2708,42 +2684,6 @@ "isDeprecated": false, "deprecationReason": null }, - { - "name": "jwksEndpoint", - "description": null, - "args": [], - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "revokeEndpoint", - "description": null, - "args": [], - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "tokenEndpoint", - "description": null, - "args": [], - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null - }, { "name": "updatedAt", "description": null, @@ -2759,18 +2699,6 @@ }, "isDeprecated": false, "deprecationReason": null - }, - { - "name": "userInfoEndpoint", - "description": null, - "args": [], - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null } ], "inputFields": null, @@ -3088,18 +3016,6 @@ "name": "AccountSSOConfigurationPublicData", "description": "Public auth configuration data for an SSO account.", "fields": [ - { - "name": "authEndpoint", - "description": null, - "args": [], - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null - }, { "name": "authProtocol", "description": null, @@ -3133,7 +3049,7 @@ "deprecationReason": null }, { - "name": "clientIdentifier", + "name": "authorizationUrl", "description": null, "args": [], "type": { @@ -3148,18 +3064,6 @@ "isDeprecated": false, "deprecationReason": null }, - { - "name": "endSessionEndpoint", - "description": null, - "args": [], - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null - }, { "name": "id", "description": null, @@ -3191,54 +3095,6 @@ }, "isDeprecated": false, "deprecationReason": null - }, - { - "name": "jwksEndpoint", - "description": null, - "args": [], - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "revokeEndpoint", - "description": null, - "args": [], - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "tokenEndpoint", - "description": null, - "args": [], - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "userInfoEndpoint", - "description": null, - "args": [], - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null } ], "inputFields": null, diff --git a/packages/eas-cli/src/channel/queries.ts b/packages/eas-cli/src/channel/queries.ts index 7a93e68e36..9415483db0 100644 --- a/packages/eas-cli/src/channel/queries.ts +++ b/packages/eas-cli/src/channel/queries.ts @@ -1,4 +1,5 @@ import chalk from 'chalk'; +import { print } from 'graphql'; import gql from 'graphql-tag'; import { ExpoGraphqlClient } from '../commandUtils/context/contextUtils/createGraphqlClient'; @@ -12,6 +13,7 @@ import { } from '../graphql/generated'; import { BranchQuery, UpdateBranchOnChannelObject } from '../graphql/queries/BranchQuery'; import { ChannelQuery, UpdateChannelObject } from '../graphql/queries/ChannelQuery'; +import { UpdateChannelBasicInfoFragmentNode } from '../graphql/types/UpdateChannelBasicInfo'; import Log from '../log'; import formatFields from '../utils/formatFields'; import { printJsonOnlyOutput } from '../utils/json'; @@ -227,11 +229,11 @@ export async function createChannelOnAppAsync( updateChannel { createUpdateChannelForApp(appId: $appId, name: $name, branchMapping: $branchMapping) { id - name - branchMapping + ...UpdateChannelBasicInfoFragment } } } + ${print(UpdateChannelBasicInfoFragmentNode)} `, { appId, diff --git a/packages/eas-cli/src/commands/channel/edit.ts b/packages/eas-cli/src/commands/channel/edit.ts index 39da565d45..2b3315a206 100644 --- a/packages/eas-cli/src/commands/channel/edit.ts +++ b/packages/eas-cli/src/commands/channel/edit.ts @@ -1,5 +1,6 @@ import { Flags } from '@oclif/core'; import chalk from 'chalk'; +import { print } from 'graphql'; import gql from 'graphql-tag'; import { selectBranchOnAppAsync } from '../../branch/queries'; @@ -9,18 +10,20 @@ import { ExpoGraphqlClient } from '../../commandUtils/context/contextUtils/creat import { EasNonInteractiveAndJsonFlags } from '../../commandUtils/flags'; import { withErrorHandlingAsync } from '../../graphql/client'; import { + UpdateChannelBasicInfoFragment, UpdateChannelBranchMappingMutation, UpdateChannelBranchMappingMutationVariables, } from '../../graphql/generated'; import { BranchQuery } from '../../graphql/queries/BranchQuery'; import { ChannelQuery } from '../../graphql/queries/ChannelQuery'; +import { UpdateChannelBasicInfoFragmentNode } from '../../graphql/types/UpdateChannelBasicInfo'; import Log from '../../log'; import { enableJsonOutput, printJsonOnlyOutput } from '../../utils/json'; export async function updateChannelBranchMappingAsync( graphqlClient: ExpoGraphqlClient, { channelId, branchMapping }: UpdateChannelBranchMappingMutationVariables -): Promise { +): Promise { const data = await withErrorHandlingAsync( graphqlClient .mutation( @@ -29,11 +32,11 @@ export async function updateChannelBranchMappingAsync( updateChannel { editUpdateChannel(channelId: $channelId, branchMapping: $branchMapping) { id - name - branchMapping + ...UpdateChannelBasicInfoFragment } } } + ${print(UpdateChannelBasicInfoFragmentNode)} `, { channelId, branchMapping } ) diff --git a/packages/eas-cli/src/commands/channel/rollout.ts b/packages/eas-cli/src/commands/channel/rollout.ts index 040f3be577..536f386633 100644 --- a/packages/eas-cli/src/commands/channel/rollout.ts +++ b/packages/eas-cli/src/commands/channel/rollout.ts @@ -15,7 +15,7 @@ import { ExpoGraphqlClient } from '../../commandUtils/context/contextUtils/creat import { EasNonInteractiveAndJsonFlags } from '../../commandUtils/flags'; import { UpdateBranch } from '../../graphql/generated'; import { BranchQuery } from '../../graphql/queries/BranchQuery'; -import { ChannelQuery, UpdateChannelByNameObject } from '../../graphql/queries/ChannelQuery'; +import { ChannelQuery, UpdateChannelObject } from '../../graphql/queries/ChannelQuery'; import Log from '../../log'; import { getDisplayNameForProjectIdAsync } from '../../project/projectUtils'; import { promptAsync, selectAsync } from '../../prompts'; @@ -45,7 +45,7 @@ async function promptForRolloutPercentAsync({ return rolloutPercent; } -function getRolloutInfo(channel: UpdateChannelByNameObject): { +function getRolloutInfo(channel: UpdateChannelObject): { newBranch: Pick; oldBranch: Pick; currentPercent: number; @@ -84,7 +84,7 @@ async function startRolloutAsync( projectId: string; displayName: string; currentBranchMapping: BranchMapping; - channel: UpdateChannelByNameObject; + channel: UpdateChannelObject; nonInteractive: boolean; } ): Promise<{ @@ -165,7 +165,7 @@ async function editRolloutAsync( percent?: number; nonInteractive: boolean; currentBranchMapping: BranchMapping; - channel: UpdateChannelByNameObject; + channel: UpdateChannelObject; } ): Promise<{ newChannelInfo: { @@ -223,7 +223,7 @@ async function endRolloutAsync( branchName?: string; nonInteractive: boolean; projectId: string; - channel: UpdateChannelByNameObject; + channel: UpdateChannelObject; } ): Promise<{ newChannelInfo: { diff --git a/packages/eas-cli/src/graphql/generated.ts b/packages/eas-cli/src/graphql/generated.ts index b887e63a68..615ef845a4 100644 --- a/packages/eas-cli/src/graphql/generated.ts +++ b/packages/eas-cli/src/graphql/generated.ts @@ -468,20 +468,14 @@ export type AccountQueryByNameArgs = { /** Auth configuration data for an SSO account. */ export type AccountSsoConfiguration = { __typename?: 'AccountSSOConfiguration'; - authEndpoint?: Maybe; authProtocol: AuthProtocolType; authProviderIdentifier: Scalars['String']; clientIdentifier: Scalars['String']; clientSecret: Scalars['String']; createdAt: Scalars['DateTime']; - endSessionEndpoint?: Maybe; id: Scalars['ID']; issuer: Scalars['String']; - jwksEndpoint?: Maybe; - revokeEndpoint?: Maybe; - tokenEndpoint?: Maybe; updatedAt: Scalars['DateTime']; - userInfoEndpoint?: Maybe; }; export type AccountSsoConfigurationData = { @@ -528,17 +522,11 @@ export type AccountSsoConfigurationMutationUpdateAccountSsoConfigurationArgs = { /** Public auth configuration data for an SSO account. */ export type AccountSsoConfigurationPublicData = { __typename?: 'AccountSSOConfigurationPublicData'; - authEndpoint?: Maybe; authProtocol: AuthProtocolType; authProviderIdentifier: Scalars['String']; - clientIdentifier: Scalars['String']; - endSessionEndpoint?: Maybe; + authorizationUrl: Scalars['String']; id: Scalars['ID']; issuer: Scalars['String']; - jwksEndpoint?: Maybe; - revokeEndpoint?: Maybe; - tokenEndpoint?: Maybe; - userInfoEndpoint?: Maybe; }; export type AccountSsoConfigurationPublicDataQuery = { @@ -6197,7 +6185,16 @@ export type ViewUpdateChannelsOnAppQueryVariables = Exact<{ }>; -export type ViewUpdateChannelsOnAppQuery = { __typename?: 'RootQuery', app: { __typename?: 'AppQuery', byId: { __typename?: 'App', id: string, updateChannels: Array<{ __typename?: 'UpdateChannel', id: string, name: string, branchMapping: string, updateBranches: Array<{ __typename?: 'UpdateBranch', id: string, name: string, updateGroups: Array> }> }> } } }; +export type ViewUpdateChannelsOnAppQuery = { __typename?: 'RootQuery', app: { __typename?: 'AppQuery', byId: { __typename?: 'App', id: string, updateChannels: Array<{ __typename?: 'UpdateChannel', id: string, name: string, createdAt: any, branchMapping: string, updateBranches: Array<{ __typename?: 'UpdateBranch', id: string, name: string, updateGroups: Array> }> }> } } }; + +export type ViewUpdateChannelsPaginatedOnAppQueryVariables = Exact<{ + appId: Scalars['String']; + first?: InputMaybe; + after?: InputMaybe; +}>; + + +export type ViewUpdateChannelsPaginatedOnAppQuery = { __typename?: 'RootQuery', app: { __typename?: 'AppQuery', byId: { __typename?: 'App', id: string, channelsPaginated: { __typename?: 'AppChannelsConnection', edges: Array<{ __typename?: 'AppChannelEdge', node: { __typename?: 'UpdateChannel', id: string, name: string, branchMapping: string } }>, pageInfo: { __typename?: 'PageInfo', hasNextPage: boolean, hasPreviousPage: boolean, startCursor?: string | null, endCursor?: string | null } } } } }; export type EnvironmentSecretsByAppIdQueryVariables = Exact<{ appId: Scalars['String']; @@ -6311,6 +6308,10 @@ export type UpdateFragment = { __typename?: 'Update', id: string, group: string, export type UpdateBranchFragment = { __typename?: 'UpdateBranch', id: string, name: string, updates: Array<{ __typename?: 'Update', id: string, group: string, message?: string | null, createdAt: any, runtimeVersion: string, platform: string, manifestFragment: string, isRollBackToEmbedded: boolean, manifestPermalink: string, gitCommitHash?: string | null, actor?: { __typename: 'Robot', firstName?: string | null, id: string } | { __typename: 'SSOUser', username: string, id: string } | { __typename: 'User', username: string, id: string } | null, branch: { __typename?: 'UpdateBranch', id: string, name: string }, codeSigningInfo?: { __typename?: 'CodeSigningInfo', keyid: string, sig: string, alg: string } | null }> }; +export type UpdateBranchWithCurrentGroupFragment = { __typename?: 'UpdateBranch', id: string, name: string, updateGroups: Array> }; + +export type UpdateChannelBasicInfoFragment = { __typename?: 'UpdateChannel', id: string, name: string, branchMapping: string }; + export type WebhookFragment = { __typename?: 'Webhook', id: string, event: WebhookType, url: string, createdAt: any, updatedAt: any }; export type AndroidAppBuildCredentialsFragment = { __typename?: 'AndroidAppBuildCredentials', id: string, isDefault: boolean, isLegacy: boolean, name: string, androidKeystore?: { __typename?: 'AndroidKeystore', id: string, type: AndroidKeystoreType, keystore: string, keystorePassword: string, keyAlias: string, keyPassword?: string | null, md5CertificateFingerprint?: string | null, sha1CertificateFingerprint?: string | null, sha256CertificateFingerprint?: string | null, createdAt: any, updatedAt: any } | null }; diff --git a/packages/eas-cli/src/graphql/queries/ChannelQuery.ts b/packages/eas-cli/src/graphql/queries/ChannelQuery.ts index 370e8d5ee2..5b60828a81 100644 --- a/packages/eas-cli/src/graphql/queries/ChannelQuery.ts +++ b/packages/eas-cli/src/graphql/queries/ChannelQuery.ts @@ -5,21 +5,29 @@ import { ChannelNotFoundError } from '../../channel/errors'; import { ExpoGraphqlClient } from '../../commandUtils/context/contextUtils/createGraphqlClient'; import { withErrorHandlingAsync } from '../client'; import { + PageInfo, + UpdateChannelBasicInfoFragment, ViewUpdateChannelOnAppQuery, ViewUpdateChannelOnAppQueryVariables, ViewUpdateChannelsOnAppQuery, ViewUpdateChannelsOnAppQueryVariables, + ViewUpdateChannelsPaginatedOnAppQuery, + ViewUpdateChannelsPaginatedOnAppQueryVariables, } from '../generated'; -import { UpdateFragmentNode } from '../types/Update'; +import { UpdateBranchWithCurrentGroupFragmentNode } from '../types/UpdateBranchWithCurrentUpdate'; +import { UpdateChannelBasicInfoFragmentNode } from '../types/UpdateChannelBasicInfo'; -export type UpdateChannelObject = NonNullable< +type ViewUpdateChannelsOnAppObject = NonNullable< ViewUpdateChannelsOnAppQuery['app']['byId']['updateChannels'] >[number]; -export type UpdateChannelByNameObject = NonNullable< +type UpdateChannelByNameObject = NonNullable< ViewUpdateChannelOnAppQuery['app']['byId']['updateChannelByName'] >; +// these types should have the same fields +export type UpdateChannelObject = ViewUpdateChannelsOnAppObject & UpdateChannelByNameObject; + export const ChannelQuery = { async viewUpdateChannelAsync( graphqlClient: ExpoGraphqlClient, @@ -40,17 +48,13 @@ export const ChannelQuery = { branchMapping updateBranches(offset: 0, limit: 5) { id - name - updateGroups(offset: 0, limit: 1) { - id - ...UpdateFragment - } + ...UpdateBranchWithCurrentGroupFragment } } } } } - ${print(UpdateFragmentNode)} + ${print(UpdateBranchWithCurrentGroupFragmentNode)} `, { appId, channelName }, { additionalTypenames: ['UpdateChannel', 'UpdateBranch', 'Update'] } @@ -80,20 +84,17 @@ export const ChannelQuery = { updateChannels(offset: $offset, limit: $limit) { id name + createdAt branchMapping updateBranches(offset: 0, limit: 5) { id - name - updateGroups(offset: 0, limit: 1) { - id - ...UpdateFragment - } + ...UpdateBranchWithCurrentGroupFragment } } } } } - ${print(UpdateFragmentNode)} + ${print(UpdateBranchWithCurrentGroupFragmentNode)} `, { appId, offset, limit }, { additionalTypenames: ['UpdateChannel', 'UpdateBranch', 'Update'] } @@ -108,4 +109,51 @@ export const ChannelQuery = { return updateChannels; }, + async viewUpdateChannelsBasicInfoPaginatedOnAppAsync( + graphqlClient: ExpoGraphqlClient, + { appId, first, after }: ViewUpdateChannelsPaginatedOnAppQueryVariables + ): Promise<[UpdateChannelBasicInfoFragment[], PageInfo]> { + const response = await withErrorHandlingAsync( + graphqlClient + .query< + ViewUpdateChannelsPaginatedOnAppQuery, + ViewUpdateChannelsPaginatedOnAppQueryVariables + >( + gql` + query ViewUpdateChannelsPaginatedOnApp($appId: String!, $first: Int, $after: String) { + app { + byId(appId: $appId) { + id + channelsPaginated(first: $first, after: $after) { + edges { + node { + id + ...UpdateChannelBasicInfoFragment + } + } + pageInfo { + hasNextPage + hasPreviousPage + startCursor + endCursor + } + } + } + } + } + ${print(UpdateChannelBasicInfoFragmentNode)} + `, + { appId, first, after }, + { additionalTypenames: ['UpdateChannel', 'UpdateBranch', 'Update'] } + ) + .toPromise() + ); + const { channelsPaginated } = response.app.byId; + + if (!channelsPaginated) { + throw new Error(`Could not find channels on project with id ${appId}`); + } + + return [channelsPaginated.edges.map(edge => edge.node) ?? [], channelsPaginated.pageInfo]; + }, }; diff --git a/packages/eas-cli/src/graphql/types/UpdateBranchWithCurrentUpdate.ts b/packages/eas-cli/src/graphql/types/UpdateBranchWithCurrentUpdate.ts new file mode 100644 index 0000000000..9c9dfe1bf9 --- /dev/null +++ b/packages/eas-cli/src/graphql/types/UpdateBranchWithCurrentUpdate.ts @@ -0,0 +1,16 @@ +import { print } from 'graphql'; +import gql from 'graphql-tag'; + +import { UpdateFragmentNode } from './Update'; + +export const UpdateBranchWithCurrentGroupFragmentNode = gql` + fragment UpdateBranchWithCurrentGroupFragment on UpdateBranch { + id + name + updateGroups(offset: 0, limit: 1) { + id + ...UpdateFragment + } + } + ${print(UpdateFragmentNode)} +`; diff --git a/packages/eas-cli/src/graphql/types/UpdateChannelBasicInfo.ts b/packages/eas-cli/src/graphql/types/UpdateChannelBasicInfo.ts new file mode 100644 index 0000000000..e6681fc3e2 --- /dev/null +++ b/packages/eas-cli/src/graphql/types/UpdateChannelBasicInfo.ts @@ -0,0 +1,9 @@ +import gql from 'graphql-tag'; + +export const UpdateChannelBasicInfoFragmentNode = gql` + fragment UpdateChannelBasicInfoFragment on UpdateChannel { + id + name + branchMapping + } +`; From 2af0117cf2a786953e170d6b66285afd0d6c5a4e Mon Sep 17 00:00:00 2001 From: Quinlan Jung Date: Tue, 25 Jul 2023 03:28:31 +0000 Subject: [PATCH 2/2] update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5596be7cea..03d9d63ae5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ This is the log of notable changes to EAS CLI and related packages. ### ๐Ÿงน Chores +- Unify channel graphql query types. ([#1949](https://github.com/expo/eas-cli/pull/1949) by [@quinlanj](https://github.com/quinlanj)) + ## [3.17.0](https://github.com/expo/eas-cli/releases/tag/v3.17.0) - 2023-07-24 ### ๐ŸŽ‰ New features