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(appsync): support enumeration types for code-first approach #10023

Merged
merged 39 commits into from Sep 11, 2020

Conversation

BryanPan342
Copy link
Contributor

@BryanPan342 BryanPan342 commented Aug 27, 2020

Support Enum Types for code-first approach. Enum Types are special types of Intermediate Types in CDK.

Desired GraphQL Enum
enum Episode {
  NEWHOPE
  EMPIRE
  JEDI
}

The above GraphQL Enumeration Type can be expressed in CDK as the following:

CDK Code
const episode = new appsync.EnumType('Episode', {
  definition: [
    'NEWHOPE',
    'EMPIRE',
    'JEDI',
  ],
}); 
api.addType(episode);

Discussion on the addField API can be found here.


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

@BryanPan342 BryanPan342 added the @aws-cdk/aws-appsync Related to AWS AppSync label Aug 27, 2020
@BryanPan342 BryanPan342 self-assigned this Aug 27, 2020
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Aug 27, 2020
packages/@aws-cdk/aws-appsync/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-appsync/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-appsync/README.md Show resolved Hide resolved
packages/@aws-cdk/aws-appsync/lib/schema-intermediate.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-appsync/lib/schema-intermediate.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-appsync/lib/schema-intermediate.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-appsync/lib/schema-intermediate.ts Outdated Show resolved Hide resolved
@BryanPan342 BryanPan342 dismissed shivlaks’s stale review September 3, 2020 16:27

addressed suggestions

@BryanPan342
Copy link
Contributor Author

[NOTE]

A discussion was had offline discussing the addField function in the IIntermediateType interface.

/**
* Add a field to this Intermediate Type
*/
addField(options: AddFieldOptions): void;

Some of the concerns that were brought to light in this PR was that causing a synth error is bad for the user because users could easily get punished for using the a weakly-typed API.

We ultimately decided to continue with the AddFieldOptions struct as an input for addField for a couple of reasons:

  • jsii prevents us from using generics and unions
  • All intermediate types should have a shared interface, having a separate addField for every single Intermediate Type is impractical
  • IIntermediateType must have an addField function to allow for dynamic schema generation
    • the addType function returns IIntermediateType
    • IntermediateTypes instantiated through the addType would be unable to addField if the function didn't exist in the interface
    const type = api.addType(new ObjectType(definition));
    type.addField(fieldName, field);   // this would be impossible if the addField function isn't in `IIntermediateType`

@mergify
Copy link
Contributor

mergify bot commented Sep 11, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: af44256
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Sep 11, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 30a5b80 into aws:master Sep 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-appsync Related to AWS AppSync contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants