Skip to content
Draft
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
69 changes: 69 additions & 0 deletions packages/eas-cli/src/commands/update/view-embedded.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Args } from '@oclif/core';

import EasCommand from '../../commandUtils/EasCommand';
import { EasJsonOnlyFlag } from '../../commandUtils/flags';
import {
EmbeddedUpdateFragment,
EmbeddedUpdateQuery,
} from '../../graphql/queries/EmbeddedUpdateQuery';
import Log from '../../log';
import formatFields from '../../utils/formatFields';
import { enableJsonOutput, printJsonOnlyOutput } from '../../utils/json';

export default class UpdateViewEmbedded extends EasCommand {
static override description = 'view details of an embedded update registered with EAS Update';

static override args = {
id: Args.string({
required: true,
description: 'The ID of the embedded update (manifest UUID from app.manifest).',
}),
};

static override flags = {
...EasJsonOnlyFlag,
};

static override contextDefinition = {
...this.ContextOptions.ProjectId,
...this.ContextOptions.LoggedIn,
};

async runAsync(): Promise<void> {
const {
args: { id: embeddedUpdateId },
flags: { json: jsonFlag },
} = await this.parse(UpdateViewEmbedded);

const {
projectId,
loggedIn: { graphqlClient },
} = await this.getContextAsync(UpdateViewEmbedded, { nonInteractive: true });

if (jsonFlag) {
enableJsonOutput();
}

const embeddedUpdate = await EmbeddedUpdateQuery.viewByIdAsync(graphqlClient, {
embeddedUpdateId,
appId: projectId,
});

if (jsonFlag) {
printJsonOnlyOutput(embeddedUpdate);
return;
}

Log.log(formatEmbeddedUpdate(embeddedUpdate));
}
}

export function formatEmbeddedUpdate(embeddedUpdate: EmbeddedUpdateFragment): string {
return formatFields([
{ label: 'ID', value: embeddedUpdate.id },
{ label: 'Platform', value: embeddedUpdate.platform.toLowerCase() },
{ label: 'Runtime version', value: embeddedUpdate.runtimeVersion },
{ label: 'Channel', value: embeddedUpdate.channel },
{ label: 'Created at', value: new Date(embeddedUpdate.createdAt).toLocaleString() },
]);
}
129 changes: 129 additions & 0 deletions packages/eas-cli/src/graphql/queries/EmbeddedUpdateQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import gql from 'graphql-tag';

import { ExpoGraphqlClient } from '../../commandUtils/context/contextUtils/createGraphqlClient';
import { AppPlatform } from '../generated';
import { Connection } from '../../utils/relay';
import { withErrorHandlingAsync } from '../client';

export type EmbeddedUpdateFragment = {
id: string;
platform: AppPlatform;
runtimeVersion: string;
channel: string;
createdAt: string;
};

type ViewEmbeddedUpdateByIdQueryResult = {
embeddedUpdates: {
byId: EmbeddedUpdateFragment;
};
};

type ViewEmbeddedUpdatesPaginatedQueryResult = {
app: {
byId: {
embeddedUpdatesPaginated: {
edges: { cursor: string; node: EmbeddedUpdateFragment }[];
pageInfo: {
hasNextPage: boolean;
hasPreviousPage: boolean;
startCursor: string | null;
endCursor: string | null;
};
};
};
};
};

export type EmbeddedUpdateFilter = {
platform?: AppPlatform;
runtimeVersion?: string;
channel?: string;
};

export const EmbeddedUpdateQuery = {
async viewByIdAsync(
graphqlClient: ExpoGraphqlClient,
{ embeddedUpdateId, appId }: { embeddedUpdateId: string; appId: string }
): Promise<EmbeddedUpdateFragment> {
const data = await withErrorHandlingAsync(
graphqlClient
.query<ViewEmbeddedUpdateByIdQueryResult>(
gql`
query ViewEmbeddedUpdateById($embeddedUpdateId: ID!, $appId: ID!) {
embeddedUpdates {
byId(embeddedUpdateId: $embeddedUpdateId, appId: $appId) {
id
platform
runtimeVersion
channel
createdAt
}
}
}
`,
{ embeddedUpdateId, appId },
{ additionalTypenames: ['EmbeddedUpdate'] }
)
.toPromise()
);
return data.embeddedUpdates.byId;
},

async viewPaginatedAsync(
graphqlClient: ExpoGraphqlClient,
{
appId,
filter,
first,
after,
}: {
appId: string;
filter?: EmbeddedUpdateFilter;
first: number;
after?: string;
}
): Promise<Connection<EmbeddedUpdateFragment>> {
const data = await withErrorHandlingAsync(
graphqlClient
.query<ViewEmbeddedUpdatesPaginatedQueryResult>(
gql`
query ViewEmbeddedUpdatesPaginated(
$appId: String!
$first: Int!
$after: String
$filter: EmbeddedUpdateFilterInput
) {
app {
byId(appId: $appId) {
id
embeddedUpdatesPaginated(first: $first, after: $after, filter: $filter) {
edges {
cursor
node {
id
platform
runtimeVersion
channel
createdAt
}
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
}
}
}
}
`,
{ appId, first, after, filter },
{ additionalTypenames: ['EmbeddedUpdate'] }
)
.toPromise()
);
return data.app.byId.embeddedUpdatesPaginated;
},
};
Loading