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

feat(api): specify include or exclude tables option to generate schema #1824

Conversation

sundersc
Copy link
Contributor

Description of changes

Include/Exclude Option

  • Customers can specify in the input AMPLIFY to exclude or only include certain tables from being re-generated.
  • Customers can not have "include" and "exclude" statements at the same time. they are mutually exclusive.

Example:

input AMPLIFY {
   exclude: [String] = ["todos", "hello"]
}

or

input AMPLIFY {
   include: [String] = ["todos", "hello"]
}

This change also includes preserving customer added relational fields on schema regeneration.

CDK / CloudFormation Parameters Changed

NA

Issue #, if available

NA

Description of how you validated changes

  • Manual test
  • New unit tests
  • New E2E test

Checklist

  • PR description included
  • yarn test passes
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)
  • New AWS SDK calls or CloudFormation actions have been added to relevant test and service IAM policies
  • Any CDK or CloudFormation parameter changes are called out explicitly

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

@sundersc sundersc requested a review from a team as a code owner August 24, 2023 21:24
Comment on lines 40 to 42
if (!existingDocument) {
return document;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This check shouldn't be required, since you don't specify as optional, and also explicitly already check this in the caller.

newObjectWrapper.fields.push(new FieldWrapper(relationalField));
});

if (relationalFields.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This branch creates a potentially bizarre modal behavior. If I'm reading this right if I go make changes to my Model after import, then upon the next import those changes are scrubbed, but if those changes ALSO include a relational update then those changes are maintained (not just the relationship).

Is that the desired behavior, or should we be doing the merge one layer deeper (e.g. only maintain relational fields in the colliding models?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That a great question. This logic copies only the relationship. newObject is the regenerated GraphQL type and existingObject is the current state of the GraphQL type from schema.rds.graphql file. We only copy the relational fields from existing type to the new type in this method (line 56-58).

I'm adding a test specific to this scenario.

However, I had other concerns that I will review with Rene and address in a follow up if required.

  • What if the table belongs to the related type is deleted? Should we still retain the relationship?
  • What if one of the references fields removed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it - thank you for explaining. I missed that on my first read, but makes sense after reviewing.

newObjectWrapper.fields.push(new FieldWrapper(relationalField));
});

if (relationalFields.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Got it - thank you for explaining. I missed that on my first read, but makes sense after reviewing.


export const applySchemaOverrides = (document: DocumentNode, existingDocument?: DocumentNode | undefined): DocumentNode => {
if (!existingDocument) {
return document;
}

let updatedDocument = preserveRelationalDirectives(document, existingDocument) as any;
Copy link
Contributor

Choose a reason for hiding this comment

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

One alternative here is to extend the schema visitor pattern we use for FieldDefinition to ObjectTypeDefinition as well, this could save us from multiple mutations of updatedDocument. Non-blocking suggestion.

@sundersc sundersc merged commit 5fe85d3 into aws-amplify:feature/rds-support-preview2 Aug 25, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants