Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sub "_" with hash in resource logical ID in transformer v2 #8600

Merged
merged 4 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/amplify-graphql-transformer-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"clean": "rimraf ./lib"
"clean": "rimraf ./lib",
"test": "jest"
},
"dependencies": {
"@aws-amplify/graphql-transformer-interfaces": "1.10.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { DefaultTransformHost } from '../transform-host';
import { GraphQLApi, TransformerAPIProps } from '../graphql-api';
import { App } from '@aws-cdk/core';
import { InlineTemplate } from '../cdk-compat/template-asset';
import { TransformerRootStack } from '../cdk-compat/root-stack';

describe('addResolver', () => {
const app = new App();
const stack = new TransformerRootStack(app, 'test-root-stack');
const transformHost = new DefaultTransformHost({ api: new GraphQLApi(stack, 'testId', { name: 'testApiName' }) });

it('generates resolver name with hash for non-alphanumeric type names', () => {
const cfnResolver = transformHost.addResolver(
'test_type',
'testField',
new InlineTemplate('testTemplate'),
new InlineTemplate('testTemplate'),
undefined,
['testPipelineConfig'],
stack,
);
expect(cfnResolver.logicalId).toMatch('testtype4c79TestFieldResolver.LogicalID'); // have to use match instead of equals because the logicalId is a CDK token that has some non-deterministic stuff in it
});

it('generates resolver name with hash for non-alphanumeric field names', () => {
const cfnResolver = transformHost.addResolver(
'testType',
'test_field',
new InlineTemplate('testTemplate'),
new InlineTemplate('testTemplate'),
undefined,
['testPipelineConfig'],
stack,
);
expect(cfnResolver.logicalId).toMatch('testTypeTestfield6a0fResolver.LogicalID'); // have to use match instead of equals because the logicalId is a CDK token that has some non-deterministic stuff in it
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { CfnFunction, Code, Function, IFunction, ILayerVersion, Runtime } from '
import { AppSyncFunctionConfiguration } from './appsync-function';
import { IRole } from '@aws-cdk/aws-iam';
import { InlineTemplate, S3MappingFunctionCode } from './cdk-compat/template-asset';
import { toCamelCase } from 'graphql-transformer-common';
import { resourceName, toCamelCase } from 'graphql-transformer-common';
import { GraphQLApi } from './graphql-api';

export interface DefaultTransformHostOptions {
Expand Down Expand Up @@ -143,7 +143,8 @@ export class DefaultTransformHost implements TransformHostProvider {

const requestTemplateLocation = requestMappingTemplate.bind(this.api);
const responseTemplateLocation = responseMappingTemplate.bind(this.api);
const resolverName = toCamelCase([typeName, fieldName, 'Resolver']);
const resolverName = toCamelCase([resourceName(typeName), resourceName(fieldName), 'Resolver']);

if (dataSourceName) {
const dataSource = this.dataSources.get(dataSourceName);

Expand Down