Skip to content

Commit

Permalink
feat: Activate graphql migrator behind feature flag
Browse files Browse the repository at this point in the history
* Feat: Activate graphql migrator behind feature flag

* Put migrator in awscloudformation package.json

* Fix tsconfig for migrator
  • Loading branch information
marcvberg committed Nov 3, 2021
1 parent 0af6139 commit 5a76b3a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
6 changes: 6 additions & 0 deletions packages/amplify-cli-core/src/feature-flags/featureFlags.ts
Expand Up @@ -557,6 +557,12 @@ export class FeatureFlags {
defaultValueForExistingProjects: 1,
defaultValueForNewProjects: 1,
},
{
name: 'suppressSchemaMigrationPrompt',
type: 'boolean',
defaultValueForExistingProjects: false,
defaultValueForNewProjects: false
},
]);

this.registerFlag('frontend-ios', [
Expand Down
9 changes: 1 addition & 8 deletions packages/amplify-graphql-transformer-migrator/tsconfig.json
Expand Up @@ -2,14 +2,7 @@
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"allowJs": true,
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"isolatedModules": true,
"jsx": "react-jsx"
"outDir": "lib"
},
"references": [
{
Expand Down
1 change: 1 addition & 0 deletions packages/amplify-provider-awscloudformation/package.json
Expand Up @@ -35,6 +35,7 @@
"@aws-amplify/graphql-searchable-transformer": "0.6.3",
"@aws-amplify/graphql-transformer-core": "0.9.2",
"@aws-amplify/graphql-transformer-interfaces": "1.10.0",
"@aws-amplify/graphql-transformer-migrator": "0.1.0",
"@aws-cdk/assets": "~1.124.0",
"@aws-cdk/aws-apigatewayv2": "~1.124.0",
"@aws-cdk/aws-autoscaling": "~1.124.0",
Expand Down
Expand Up @@ -45,6 +45,7 @@ import {
transformGraphQLSchema as transformGraphQLSchemaV6,
getDirectiveDefinitions as getDirectiveDefinitionsV6,
} from './graphql-transformer/transform-graphql-schema';
import { attemptV2TransformerMigration } from '@aws-amplify/graphql-transformer-migrator';

const apiCategory = 'api';
const storageCategory = 'storage';
Expand Down Expand Up @@ -314,10 +315,8 @@ async function migrateProject(context, options) {
}

export async function transformGraphQLSchema(context, options) {
const suppressSchemaMigrationPrompt = FeatureFlags.getBoolean('graphQLTransformer.suppressSchemaMigrationPrompt');
const transformerVersion = getTransformerVersion(context);
if (transformerVersion === 2) {
return transformGraphQLSchemaV6(context, options);
}
const backEndDir = context.amplify.pathManager.getBackendDirPath();
const flags = context.parameters.options;
if (flags['no-gql-override']) {
Expand Down Expand Up @@ -390,6 +389,15 @@ export async function transformGraphQLSchema(context, options) {
}
}

// This section applies to migrating schemas from V1 to V2 format
let migratedResult = false;
if (transformerVersion === 2 && !suppressSchemaMigrationPrompt) {
migratedResult = await attemptV2TransformerMigration(resourceDir, parameters[ResourceConstants.PARAMETERS.AppSyncApiName], context);
}
if (migratedResult || transformerVersion === 2) {
return transformGraphQLSchemaV6(context, options);
}

const isCLIMigration = options.migrate;
const isOldApiVersion = apiProjectIsFromOldVersion(previouslyDeployedBackendDir, resourcesToBeCreated);
const migrateOptions = {
Expand Down
3 changes: 2 additions & 1 deletion packages/amplify-provider-awscloudformation/tsconfig.json
Expand Up @@ -26,7 +26,8 @@
{"path": "../graphql-predictions-transformer"},
{"path": "../graphql-transformer-core"},
{"path": "../graphql-versioned-transformer"},
{ "path": "../amplify-graphql-transformer-core" },
{ "path": "../amplify-graphql-transformer-interfaces" },
{ "path": "../amplify-graphql-transformer-core" }
{ "path": "../amplify-graphql-transformer-migrator" }
]
}

0 comments on commit 5a76b3a

Please sign in to comment.