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 union types for code-first approach #10025

Merged
merged 20 commits into from
Sep 8, 2020

Conversation

BryanPan342
Copy link
Contributor

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

Desired GraphQL Union Type
union Search = Human | Droid | Starship

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

CDK Code
const human = new appsync.ObjectType('Human', { definition: {} });
const droid = new appsync.ObjectType('Droid', { definition: {} });
const starship = new appsync.ObjectType('Starship', { definition: {} });
const search = new appsync.UnionType('Search', {
  definition: [ human, droid, starship ],
}); 
api.addType(search);

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

@BryanPan342 BryanPan342 self-assigned this Aug 27, 2020
@BryanPan342 BryanPan342 added the @aws-cdk/aws-appsync Related to AWS AppSync label Aug 27, 2020
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Aug 27, 2020
Copy link
Contributor

@shivlaks shivlaks left a comment

Choose a reason for hiding this comment

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

nice work! some minor suggestions to take a look at before we can merge this one.

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
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
Comment on lines +6 to +14
const out = 'type Test1 {\n test1: String\n}\ntype Test2 {\n test2: String\n}\nunion UnionTest = Test1 | Test2\n';
const test1 = new appsync.ObjectType('Test1', {
definition: { test1: t.string },
});
const test2 = new appsync.ObjectType('Test2', {
definition: { test2: t.string },
});
let stack: cdk.Stack;
let api: appsync.GraphqlApi;
Copy link
Contributor

Choose a reason for hiding this comment

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

why not put all of this into a beforeAll() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is there a difference between giving it global scope and using beforeAll()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://stackoverflow.com/questions/47913168/in-jest-are-defining-global-variables-the-same-as-if-they-are-defined-in-before

since i dont have any asynchronous code before the testing I think it's okay to put it in global scope. wdyt?

@BryanPan342 BryanPan342 requested a review from shivlaks September 8, 2020 20:50
@mergify
Copy link
Contributor

mergify bot commented Sep 8, 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: 296fabf
  • 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 8, 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 28a9834 into aws:master Sep 8, 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.

3 participants