Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate client code command #265

Merged
merged 11 commits into from
Sep 25, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand Down
18 changes: 15 additions & 3 deletions packages/model-generator/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,30 @@ export type DocumentGenerationParameters = {
// @public
export const generateApiCode: (props: GenerateApiCodeProps) => Promise<GenerationResult>;

// @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"];
alharris-at marked this conversation as resolved.
Show resolved Hide resolved

// @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;
};

Expand All @@ -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;
Expand Down
42 changes: 32 additions & 10 deletions packages/model-generator/src/generate_api_code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
};

Expand Down
Loading