Skip to content

Commit

Permalink
wip: working on this
Browse files Browse the repository at this point in the history
  • Loading branch information
alharris-at committed Sep 21, 2023
1 parent 0b72138 commit 5ae148c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 8 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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], {
Expand All @@ -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], {
Expand All @@ -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/);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -54,7 +62,9 @@ export class GenerateGraphqlClientCodeCommand
): Promise<void> => {
const defaultArgs = {
out: process.cwd(),
format: 'js',
format: 'amplify-codegen',
platform: 'js',
target: 'javascript',
};
const backendIdentifier = await this.getBackendIdentifier(args);

Expand Down Expand Up @@ -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,
})
Expand Down
Original file line number Diff line number Diff line change
@@ -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<string, string> => {
// eslint-disable-next-line no-console
console.log(`generateAPICode invoked with ${JSON.stringify(props)}`);
return {};
};

0 comments on commit 5ae148c

Please sign in to comment.