diff --git a/package.json b/package.json index 65017dfc3d..010db561c1 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,8 @@ "update:integration-snapshots": "UPDATE_INTEGRATION_SNAPSHOTS=true tsx --test --test-reporter spec packages/integration-tests/lib/test-in-memory", "update:tsconfig-refs": "tsx scripts/update_tsconfig_refs.ts", "vend": "npm run start:npm-proxy && npm run publish:local", - "watch": "npm run build -- --watch" + "watch": "npm run build -- --watch", + "al": "bash -c 'tsc --build packages/cli' && bash -c 'npm run test:dir packages/cli/lib/commands/generate/graphql-client-code'" }, "repository": { "type": "git", diff --git a/packages/cli/src/commands/generate/graphql-client-code/generate_graphql_client_code_command.test.ts b/packages/cli/src/commands/generate/graphql-client-code/generate_graphql_client_code_command.test.ts index 12ca2074b8..bd87ac06a9 100644 --- a/packages/cli/src/commands/generate/graphql-client-code/generate_graphql_client_code_command.test.ts +++ b/packages/cli/src/commands/generate/graphql-client-code/generate_graphql_client_code_command.test.ts @@ -85,7 +85,7 @@ describe('generate graphql-client-code command', () => { it('can generate to custom absolute path', async () => { await commandRunner.runCommand( - 'graphql-client-code --stack stack_name --out /foo/bar --format ts' + 'graphql-client-code --stack stack_name --out /foo/bar' ); assert.equal(generateClientConfigMock.mock.callCount(), 1); assert.deepEqual(generateClientConfigMock.mock.calls[0].arguments[0], { @@ -106,7 +106,7 @@ describe('generate graphql-client-code command', () => { it('can generate to custom relative path', async () => { await commandRunner.runCommand( - 'graphql-client-code --stack stack_name --out foo/bar --format js' + 'graphql-client-code --stack stack_name --out foo/bar' ); assert.equal(generateClientConfigMock.mock.callCount(), 1); assert.deepEqual(generateClientConfigMock.mock.calls[0].arguments[0], { @@ -125,6 +125,8 @@ describe('generate graphql-client-code command', () => { assert.match(output, /--appId/); assert.match(output, /--branch/); assert.match(output, /--format/); + assert.match(output, /--platform/); + assert.match(output, /--target/); assert.match(output, /--out/); }); diff --git a/packages/cli/src/commands/generate/graphql-client-code/generate_graphql_client_code_command.ts b/packages/cli/src/commands/generate/graphql-client-code/generate_graphql_client_code_command.ts index 049abf051c..8999f64f00 100644 --- a/packages/cli/src/commands/generate/graphql-client-code/generate_graphql_client_code_command.ts +++ b/packages/cli/src/commands/generate/graphql-client-code/generate_graphql_client_code_command.ts @@ -4,14 +4,22 @@ import { BackendIdentifier } from '@aws-amplify/client-config'; import { AppNameResolver } from '../../../local_app_name_resolver.js'; import { GraphqlClientCodeGeneratorAdapter } from './generate_graphql_client_code_generator_adapter.js'; -export const formatChoices = ['js', 'json', 'ts'] as const; +export const formatChoices = ['amplify-codegen', 'introspection', 'modelgen']; +export const platformChoices = ['js', 'ts', 'dart', 'android', 'swift']; export const configFileName = 'amplifyconfiguration'; +export const modelgenTargetChoices = ['java', 'swift', 'javascript', 'typescript', 'dart', 'introspection']; +export const statementsTargetChoices = ['javascript', 'graphql', 'flow', 'typescript', 'angular'] +export const typesTargetChoice = ['json', 'swift', 'ts', 'typescript', 'flow', 'scala', 'flow-modern', 'angular'] +export const targetChoices = ['javascript', 'java', 'swift', 'typescript', 'dart', 'introspection', 'graphql', 'flow', 'angular', 'json', 'ts', 'scala', 'flow-modern']; + export type GenerateGraphqlClientCodeCommandOptions = { stack: string | undefined; appId: string | undefined; branch: string | undefined; format: (typeof formatChoices)[number] | undefined; + platform: (typeof platformChoices)[number] | undefined; + target: (typeof targetChoices)[number] | undefined; out: string | undefined; }; @@ -54,7 +62,9 @@ export class GenerateGraphqlClientCodeCommand ): Promise => { const defaultArgs = { out: process.cwd(), - format: 'js', + format: 'amplify-codegen', + platform: 'js', + target: 'javascript', }; const backendIdentifier = await this.getBackendIdentifier(args); @@ -126,14 +136,25 @@ export class GenerateGraphqlClientCodeCommand group: 'Project identifier', }) .option('format', { - describe: 'The format which the configuration should be exported into.', + describe: 'The format that the GraphQL client code should be generated in.', type: 'string', array: false, choices: formatChoices, }) + .option('platform', { + describe: 'The platform for which the configuration should be exported for.', + type: 'string', + array: false, + choices: platformChoices, + }) + .option('target', { + describe: 'The platform for which the configuration should be exported for.', + type: 'string', + array: false, + choices: targetChoices, + }) .option('out', { - describe: - 'A path to directory where config is written. If not provided defaults to current process working directory.', + describe: 'A path to directory where config is written. If not provided defaults to current process working directory.', type: 'string', array: false, }) diff --git a/packages/cli/src/commands/generate/graphql-client-code/mock_code_generator.ts b/packages/cli/src/commands/generate/graphql-client-code/mock_code_generator.ts new file mode 100644 index 0000000000..791afba740 --- /dev/null +++ b/packages/cli/src/commands/generate/graphql-client-code/mock_code_generator.ts @@ -0,0 +1,26 @@ +import { BackendIdentifier } from "@aws-amplify/client-config"; +import { AwsCredentialIdentityProvider } from "@aws-sdk/types"; + +export const formatChoices = ['introspection', 'amplify-codegen', 'modelgen']; +export const platformChoices = ['ts', 'js', 'dart', 'android', 'swift']; +export const configFileName = 'amplifyconfiguration'; + +export const modelgenTargetChoices = ['java', 'swift', 'javascript', 'typescript', 'dart', 'introspection']; +export const statementsTargetChoices = ['javascript', 'graphql', 'flow', 'typescript', 'angular'] +export const typesTargetChoice = ['json', 'swift', 'ts', 'typescript', 'flow', 'scala', 'flow-modern', 'angular'] + +export type GenerateAPICodeProps = BackendIdentifier & { + credentialProvider: AwsCredentialIdentityProvider, + format: string; + platform: string; + target?: string; +}; + +/** + * Mock generateApiCode command. + */ +export const generateAPICode = (props: GenerateAPICodeProps): Record => { + // eslint-disable-next-line no-console + console.log(`generateAPICode invoked with ${JSON.stringify(props)}`); + return {}; +};