Skip to content

Commit

Permalink
fix: change model type to any if no graphql types (#1086)
Browse files Browse the repository at this point in the history
Co-authored-by: Justin Shih <jushih@amazon.com>
  • Loading branch information
Jshhhh and Justin Shih committed Aug 22, 2023
1 parent f62567e commit 4cc0755
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10235,6 +10235,26 @@ export default function CustomButton(
"
`;

exports[`amplify render tests renderer configurations with NoApi should render component without graphql types 1`] = `
"import * as React from \\"react\\";
import { EscapeHatchProps } from \\"@aws-amplify/ui-react/internal\\";
import { ButtonProps } from \\"@aws-amplify/ui-react\\";
export declare type PrimitiveOverrideProps<T> = Partial<T> & React.DOMAttributes<HTMLDivElement>;
export declare type ComponentWithDataBindingOverridesProps = {
ComponentWithDataBinding?: PrimitiveOverrideProps<ButtonProps>;
} & EscapeHatchProps;
export declare type ComponentWithDataBindingProps = React.PropsWithChildren<Partial<ButtonProps> & {
width?: Number;
isDisabled?: Boolean;
buttonUser?: any;
buttonColor?: String;
} & {
overrides?: ComponentWithDataBindingOverridesProps | undefined | null;
}>;
export default function ComponentWithDataBinding(props: ComponentWithDataBindingProps): React.ReactElement;
"
`;

exports[`amplify render tests sample code snippet tests should generate a sample code snippet for components 1`] = `
"/* eslint-disable */
import * as React from \\"react\\";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,24 @@ describe('amplify render tests', () => {
const generatedCode = generateWithAmplifyRenderer('buttonGolden', rendererConfigWithNoApi);
expect(generatedCode.componentText).toMatchSnapshot();
});

it('should render component without graphql types', () => {
const generatedCode = generateWithAmplifyRenderer('componentWithDataBinding', {
apiConfiguration: {
dataApi: 'GraphQL',
typesFilePath: '',
fragmentsFilePath: '../graphql/fragments',
mutationsFilePath: '../graphql/mutations',
queriesFilePath: '../graphql/queries',
subscriptionsFilePath: '../graphql/subscriptions',
},
module: ModuleKind.ES2020,
target: ScriptTarget.ES2020,
script: ScriptKind.JSX,
renderTypeDeclarations: true,
});
expect(generatedCode.declaration).toMatchSnapshot();
});
});

describe('collection', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ import {
buildArrowFunctionStatement,
} from './helpers';
import { addUseEffectWrapper } from './utils/generate-react-hooks';
import { ActionType, getGraphqlCallExpression, getGraphqlQueryForModel } from './utils/graphql';
import { ActionType, getGraphqlCallExpression, getGraphqlQueryForModel, isGraphqlConfig } from './utils/graphql';

export abstract class ReactStudioTemplateRenderer extends StudioTemplateRenderer<
string,
Expand Down Expand Up @@ -558,7 +558,11 @@ export abstract class ReactStudioTemplateRenderer extends StudioTemplateRenderer
);
propSignatures.push(propSignature);
} else if (isDataPropertyBinding(binding)) {
const modelName = this.importCollection.getMappedModelAlias(binding.bindingProperties.model);
let modelName = this.importCollection.getMappedModelAlias(binding.bindingProperties.model);
const apiConfig = this.renderConfig.apiConfiguration;
if (isGraphqlConfig(apiConfig) && !apiConfig.typesFilePath) {
modelName = 'any';
}
const propSignature = factory.createPropertySignature(
undefined,
propName,
Expand Down

0 comments on commit 4cc0755

Please sign in to comment.