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

refactor: move directive definitions to a single source of truth #2342

Merged
merged 22 commits into from
Mar 27, 2024

Conversation

dpilch
Copy link
Member

@dpilch dpilch commented Mar 13, 2024

Description of changes

Move directive definitions to a single source of truth. Transform logic will still be contained in the transformers. This change will allow codegen to depend the @aws-amplify/graphql-directives package and use the definitions as the default definitions of model generation.

PR to use new package in codegen: aws-amplify/amplify-codegen#796

CDK / CloudFormation Parameters Changed

N/A

Issue #, if available

N/A

Description of how you validated changes

  • Unit tests
  • E2E tests

Checklist

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

@dpilch dpilch force-pushed the directive-definitions branch from 40e9298 to 13383ed Compare March 13, 2024 20:24
@dpilch dpilch changed the title Directive definitions refactor: move directive definitions to a single source of truth Mar 13, 2024
@dpilch dpilch force-pushed the directive-definitions branch from 43b57f5 to 282c07d Compare March 13, 2024 22:59
@@ -64,7 +64,7 @@ export interface AuthDirective {
}

// @public (undocumented)
export const authDirectiveDefinition = "\n directive @auth(rules: [AuthRule!]!) on OBJECT | FIELD_DEFINITION\n input AuthRule {\n allow: AuthStrategy!\n provider: AuthProvider\n identityClaim: String\n groupClaim: String\n ownerField: String\n groupsField: String\n groups: [String]\n operations: [ModelOperation]\n }\n enum AuthStrategy {\n owner\n groups\n private\n public\n custom\n }\n enum AuthProvider {\n apiKey\n iam\n oidc\n userPools\n function\n }\n enum ModelOperation {\n create\n update\n delete\n read\n list\n get\n sync\n listen\n search\n }\n";
export const authDirectiveDefinition: string;
Copy link
Member Author

Choose a reason for hiding this comment

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

The type is changing to string here, but the value is still the same.

@dpilch dpilch force-pushed the directive-definitions branch from 6b9c874 to e9b7109 Compare March 19, 2024 16:47
@dpilch dpilch force-pushed the directive-definitions branch from 75613ac to 04d2aa7 Compare March 19, 2024 17:47
@dpilch dpilch force-pushed the directive-definitions branch from 943ea0c to 4d9b06c Compare March 19, 2024 19:24
@dpilch dpilch marked this pull request as ready for review March 19, 2024 21:08
@dpilch dpilch requested review from a team as code owners March 19, 2024 21:08
atierian
atierian previously approved these changes Mar 22, 2024
# Allows transformer libraries to deprecate directive arguments.
directive @deprecated(reason: String) on FIELD_DEFINITION | INPUT_FIELD_DEFINITION | ENUM | ENUM_VALUE
`);
export const EXTRA_DIRECTIVES_DOCUMENT = parse(
Copy link
Member

Choose a reason for hiding this comment

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

Good find! I didn't see this when I was looking for definitions!

@@ -61,6 +61,7 @@ export const constructTransformerChain = (options?: TransformerFactoryArgs): Tra
const indexTransformer = new IndexTransformer();
const hasOneTransformer = new HasOneTransformer();

// The default list of transformers should match DefaultDirectives in packages/amplify-graphql-directives/src/index.ts
Copy link
Member

Choose a reason for hiding this comment

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

I know what you're getting at, but this list doesn't match because we don't have transformers for the AppSync directives. A couple of things I can think of:

  1. Create new structures to house AppSync directives and Amplify directives, and compose DefaultDirectives from it and the list of Amplify directives
  2. Include the list of supported AppSync directives in a comment so at least the number of directive definitions matches the number of transformer definitions

I slightly favor 1, but not enough to fight about it since we don't yet have any validation beyond somebody eyeballing it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I implemented option 1.

@dpilch dpilch force-pushed the directive-definitions branch from 5be7b90 to d9a2b41 Compare March 26, 2024 15:11
@dpilch dpilch merged commit 3346677 into main Mar 27, 2024
7 checks passed
@dpilch dpilch deleted the directive-definitions branch March 27, 2024 16:18
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