Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(amplify-provider-awscloudformation): change sandbox mode syntax …
…in schema (#8592)
- Loading branch information
1 parent
e3a2afb
commit a3bdd44
Showing
11 changed files
with
219 additions
and
95 deletions.
There are no files selected for viewing
19 changes: 4 additions & 15 deletions
19
...gory-api/src/__tests__/provider-utils/awscloudformation/utils/global-sandbox-mode.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,10 @@ | ||
import { defineGlobalSandboxMode } from '../../../../provider-utils/awscloudformation/utils/global-sandbox-mode'; | ||
import { $TSContext } from 'amplify-cli-core'; | ||
|
||
describe('global sandbox mode GraphQL directive', () => { | ||
it('returns AMPLIFY_DIRECTIVE type with code comment, directive, and env name', () => { | ||
const envName = 'envone'; | ||
const ctx = <$TSContext>{ | ||
amplify: { | ||
getEnvInfo() { | ||
return { envName }; | ||
}, | ||
}, | ||
}; | ||
|
||
expect(defineGlobalSandboxMode(ctx)) | ||
.toBe(`# This allows public create, read, update, and delete access for a limited time to all models via API Key. | ||
# To configure PRODUCTION-READY authorization rules, review: https://docs.amplify.aws/cli/graphql-transformer/auth | ||
type AMPLIFY_GLOBAL @allow_public_data_access_with_api_key(in: \"${envName}\") # FOR TESTING ONLY!\n | ||
it('returns input AMPLIFY with code comment', () => { | ||
expect(defineGlobalSandboxMode()).toEqual(`# This "input" configures a global authorization rule to enable public access to | ||
# all models in this schema. Learn more about authorization rules here: https://docs.amplify.aws/cli/graphql-transformer/auth | ||
input AMPLIFY { global_auth_rule: AuthorizationRule = { allow: public } } # FOR TESTING ONLY!\n | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 4 additions & 8 deletions
12
...es/amplify-category-api/src/provider-utils/awscloudformation/utils/global-sandbox-mode.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,6 @@ | ||
import { $TSContext } from 'amplify-cli-core'; | ||
|
||
export function defineGlobalSandboxMode(context: $TSContext): string { | ||
const envName = context.amplify.getEnvInfo().envName; | ||
|
||
return `# This allows public create, read, update, and delete access for a limited time to all models via API Key. | ||
# To configure PRODUCTION-READY authorization rules, review: https://docs.amplify.aws/cli/graphql-transformer/auth | ||
type AMPLIFY_GLOBAL @allow_public_data_access_with_api_key(in: \"${envName}\") # FOR TESTING ONLY!\n | ||
export function defineGlobalSandboxMode(): string { | ||
return `# This "input" configures a global authorization rule to enable public access to | ||
# all models in this schema. Learn more about authorization rules here: https://docs.amplify.aws/cli/graphql-transformer/auth | ||
input AMPLIFY { global_auth_rule: AuthorizationRule = { allow: public } } # FOR TESTING ONLY!\n | ||
`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
packages/amplify-e2e-tests/schemas/model_with_sandbox_mode.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/amplify-e2e-tests/src/__tests__/global_sandbox.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { | ||
initJSProjectWithProfile, | ||
deleteProject, | ||
addFeatureFlag, | ||
addApiWithoutSchema, | ||
addApiWithOneModel, | ||
addApiWithThreeModels, | ||
updateApiSchema, | ||
apiGqlCompile, | ||
amplifyPush, | ||
} from 'amplify-e2e-core'; | ||
import { createNewProjectDir, deleteProjectDir } from 'amplify-e2e-core'; | ||
|
||
describe('global sandbox mode', () => { | ||
let projectDir: string; | ||
let apiName = 'sandbox'; | ||
|
||
beforeEach(async () => { | ||
projectDir = await createNewProjectDir('sandbox'); | ||
await initJSProjectWithProfile(projectDir); | ||
addFeatureFlag(projectDir, 'graphqltransformer', 'useexperimentalpipelinedtransformer', true); | ||
}); | ||
|
||
afterEach(async () => { | ||
await deleteProject(projectDir); | ||
deleteProjectDir(projectDir); | ||
}); | ||
|
||
it('compiles schema with one model and pushes to cloud', async () => { | ||
await addApiWithOneModel(projectDir); | ||
await apiGqlCompile(projectDir, true); | ||
await amplifyPush(projectDir, true); | ||
}); | ||
|
||
it.skip('compiles schema with three models and pushes to cloud', async () => { | ||
await addApiWithThreeModels(projectDir); | ||
await apiGqlCompile(projectDir, true); | ||
await amplifyPush(projectDir, true); | ||
}); | ||
|
||
it('compiles schema user-added schema and pushes to cloud', async () => { | ||
await addApiWithoutSchema(projectDir, { apiName }); | ||
updateApiSchema(projectDir, apiName, 'model_with_sandbox_mode.graphql'); | ||
await apiGqlCompile(projectDir, true); | ||
await amplifyPush(projectDir, true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.