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: un-require required input fields with @default #2867

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

p5quared
Copy link
Member

@p5quared p5quared commented Sep 11, 2024

Description of changes

Un-require required input fields that have @default applied. Also update the corresponding snapshot to document this behavior.

Prior to this change, a copy of the input object was being modified but ctx.output was not being updated with the new input.

CDK / CloudFormation Parameters Changed

n/a

Issue #, if available

aws-amplify/amplify-codegen#390

Description of how you validated changes

Fixed a test snapshot and passed it.

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@p5quared p5quared added the bug Something isn't working label Sep 11, 2024
@p5quared p5quared requested a review from a team as a code owner September 11, 2024 20:39
@p5quared p5quared force-pushed the default-transformer-unrequire branch 2 times, most recently from 0d93765 to cbc28fd Compare September 12, 2024 17:02
const isPrimaryKeyField =
field.directives!.find((dir) => dir.name.value === 'primaryKey') ||
(getBaseType(field.type) === 'ID' && field.type.kind === Kind.NON_NULL_TYPE && field.name.value === 'id');

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one more case to consider here which is when the @default is applied to fields part of a composite primary key. Gen2 doc or this Gen1 doc is more explicit about the schema with composite primary key.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a separate check scanning over sortKeyFields.


const validateNotCompositeKeyMember = (config: DefaultValueDirectiveConfiguration): void => {
const objectDirectives = config.object.fields?.flatMap((f) => f.directives);
const primaryKeyDirective = objectDirectives?.find((dir) => dir?.name.value === 'primaryKey');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we refactor this check to see if the field is a primary key into it's own method that can be re-used between this method and the one above?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants