-
Notifications
You must be signed in to change notification settings - Fork 825
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): merge user config with tran…
…sform generated resolvers
- Loading branch information
1 parent
b122947
commit ace39d5
Showing
5 changed files
with
133 additions
and
2 deletions.
There are no files selected for viewing
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
46 changes: 46 additions & 0 deletions
46
packages/amplify-e2e-tests/src/__tests__/resolvers.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,46 @@ | ||
import { | ||
initJSProjectWithProfile, | ||
deleteProject, | ||
createNewProjectDir, | ||
deleteProjectDir, | ||
addFeatureFlag, | ||
addApiWithSchema, | ||
amplifyPush, | ||
addCustomResolver, | ||
apiGqlCompile, | ||
} from 'amplify-e2e-core'; | ||
import { join } from 'path'; | ||
import * as fs from 'fs-extra'; | ||
|
||
describe('overriding generated resolvers', () => { | ||
let projectDir: string; | ||
let apiName = 'simpleapi'; | ||
|
||
beforeAll(async () => { | ||
projectDir = await createNewProjectDir('overrideresolvers'); | ||
await initJSProjectWithProfile(projectDir, {}); | ||
|
||
addFeatureFlag(projectDir, 'graphqltransformer', 'useexperimentalpipelinedtransformer', true); | ||
}); | ||
|
||
afterAll(async () => { | ||
await deleteProject(projectDir); | ||
deleteProjectDir(projectDir); | ||
}); | ||
|
||
it('adds the overwritten resolver to the build', async () => { | ||
const resolverName = 'Query.listTodos.req.vtl'; | ||
const resolver = '$util.unauthorized()'; | ||
const generatedResolverPath = join(projectDir, 'amplify', 'backend', 'api', apiName, 'build', 'pipelineFunctions', resolverName); | ||
|
||
await addApiWithSchema(projectDir, 'simple_model.graphql'); | ||
await apiGqlCompile(projectDir, true); | ||
|
||
expect(fs.readFileSync(generatedResolverPath)).not.toContain(resolver); | ||
|
||
addCustomResolver(projectDir, apiName, resolverName, resolver); | ||
await apiGqlCompile(projectDir, true); | ||
|
||
expect(fs.readFileSync(generatedResolverPath)).toEqual(resolver); | ||
}); | ||
}); |
63 changes: 63 additions & 0 deletions
63
packages/amplify-provider-awscloudformation/src/__tests__/graphql-transformer/utils.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,63 @@ | ||
import { mergeUserConfigWithTransformOutput } from '../../graphql-transformer/utils'; | ||
import { TransformerProjectConfig, DeploymentResources } from '@aws-amplify/graphql-transformer-core'; | ||
|
||
describe('mergeUserConfigWithTransformOutput', () => { | ||
let userConfig; | ||
let transformerOutput; | ||
|
||
beforeAll(() => { | ||
transformerOutput = { | ||
resolvers: {}, | ||
pipelineFunctions: { | ||
'Query.listTodos.req.vtl': '## [Start] List Request. **\n' + '#set( $limit = $util.defaultIfNull($context.args.limit, 100) )\n', | ||
}, | ||
functions: {}, | ||
schema: '', | ||
stackMapping: {}, | ||
stacks: {}, | ||
rootStack: null, | ||
} as DeploymentResources; | ||
}); | ||
|
||
describe('has user-created resolvers', () => { | ||
beforeAll(() => { | ||
userConfig = { | ||
schema: '', | ||
functions: {}, | ||
pipelineFunctions: {}, | ||
resolvers: { | ||
'Query.listTodos.req.vtl': '$util.unauthorized\n', | ||
}, | ||
stacks: {}, | ||
config: { Version: 5, ElasticsearchWarning: true }, | ||
} as TransformerProjectConfig; | ||
}); | ||
|
||
it('merges the custom resolver with transformer output', () => { | ||
const output = mergeUserConfigWithTransformOutput(userConfig, transformerOutput); | ||
|
||
expect(output.pipelineFunctions['Query.listTodos.req.vtl']).toEqual('$util.unauthorized\n'); | ||
}); | ||
}); | ||
|
||
describe('has user created pipeline function', () => { | ||
beforeAll(() => { | ||
userConfig = { | ||
schema: '', | ||
functions: {}, | ||
pipelineFunctions: { | ||
'Query.listTodos.req.vtl': '$util.unauthorized\n', | ||
}, | ||
resolvers: {}, | ||
stacks: {}, | ||
config: { Version: 5, ElasticsearchWarning: true }, | ||
} as TransformerProjectConfig; | ||
}); | ||
|
||
it('merges custom pipeline function with transformer output', () => { | ||
const output = mergeUserConfigWithTransformOutput(userConfig, transformerOutput); | ||
|
||
expect(output.pipelineFunctions['Query.listTodos.req.vtl']).toEqual('$util.unauthorized\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
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