Skip to content

Commit

Permalink
feat(graphql-model-transformer): added transformer version feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
lazpavel committed Oct 11, 2021
1 parent 7309d96 commit a7ad372
Show file tree
Hide file tree
Showing 27 changed files with 93 additions and 55 deletions.
44 changes: 22 additions & 22 deletions packages/amplify-cli-core/src/__tests__/featureFlags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('feature flags', () => {

await fs.copyFile(templateConfigFileName, projectConfigFileName);

await FeatureFlags.initialize(({ getCurrentEnvName: () => 'dev' } as unknown) as CLIEnvironmentProvider, undefined, getTestFlags());
await FeatureFlags.initialize({ getCurrentEnvName: () => 'dev' } as unknown as CLIEnvironmentProvider, undefined, getTestFlags());

await FeatureFlags.ensureDefaultFeatureFlags(true);

Expand Down Expand Up @@ -78,7 +78,7 @@ describe('feature flags', () => {

await fs.copyFile(templateConfigFileName, projectConfigFileName);

await FeatureFlags.initialize(({ getCurrentEnvName: () => 'dev' } as unknown) as CLIEnvironmentProvider, undefined, getTestFlags());
await FeatureFlags.initialize({ getCurrentEnvName: () => 'dev' } as unknown as CLIEnvironmentProvider, undefined, getTestFlags());
await FeatureFlags.ensureDefaultFeatureFlags(true);

const originalConfig = (await fs.readFile(templateConfigFileName)).toString();
Expand All @@ -103,7 +103,7 @@ describe('feature flags', () => {

await fs.mkdirs(path.dirname(projectConfigFileName));

await FeatureFlags.initialize(({ getCurrentEnvName: () => 'dev' } as unknown) as CLIEnvironmentProvider, undefined, getTestFlags());
await FeatureFlags.initialize({ getCurrentEnvName: () => 'dev' } as unknown as CLIEnvironmentProvider, undefined, getTestFlags());
await FeatureFlags.ensureDefaultFeatureFlags(true);

const createdConfig = (await fs.readFile(projectConfigFileName)).toString();
Expand Down Expand Up @@ -131,7 +131,7 @@ describe('feature flags', () => {

await fs.copyFile(templateConfigFileName, projectConfigFileName);

await FeatureFlags.initialize(({ getCurrentEnvName: () => 'dev' } as unknown) as CLIEnvironmentProvider);
await FeatureFlags.initialize({ getCurrentEnvName: () => 'dev' } as unknown as CLIEnvironmentProvider);

expect(FeatureFlags.getBoolean('graphQLTransformer.validateTypeNameReservedWords')).toBe(false);
} finally {
Expand All @@ -141,7 +141,7 @@ describe('feature flags', () => {

test('missing environmentProvider argument', async () => {
await expect(async () => {
await FeatureFlags.initialize((undefined as unknown) as CLIContextEnvironmentProvider, undefined, getTestFlags());
await FeatureFlags.initialize(undefined as unknown as CLIContextEnvironmentProvider, undefined, getTestFlags());
}).rejects.toThrowError(`'environmentProvider' argument is required`);
});

Expand All @@ -162,10 +162,10 @@ describe('feature flags', () => {

await FeatureFlags.initialize(envProvider, undefined, getTestFlags());

const transformerVersion = FeatureFlags.getNumber('graphQLTransformer.transformerVersion');
const customTransformerVersion = FeatureFlags.getNumber('graphQLTransformer.customTransformerVersion');
const isDefaultQueryEnabled = FeatureFlags.getBoolean('keyTransformer.defaultQuery');

expect(transformerVersion).toBe(4);
expect(customTransformerVersion).toBe(4);
expect(isDefaultQueryEnabled).toBe(true);
});

Expand All @@ -178,12 +178,12 @@ describe('feature flags', () => {

process.chdir(tempProjectDir);

await FeatureFlags.initialize(({ getCurrentEnvName: () => 'dev' } as unknown) as CLIEnvironmentProvider, true, getTestFlags());
await FeatureFlags.initialize({ getCurrentEnvName: () => 'dev' } as unknown as CLIEnvironmentProvider, true, getTestFlags());

const transformerVersion = FeatureFlags.getNumber('graphQLTransformer.transformerVersion');
const customTransformerVersion = FeatureFlags.getNumber('graphQLTransformer.customTransformerVersion');
const isDefaultQueryEnabled = FeatureFlags.getBoolean('keyTransformer.defaultQuery');

expect(transformerVersion).toBe(5);
expect(customTransformerVersion).toBe(5);
expect(isDefaultQueryEnabled).toBe(true);
} finally {
rimraf.sync(tempProjectDir);
Expand Down Expand Up @@ -232,7 +232,7 @@ describe('feature flags', () => {

expect(effectiveFlags).toMatchObject({
graphqltransformer: {
transformerversion: 3,
customtransformerversion: 3,
},
keytransformer: {
defaultquery: false,
Expand Down Expand Up @@ -260,7 +260,7 @@ describe('feature flags', () => {

expect(effectiveFlags).toMatchObject({
graphqltransformer: {
transformerversion: 4,
customtransformerversion: 4,
},
keytransformer: {
defaultquery: true,
Expand Down Expand Up @@ -288,7 +288,7 @@ describe('feature flags', () => {

expect(effectiveFlags).toMatchObject({
graphqltransformer: {
transformerversion: 5,
customtransformerversion: 5,
},
keytransformer: {
defaultquery: false,
Expand Down Expand Up @@ -316,7 +316,7 @@ describe('feature flags', () => {

expect(effectiveFlags).toMatchObject({
graphqltransformer: {
transformerversion: 6,
customtransformerversion: 6,
},
keytransformer: {
defaultquery: true,
Expand Down Expand Up @@ -401,7 +401,7 @@ describe('feature flags', () => {

await expect(async () => {
await FeatureFlags.initialize(envProvider, undefined, getTestFlags());
}).rejects.toThrowError(`Invalid number value: 'invalid' for 'transformerversion' in section 'graphqltransformer'`);
}).rejects.toThrowError(`Invalid number value: 'invalid' for 'customtransformerversion' in section 'graphqltransformer'`);
});

test('initialize feature flag provider fail unknown flags', async () => {
Expand All @@ -425,15 +425,15 @@ describe('feature flags', () => {
message: 'Invalid feature flag configuration',
name: 'JSONValidationError',
unknownFlags: ['graphqltransformer.foo', 'graphqltransformer.bar'],
otherErrors: ['graphqltransformer.transformerversion: should be number'],
otherErrors: ['graphqltransformer.customtransformerversion: should be number'],
});
});

const getTestFlags = (): Record<string, FeatureFlagRegistration[]> => {
return {
graphQLTransformer: [
{
name: 'transformerVersion',
name: 'customTransformerVersion',
type: 'number',
defaultValueForExistingProjects: 4,
defaultValueForNewProjects: 5,
Expand Down Expand Up @@ -533,7 +533,7 @@ describe('feature flags', () => {

test('error with empty field returns unknown', () => {
expect(() => {
throw new EnvVarFormatError((undefined as unknown) as string);
throw new EnvVarFormatError(undefined as unknown as string);
}).toThrowError(`Invalid variable name format: '<unknown>'`);
});

Expand Down Expand Up @@ -594,13 +594,13 @@ describe('feature flags', () => {
expect(features).toMatchObject({
project: {
graphqltransformer: {
transformerversion: 5,
customtransformerversion: 5,
},
},
environments: {
dev: {
graphqltransformer: {
transformerversion: 6,
customtransformerversion: 6,
},
},
},
Expand All @@ -626,7 +626,7 @@ describe('feature flags', () => {
expect(features).toMatchObject({
project: {
graphqltransformer: {
transformerversion: 5,
customtransformerversion: 5,
},
},
environments: {},
Expand Down Expand Up @@ -676,7 +676,7 @@ describe('feature flags', () => {
environments: {
dev: {
graphqltransformer: {
transformerversion: 6,
customtransformerversion: 6,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
},
"features": {
"graphQLTransformer": {
"transformerVersion": 5
"customTransformerVersion": 5
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"features": {
"graphQLTransformer": {
"transformerVersion": 6
"customTransformerVersion": 6
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
},
"features": {
"graphQLTransformer": {
"transformerVersion": 5
"customTransformerVersion": 5
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
},
"features": {
"graphQLTransformer": {
"transformerVersion": 3
"customTransformerVersion": 3
},
"keyTransformer": {
"defaultQuery": false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"features": {
"graphQLTransformer": {
"transformerVersion": 10
"customTransformerVersion": 10
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"features": {
"graphQLTransformer": {
"transformerVersion": 4
"customTransformerVersion": 4
},
"keyTransformer": {
"defaultQuery": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
},
"features": {
"graphQLTransformer": {
"transformerVersion": 3
"customTransformerVersion": 3
},
"keyTransformer": {
"defaultQuery": false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"features": {
"graphQLTransformer": {
"transformerVersion": 10
"customTransformerVersion": 10
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AMPLIFYCLI_GRAPHQLTRANSFORMER__TRANSFORMERVERSION=5
#AMPLIFYCLI-DEV_GRAPHQLTRANSFORMER__TRANSFORMERVERSION=6
AMPLIFYCLI_GRAPHQLTRANSFORMER__CUSTOMTRANSFORMERVERSION=5
#AMPLIFYCLI-DEV_GRAPHQLTRANSFORMER__CUSTOMTRANSFORMERVERSION=6
AMPLIFYCLI_KEYTRANSFORMER__defaultquery=false
#AMPLIFYCLI-DEV_KEYTRANSFORMER__defaultquery=true
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"features": {
"graphQLTransformer": {
"transformerVersion": 4
"customTransformerVersion": 4
},
"keyTransformer": {
"defaultQuery": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
},
"features": {
"graphQLTransformer": {
"transformerVersion": 3
"customTransformerVersion": 3
},
"keyTransformer": {
"defaultQuery": false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"features": {
"graphQLTransformer": {
"transformerVersion": 10
"customTransformerVersion": 10
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AMPLIFYCLI_GRAPHQLTRANSFORMER__TRANSFORMERVERSION=5
AMPLIFYCLI-DEV_GRAPHQLTRANSFORMER__TRANSFORMERVERSION=6
AMPLIFYCLI_GRAPHQLTRANSFORMER__CUSTOMTRANSFORMERVERSION=5
AMPLIFYCLI-DEV_GRAPHQLTRANSFORMER__CUSTOMTRANSFORMERVERSION=6
AMPLIFYCLI_KEYTRANSFORMER__defaultquery=false
AMPLIFYCLI-DEV_KEYTRANSFORMER__defaultquery=true
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"features": {
"graphQLTransformer": {
"transformerVersion": 4
"customTransformerVersion": 4
},
"keyTransformer": {
"defaultQuery": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
},
"features": {
"graphQLTransformer": {
"transformerVersion": 3
"customTransformerVersion": 3
},
"keyTransformer": {
"defaultQuery": false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"features": {
"graphQLTransformer": {
"transformerVersion": 10
"customTransformerVersion": 10
}
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
AMPLIFYCLI_GRAPHQLTRANSFORMER__TRANSFORMERVERSION=invalid
AMPLIFYCLI_GRAPHQLTRANSFORMER__CUSTOMTRANSFORMERVERSION=invalid
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
},
"features": {
"graphQLTransformer": {
"transformerVersion": "it-is-a-string",
"customTransformerVersion": "it-is-a-string",
"foo": "unknown",
"bar": "unknown"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#AMPLIFYCLI_GRAPHQLTRANSFORMER__TRANSFORMERVERSION=5
#AMPLIFYCLI-DEV_GRAPHQLTRANSFORMER__TRANSFORMERVERSION=6
#AMPLIFYCLI_GRAPHQLTRANSFORMER__CUSTOMTRANSFORMERVERSION=5
#AMPLIFYCLI-DEV_GRAPHQLTRANSFORMER__CUSTOMTRANSFORMERVERSION=6
#AMPLIFYCLI_KEYTRANSFORMER__defaultquery=false
#AMPLIFYCLI-DEV_KEYTRANSFORMER__defaultquery=true
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"features": {
"graphQLTransformer": {
"transformerVersion": 4
"customTransformerVersion": 4
},
"keyTransformer": {
"defaultQuery": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
},
"features": {
"graphQLTransformer": {
"transformerVersion": 3
"customTransformerVersion": 3
},
"keyTransformer": {
"defaultQuery": false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"features": {
"graphQLTransformer": {
"transformerVersion": 10
"customTransformerVersion": 10
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
},
"features": {
"graphQLTransformer": {
"transformerVersion": 5
"customTransformerVersion": 5
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"features": {
"graphQLTransformer": {
"transformerVersion": 6
"customTransformerVersion": 6
}
}
}
6 changes: 6 additions & 0 deletions packages/amplify-cli-core/src/feature-flags/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,12 @@ export class FeatureFlags {
defaultValueForExistingProjects: false,
defaultValueForNewProjects: true,
},
{
name: 'transformerVersion',
type: 'number',
defaultValueForExistingProjects: 1,
defaultValueForNewProjects: 1,
},
]);

this.registerFlag('frontend-ios', [
Expand Down
Loading

0 comments on commit a7ad372

Please sign in to comment.