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 0d10e984c7..c0a86ed547 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 @@ -2,41 +2,21 @@ import { ArgumentsCamelCase, Argv, CommandModule } from 'yargs'; import { BackendIdentifierResolver } from '../../../backend-identifier/backend_identifier_resolver.js'; import { isAbsolute, resolve } from 'path'; import { GenerateApiCodeAdapter } from './generate_api_code_adapter.js'; - -export const formatChoices = ['graphql-codegen', 'introspection', 'modelgen']; -export const modelgenTargetChoices = [ - 'java', - 'swift', - 'javascript', - 'typescript', - 'dart', -]; -export const statementsTargetChoices = [ - 'javascript', - 'graphql', - 'flow', - 'typescript', - 'angular', -]; -export const typesTargetChoice = [ - 'json', - 'swift', - 'ts', - 'typescript', - 'flow', - 'scala', - 'flow-modern', - 'angular', -]; +import { + generateApiCodeFormats, + generateApiCodeModelTargets, + generateApiCodeStatementTargets, + generateApiCodeTypeTargets, +} from '@aws-amplify/model-generator'; export type GenerateGraphqlClientCodeCommandOptions = { stack: string | undefined; appId: string | undefined; branch: string | undefined; - format: (typeof formatChoices)[number] | undefined; - modelTarget: (typeof modelgenTargetChoices)[number] | undefined; - statementTarget: (typeof statementsTargetChoices)[number] | undefined; - typeTarget: (typeof typesTargetChoice)[number] | undefined; + format: (typeof generateApiCodeFormats)[number] | undefined; + modelTarget: (typeof generateApiCodeModelTargets)[number] | undefined; + statementTarget: (typeof generateApiCodeStatementTargets)[number] | undefined; + typeTarget: (typeof generateApiCodeTypeTargets)[number] | undefined; out: string | undefined; modelGenerateIndexRules: boolean | undefined; modelEmitAuthProvider: boolean | undefined; @@ -207,28 +187,28 @@ export class GenerateGraphqlClientCodeCommand 'The format that the GraphQL client code should be generated in.', type: 'string', array: false, - choices: formatChoices, + choices: generateApiCodeFormats, }) .option('modelTarget', { describe: 'The modelgen export target. Only applies when the `--format` parameter is set to `modelgen`', type: 'string', array: false, - choices: modelgenTargetChoices, + choices: generateApiCodeModelTargets, }) .option('statementTarget', { describe: 'The graphql-codegen statement export target. Only applies when the `--format` parameter is set to `graphql-codegen`', type: 'string', array: false, - choices: statementsTargetChoices, + choices: generateApiCodeStatementTargets, }) .option('typeTarget', { describe: 'The optional graphql-codegen type export target. Only applies when the `--format` parameter is set to `graphql-codegen`', type: 'string', array: false, - choices: typesTargetChoice, + choices: generateApiCodeTypeTargets, }) .option('modelGenerateIndexRules', { description: 'Adds key/index details to iOS models', diff --git a/packages/model-generator/API.md b/packages/model-generator/API.md index 97087da629..128f207aaf 100644 --- a/packages/model-generator/API.md +++ b/packages/model-generator/API.md @@ -23,18 +23,30 @@ export type DocumentGenerationParameters = { // @public export const generateApiCode: (props: GenerateApiCodeProps) => Promise; +// @public (undocumented) +export const generateApiCodeFormats: readonly ["modelgen", "graphql-codegen", "introspection"]; + +// @public (undocumented) +export const generateApiCodeModelTargets: readonly ["java", "swift", "javascript", "typescript", "dart"]; + // @public (undocumented) export type GenerateApiCodeProps = GenerateOptions & BackendIdentifier & { credentialProvider: AwsCredentialIdentityProvider; }; +// @public (undocumented) +export const generateApiCodeStatementTargets: readonly ["javascript", "graphql", "flow", "typescript", "angular"]; + +// @public (undocumented) +export const generateApiCodeTypeTargets: readonly ["json", "swift", "typescript", "flow", "scala", "flow-modern", "angular"]; + // @public (undocumented) export type GenerateGraphqlCodegenOptions = { format: 'graphql-codegen'; - statementTarget: 'javascript' | 'graphql' | 'flow' | 'typescript' | 'angular'; + statementTarget: typeof generateApiCodeStatementTargets[number]; maxDepth?: number; typeNameIntrospection?: boolean; - typeTarget?: 'json' | 'swift' | 'typescript' | 'flow' | 'scala' | 'flow-modern' | 'angular'; + typeTarget?: typeof generateApiCodeTypeTargets[number]; multipleSwiftFiles?: boolean; }; @@ -46,7 +58,7 @@ export type GenerateIntrospectionOptions = { // @public (undocumented) export type GenerateModelsOptions = { format: 'modelgen'; - modelTarget: 'java' | 'swift' | 'javascript' | 'typescript' | 'dart'; + modelTarget: typeof generateApiCodeModelTargets[number]; generateIndexRules?: boolean; emitAuthProvider?: boolean; useExperimentalPipelinedTransformer?: boolean; diff --git a/packages/model-generator/src/generate_api_code.ts b/packages/model-generator/src/generate_api_code.ts index 6841ef8bbf..01d5caa90f 100644 --- a/packages/model-generator/src/generate_api_code.ts +++ b/packages/model-generator/src/generate_api_code.ts @@ -7,9 +7,38 @@ import { createGraphqlModelsGenerator } from './create_graphql_models_generator. import { createGraphqlTypesGenerator } from './create_graphql_types_generator.js'; import { createGraphqlDocumentGenerator } from './create_graphql_document_generator.js'; +export const generateApiCodeFormats = [ + 'modelgen', + 'graphql-codegen', + 'introspection', +] as const; +export const generateApiCodeModelTargets = [ + 'java', + 'swift', + 'javascript', + 'typescript', + 'dart', +] as const; +export const generateApiCodeStatementTargets = [ + 'javascript', + 'graphql', + 'flow', + 'typescript', + 'angular', +] as const; +export const generateApiCodeTypeTargets = [ + 'json', + 'swift', + 'typescript', + 'flow', + 'scala', + 'flow-modern', + 'angular', +] as const; + export type GenerateModelsOptions = { format: 'modelgen'; - modelTarget: 'java' | 'swift' | 'javascript' | 'typescript' | 'dart'; + modelTarget: (typeof generateApiCodeModelTargets)[number]; generateIndexRules?: boolean; emitAuthProvider?: boolean; useExperimentalPipelinedTransformer?: boolean; @@ -22,17 +51,10 @@ export type GenerateModelsOptions = { export type GenerateGraphqlCodegenOptions = { format: 'graphql-codegen'; - statementTarget: 'javascript' | 'graphql' | 'flow' | 'typescript' | 'angular'; + statementTarget: (typeof generateApiCodeStatementTargets)[number]; maxDepth?: number; typeNameIntrospection?: boolean; - typeTarget?: - | 'json' - | 'swift' - | 'typescript' - | 'flow' - | 'scala' - | 'flow-modern' - | 'angular'; + typeTarget?: (typeof generateApiCodeTypeTargets)[number]; multipleSwiftFiles?: boolean; };