From de064acf14764586830c94415b0aeaec8e125193 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Mon, 31 Aug 2020 10:50:49 -0700 Subject: [PATCH 1/9] prelim addition of subscriptions --- .../@aws-cdk/aws-appsync/lib/graphqlapi.ts | 23 ++++++++-- packages/@aws-cdk/aws-appsync/lib/schema.ts | 31 +++++++++++-- .../aws-appsync/test/appsync-schema.test.ts | 45 +++++++++++++++++++ .../test/integ.graphql-schema.expected.json | 2 +- .../aws-appsync/test/integ.graphql-schema.ts | 5 +++ 5 files changed, 97 insertions(+), 9 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts index 4251336f017ea..5732506bab3ba 100644 --- a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts +++ b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts @@ -592,8 +592,8 @@ export class GraphQLApi extends GraphqlApiBase { } /** - * Add a query field to the schema's Query. If one isn't set by - * the user, CDK will create an Object Type called 'Query'. For example, + * Add a query field to the schema's Query. CDK will create an + * Object Type called 'Query'. For example, * * type Query { * fieldName: Field.returnType @@ -607,8 +607,8 @@ export class GraphQLApi extends GraphqlApiBase { } /** - * Add a mutation field to the schema's Mutation. If one isn't set by - * the user, CDK will create an Object Type called 'Mutation'. For example, + * Add a mutation field to the schema's Mutation. CDK will create an + * Object Type called 'Mutation'. For example, * * type Mutation { * fieldName: Field.returnType @@ -620,4 +620,19 @@ export class GraphQLApi extends GraphqlApiBase { public addMutation(fieldName: string, field: ResolvableField): ObjectType { return this.schema.addMutation(fieldName, field); } + + /** + * Add a subscription field to the schema's Subscription. CDK will create an + * Object Type called 'Subscription'. For example, + * + * type Subscription { + * fieldName: Field.returnType + * } + * + * @param fieldName the name of the Subscription + * @param field the resolvable field to for this Subscription + */ + public addSubscription(fieldName: string, field: ResolvableField): ObjectType { + return this.schema.addSubscription(fieldName, field); + } } diff --git a/packages/@aws-cdk/aws-appsync/lib/schema.ts b/packages/@aws-cdk/aws-appsync/lib/schema.ts index f7751f38a3182..d337baabd155d 100644 --- a/packages/@aws-cdk/aws-appsync/lib/schema.ts +++ b/packages/@aws-cdk/aws-appsync/lib/schema.ts @@ -101,8 +101,8 @@ export class Schema { } /** - * Add a query field to the schema's Query. If one isn't set by - * the user, CDK will create an Object Type called 'Query'. For example, + * Add a query field to the schema's Query. CDK will create an + * Object Type called 'Query'. For example, * * type Query { * fieldName: Field.returnType @@ -124,8 +124,8 @@ export class Schema { } /** - * Add a mutation field to the schema's Mutation. If one isn't set by - * the user, CDK will create an Object Type called 'Mutation'. For example, + * Add a mutation field to the schema's Mutation. CDK will create an + * Object Type called 'Mutation'. For example, * * type Mutation { * fieldName: Field.returnType @@ -146,6 +146,29 @@ export class Schema { return this.mutation; } + /** + * Add a subscription field to the schema's Subscription. CDK will create an + * Object Type called 'Subscription'. For example, + * + * type Subscription { + * fieldName: Field.returnType + * } + * + * @param fieldName the name of the Subscription + * @param field the resolvable field to for this Subscription + */ + public addSubscription(fieldName: string, field: ResolvableField): ObjectType { + if (this.mode !== SchemaMode.CODE) { + throw new Error(`Unable to add subscription. Schema definition mode must be ${SchemaMode.CODE} Received: ${this.mode}`); + } + if (!this.subscription) { + this.subscription = new ObjectType('Subscription', { definition: {} }); + this.addType(this.subscription); + } + this.subscription.addField(fieldName, field); + return this.subscription; + } + /** * Add type to the schema * diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts index f60d63f1dec5c..91bb1b5b6e5ba 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts @@ -124,6 +124,38 @@ describe('basic testing schema definition mode `code`', () => { Definition: 'schema {\n mutation: Mutation\n}\ntype Mutation {\n test: String\n}\n', }); }); + + test('definition mode `code` allows for api to addSubscription', () => { + // WHEN + const api = new appsync.GraphQLApi(stack, 'API', { + name: 'demo', + }); + api.addSubscription('test', new appsync.ResolvableField({ + returnType: t.string, + })); + + // THEN + expect(stack).toHaveResourceLike('AWS::AppSync::GraphQLSchema', { + Definition: 'schema {\n subscription: Subscription\n}\ntype Subscription {\n test: String\n}\n', + }); + }); + + test('definition mode `code` allows for schema to addSubscription', () => { + // WHEN + const schema = new appsync.Schema(); + new appsync.GraphQLApi(stack, 'API', { + name: 'demo', + schema, + }); + schema.addSubscription('test', new appsync.ResolvableField({ + returnType: t.string, + })); + + // THEN + expect(stack).toHaveResourceLike('AWS::AppSync::GraphQLSchema', { + Definition: 'schema {\n subscription: Subscription\n}\ntype Subscription {\n test: String\n}\n', + }); + }); }); describe('testing schema definition mode `file`', () => { @@ -209,4 +241,17 @@ describe('testing schema definition mode `file`', () => { api.addMutation('blah', new appsync.ResolvableField({ returnType: t.string })); }).toThrowError('Unable to add mutation. Schema definition mode must be CODE Received: FILE'); }); + + test('definition mode `file` errors when addSubscription is called', () => { + // WHEN + const api = new appsync.GraphQLApi(stack, 'API', { + name: 'demo', + schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), + }); + + // THEN + expect(() => { + api.addSubscription('blah', new appsync.ResolvableField({ returnType: t.string })); + }).toThrowError('Unable to add subscription. Schema definition mode must be CODE Received: FILE'); + }); }); \ No newline at end of file diff --git a/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.expected.json b/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.expected.json index a9ac30ac73a09..27a7eefce492d 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.expected.json +++ b/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.expected.json @@ -16,7 +16,7 @@ "ApiId" ] }, - "Definition": "schema {\n query: Query\n mutation: Mutation\n}\ninterface Node {\n created: String\n edited: String\n id: ID!\n}\ntype Planet {\n name: String\n diameter: Int\n rotationPeriod: Int\n orbitalPeriod: Int\n gravity: String\n population: [String]\n climates: [String]\n terrains: [String]\n surfaceWater: Float\n created: String\n edited: String\n id: ID!\n}\ntype Species implements Node {\n name: String\n classification: String\n designation: String\n averageHeight: Float\n averageLifespan: Int\n eyeColors: [String]\n hairColors: [String]\n skinColors: [String]\n language: String\n homeworld: Planet\n created: String\n edited: String\n id: ID!\n}\ntype Query {\n getPlanets: [Planet]\n}\ntype Mutation {\n addPlanet(name: String diameter: Int rotationPeriod: Int orbitalPeriod: Int gravity: String population: [String] climates: [String] terrains: [String] surfaceWater: Float): Planet\n}\n" + "Definition": "schema {\n query: Query\n mutation: Mutation\n subscription: Subscription\n}\ninterface Node {\n created: String\n edited: String\n id: ID!\n}\ntype Planet {\n name: String\n diameter: Int\n rotationPeriod: Int\n orbitalPeriod: Int\n gravity: String\n population: [String]\n climates: [String]\n terrains: [String]\n surfaceWater: Float\n created: String\n edited: String\n id: ID!\n}\ntype Species implements Node {\n name: String\n classification: String\n designation: String\n averageHeight: Float\n averageLifespan: Int\n eyeColors: [String]\n hairColors: [String]\n skinColors: [String]\n language: String\n homeworld: Planet\n created: String\n edited: String\n id: ID!\n}\ntype Query {\n getPlanets: [Planet]\n}\ntype Mutation {\n addPlanet(name: String diameter: Int rotationPeriod: Int orbitalPeriod: Int gravity: String population: [String] climates: [String] terrains: [String] surfaceWater: Float): Planet\n}\ntype Subscription {\n addedPlanets(id: ID!): Planet\n}\n" } }, "codefirstapiDefaultApiKey89863A80": { diff --git a/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.ts b/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.ts index 8bde313c6f724..568798d5aa35a 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.ts +++ b/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.ts @@ -101,4 +101,9 @@ api.addMutation('addPlanet', new appsync.ResolvableField({ responseMappingTemplate: appsync.MappingTemplate.dynamoDbResultItem(), })); +api.addSubscription('addedPlanets', new appsync.ResolvableField({ + returnType: planet.attribute(), + args: { id: ScalarType.required_id }, +})); + app.synth(); \ No newline at end of file From f3838efeb89033b4263767b83fda33371902fb30 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Mon, 31 Aug 2020 11:15:39 -0700 Subject: [PATCH 2/9] first pass changes to readme --- packages/@aws-cdk/aws-appsync/README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/@aws-cdk/aws-appsync/README.md b/packages/@aws-cdk/aws-appsync/README.md index 104be3e026e12..2038dec7c3e44 100644 --- a/packages/@aws-cdk/aws-appsync/README.md +++ b/packages/@aws-cdk/aws-appsync/README.md @@ -608,3 +608,23 @@ api.addMutation('addFilm', new appsync.ResolvableField({ ``` To learn more about top level operations, check out the docs [here](https://docs.aws.amazon.com/appsync/latest/devguide/graphql-overview.html). + +#### Subscription + +Every schema **can** have a top level Subscription type. The top level `Subscription` Type +is the only exposed type that users can access to invoke a response to a mutation. This means +you can make any data source real time by specificy a GraphQL Schema directive on a mutation. + +**Note**: The AWS AppSync client SDK automatically handles subscription connection management. + +To add fields for these subscriptions, we can simply run the `addSubscription` function to add +to the schema's `Subscription` type. + +```ts +api.addSubscription('addedFilm', new appsync.ResolvableField({ + returnType: film.attribute(), + args: { id: appsync.GraphqlType.id({ isRequired: true }) }, +})); +``` + +To learn more about top level operations, check out the docs [here](https://docs.aws.amazon.com/appsync/latest/devguide/real-time-data.html). From f3c77e35237abb980e50ab300fb39eb72a1f3934 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Mon, 31 Aug 2020 14:56:35 -0700 Subject: [PATCH 3/9] refactor(appsync): graphQLApi to graphqlApi for better snakecasing --- .../@aws-cdk/aws-appsync/lib/graphqlapi.ts | 14 +++--- packages/@aws-cdk/aws-appsync/lib/schema.ts | 4 +- packages/@aws-cdk/aws-appsync/package.json | 3 +- .../aws-appsync/test/appsync-auth.test.ts | 46 +++++++++---------- .../test/appsync-code-first.test.ts | 16 +++---- .../aws-appsync/test/appsync-dynamodb.test.ts | 10 ++-- .../aws-appsync/test/appsync-grant.test.ts | 4 +- .../aws-appsync/test/appsync-http.test.ts | 10 ++-- .../test/appsync-interface-type.test.ts | 4 +- .../aws-appsync/test/appsync-lambda.test.ts | 10 ++-- .../aws-appsync/test/appsync-none.test.ts | 10 ++-- .../test/appsync-object-type.test.ts | 4 +- .../test/appsync-scalar-type.test.ts | 4 +- .../aws-appsync/test/appsync-schema.test.ts | 24 +++++----- .../@aws-cdk/aws-appsync/test/appsync.test.ts | 6 +-- .../aws-appsync/test/integ.api-import.ts | 8 ++-- .../aws-appsync/test/integ.graphql-iam.ts | 8 ++-- .../aws-appsync/test/integ.graphql-schema.ts | 2 +- .../aws-appsync/test/integ.graphql.ts | 4 +- 19 files changed, 95 insertions(+), 96 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts index 4251336f017ea..052e3ecd53392 100644 --- a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts +++ b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts @@ -206,7 +206,7 @@ export interface LogConfig { /** * Properties for an AppSync GraphQL API */ -export interface GraphQLApiProps { +export interface GraphqlApiProps { /** * the name of the GraphQL API */ @@ -293,7 +293,7 @@ export class IamResource { * * @param api The GraphQL API to give permissions */ - public resourceArns(api: GraphQLApi): string[] { + public resourceArns(api: GraphqlApi): string[] { return this.arns.map((arn) => Stack.of(api).formatArn({ service: 'appsync', resource: `apis/${api.apiId}`, @@ -325,7 +325,7 @@ export interface GraphqlApiAttributes { * * @resource AWS::AppSync::GraphQLApi */ -export class GraphQLApi extends GraphqlApiBase { +export class GraphqlApi extends GraphqlApiBase { /** * Import a GraphQL API through this function * @@ -362,9 +362,9 @@ export class GraphQLApi extends GraphqlApiBase { /** * the URL of the endpoint created by AppSync * - * @attribute + * @attribute GraphQlUrl */ - public readonly graphQlUrl: string; + public readonly graphqlUrl: string; /** * the name of the API @@ -387,7 +387,7 @@ export class GraphQLApi extends GraphqlApiBase { private api: CfnGraphQLApi; private apiKeyResource?: CfnApiKey; - constructor(scope: Construct, id: string, props: GraphQLApiProps) { + constructor(scope: Construct, id: string, props: GraphqlApiProps) { super(scope, id); const defaultMode = props.authorizationConfig?.defaultAuthorization ?? @@ -409,7 +409,7 @@ export class GraphQLApi extends GraphqlApiBase { this.apiId = this.api.attrApiId; this.arn = this.api.attrArn; - this.graphQlUrl = this.api.attrGraphQlUrl; + this.graphqlUrl = this.api.attrGraphQlUrl; this.name = this.api.name; this.schema = props.schema ?? new Schema(); this.schemaResource = this.schema.bind(this); diff --git a/packages/@aws-cdk/aws-appsync/lib/schema.ts b/packages/@aws-cdk/aws-appsync/lib/schema.ts index f7751f38a3182..0efb28074fc27 100644 --- a/packages/@aws-cdk/aws-appsync/lib/schema.ts +++ b/packages/@aws-cdk/aws-appsync/lib/schema.ts @@ -1,7 +1,7 @@ import { readFileSync } from 'fs'; import { Lazy } from '@aws-cdk/core'; import { CfnGraphQLSchema } from './appsync.generated'; -import { GraphQLApi } from './graphqlapi'; +import { GraphqlApi } from './graphqlapi'; import { SchemaMode, shapeAddition } from './private'; import { IIntermediateType } from './schema-base'; import { ResolvableField } from './schema-field'; @@ -72,7 +72,7 @@ export class Schema { * * @param api The binding GraphQL Api */ - public bind(api: GraphQLApi): CfnGraphQLSchema { + public bind(api: GraphqlApi): CfnGraphQLSchema { if (!this.schema) { this.schema = new CfnGraphQLSchema(api, 'Schema', { apiId: api.apiId, diff --git a/packages/@aws-cdk/aws-appsync/package.json b/packages/@aws-cdk/aws-appsync/package.json index 7c38409b37325..6726dc41c43a4 100644 --- a/packages/@aws-cdk/aws-appsync/package.json +++ b/packages/@aws-cdk/aws-appsync/package.json @@ -98,8 +98,7 @@ "no-unused-type:@aws-cdk/aws-appsync.ApiKeyConfig", "no-unused-type:@aws-cdk/aws-appsync.UserPoolConfig", "no-unused-type:@aws-cdk/aws-appsync.UserPoolDefaultAction", - "props-physical-name:@aws-cdk/aws-appsync.GraphQLApiProps", - "from-method:@aws-cdk/aws-appsync.GraphQLApi" + "props-physical-name:@aws-cdk/aws-appsync.GraphqlApiProps" ] }, "stability": "experimental", diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts index fabde1d59c95e..5815908198feb 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts @@ -13,7 +13,7 @@ beforeEach(() => { describe('AppSync API Key Authorization', () => { test('AppSync creates default api key', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), }); @@ -24,7 +24,7 @@ describe('AppSync API Key Authorization', () => { test('AppSync creates api key from additionalAuthorizationModes', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -41,7 +41,7 @@ describe('AppSync API Key Authorization', () => { test('AppSync does not create unspecified api key from additionalAuthorizationModes', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -55,7 +55,7 @@ describe('AppSync API Key Authorization', () => { test('appsync does not create unspecified api key with empty additionalAuthorizationModes', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -70,7 +70,7 @@ describe('AppSync API Key Authorization', () => { test('appsync creates configured api key with additionalAuthorizationModes', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -90,7 +90,7 @@ describe('AppSync API Key Authorization', () => { test('appsync creates configured api key with additionalAuthorizationModes (not as first element)', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -117,7 +117,7 @@ describe('AppSync API Key Authorization', () => { test('appsync fails when empty default and API_KEY in additional', () => { // THEN expect(() => { - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -132,7 +132,7 @@ describe('AppSync API Key Authorization', () => { test('appsync fails when multiple API_KEY auth modes', () => { // THEN expect(() => { - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -148,7 +148,7 @@ describe('AppSync API Key Authorization', () => { test('appsync fails when multiple API_KEY auth modes in additionalXxx', () => { // THEN expect(() => { - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -166,7 +166,7 @@ describe('AppSync API Key Authorization', () => { describe('AppSync IAM Authorization', () => { test('Iam authorization configurable in default authorization', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -182,7 +182,7 @@ describe('AppSync IAM Authorization', () => { test('Iam authorization configurable in additional authorization', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -199,7 +199,7 @@ describe('AppSync IAM Authorization', () => { test('appsync fails when multiple iam auth modes', () => { // THEN expect(() => { - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -213,7 +213,7 @@ describe('AppSync IAM Authorization', () => { test('appsync fails when multiple IAM auth modes in additionalXxx', () => { // THEN expect(() => { - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -234,7 +234,7 @@ describe('AppSync User Pool Authorization', () => { }); test('User Pool authorization configurable in default authorization has default configuration', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -258,7 +258,7 @@ describe('AppSync User Pool Authorization', () => { test('User Pool authorization configurable in default authorization', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -287,7 +287,7 @@ describe('AppSync User Pool Authorization', () => { test('User Pool authorization configurable in additional authorization has default configuration', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -312,7 +312,7 @@ describe('AppSync User Pool Authorization', () => { test('User Pool property defaultAction does not configure when in additional auth', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -342,7 +342,7 @@ describe('AppSync User Pool Authorization', () => { test('User Pool property defaultAction does not configure when in additional auth', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -399,7 +399,7 @@ describe('AppSync User Pool Authorization', () => { describe('AppSync OIDC Authorization', () => { test('OIDC authorization configurable in default authorization has default configuration', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -421,7 +421,7 @@ describe('AppSync OIDC Authorization', () => { test('User Pool authorization configurable in default authorization', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -451,7 +451,7 @@ describe('AppSync OIDC Authorization', () => { test('OIDC authorization configurable in additional authorization has default configuration', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -475,7 +475,7 @@ describe('AppSync OIDC Authorization', () => { test('User Pool authorization configurable in additional authorization', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -507,7 +507,7 @@ describe('AppSync OIDC Authorization', () => { test('User Pool authorization configurable in with multiple authorization', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-code-first.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-code-first.test.ts index 0b39cab4c4c24..98460fd8be00d 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-code-first.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-code-first.test.ts @@ -10,10 +10,10 @@ beforeEach(() => { }); describe('code-first implementation through GraphQL Api functions`', () => { - let api: appsync.GraphQLApi; + let api: appsync.GraphqlApi; beforeEach(() => { // GIVEN - api = new appsync.GraphQLApi(stack, 'api', { + api = new appsync.GraphqlApi(stack, 'api', { name: 'api', }); }); @@ -164,7 +164,7 @@ describe('code-first implementation through Schema functions`', () => { schema.addType(test); test.addField('dupid', t.dup_id); - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema, }); @@ -190,7 +190,7 @@ describe('code-first implementation through Schema functions`', () => { schema.addType(test); test.addField('dupid', t.dup_id); - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema, }); @@ -215,7 +215,7 @@ describe('code-first implementation through Schema functions`', () => { }, })); - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema, }); @@ -241,7 +241,7 @@ describe('code-first implementation through Schema functions`', () => { })); test.addField('dupid', t.dup_id); - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema, }); @@ -265,7 +265,7 @@ describe('code-first implementation through Schema functions`', () => { dupid: t.dup_id, }, })); - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema, }); @@ -290,7 +290,7 @@ describe('code-first implementation through Schema functions`', () => { })); test.addField('dupid', t.dup_id); - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema, }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-dynamodb.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-dynamodb.test.ts index e54a9576396d1..07565edd1fba5 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-dynamodb.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-dynamodb.test.ts @@ -10,10 +10,10 @@ function joined(str: string): string { // GLOBAL GIVEN let stack: cdk.Stack; -let api: appsync.GraphQLApi; +let api: appsync.GraphqlApi; beforeEach(() => { stack = new cdk.Stack(); - api = new appsync.GraphQLApi(stack, 'baseApi', { + api = new appsync.GraphqlApi(stack, 'baseApi', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), }); @@ -75,7 +75,7 @@ describe('DynamoDb Data Source configuration', () => { expect(() => { api.addDynamoDbDataSource('ds', table); api.addDynamoDbDataSource('ds', table); - }).toThrow("There is already a Construct with name 'ds' in GraphQLApi [baseApi]"); + }).toThrow("There is already a Construct with name 'ds' in GraphqlApi [baseApi]"); }); }); @@ -160,7 +160,7 @@ describe('adding DynamoDb data source from imported api', () => { test('imported api can add DynamoDbDataSource from id', () => { // WHEN - const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, }); importedApi.addDynamoDbDataSource('ds', table); @@ -174,7 +174,7 @@ describe('adding DynamoDb data source from imported api', () => { test('imported api can add DynamoDbDataSource from attributes', () => { // WHEN - const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, graphqlApiArn: api.arn, }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-grant.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-grant.test.ts index 44251cd7fabee..d59b7c5d363cb 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-grant.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-grant.test.ts @@ -6,14 +6,14 @@ import * as appsync from '../lib'; let stack: cdk.Stack; let role: iam.Role; -let api: appsync.GraphQLApi; +let api: appsync.GraphqlApi; beforeEach(() => { // GIVEN stack = new cdk.Stack(); role = new iam.Role(stack, 'Role', { assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'), }); - api = new appsync.GraphQLApi(stack, 'API', { + api = new appsync.GraphqlApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), authorizationConfig: { diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts index 899a76ebd19f4..6bc237e0f5c71 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts @@ -5,11 +5,11 @@ import * as appsync from '../lib'; // GLOBAL GIVEN let stack: cdk.Stack; -let api: appsync.GraphQLApi; +let api: appsync.GraphqlApi; let endpoint: string; beforeEach(() => { stack = new cdk.Stack(); - api = new appsync.GraphQLApi(stack, 'baseApi', { + api = new appsync.GraphqlApi(stack, 'baseApi', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), }); @@ -62,14 +62,14 @@ describe('Http Data Source configuration', () => { expect(() => { api.addHttpDataSource('ds', endpoint); api.addHttpDataSource('ds', endpoint); - }).toThrow("There is already a Construct with name 'ds' in GraphQLApi [baseApi]"); + }).toThrow("There is already a Construct with name 'ds' in GraphqlApi [baseApi]"); }); }); describe('adding http data source from imported api', () => { test('imported api can add HttpDataSource from id', () => { // WHEN - const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, }); importedApi.addHttpDataSource('ds', endpoint); @@ -83,7 +83,7 @@ describe('adding http data source from imported api', () => { test('imported api can add HttpDataSource from attributes', () => { // WHEN - const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, graphqlApiArn: api.arn, }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-interface-type.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-interface-type.test.ts index 981ec8b60a039..644e7fae42354 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-interface-type.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-interface-type.test.ts @@ -4,11 +4,11 @@ import * as appsync from '../lib'; import * as t from './scalar-type-defintions'; let stack: cdk.Stack; -let api: appsync.GraphQLApi; +let api: appsync.GraphqlApi; beforeEach(() => { // GIVEN stack = new cdk.Stack(); - api = new appsync.GraphQLApi(stack, 'api', { + api = new appsync.GraphqlApi(stack, 'api', { name: 'api', }); }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-lambda.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-lambda.test.ts index a67fd4b1691b7..0cc8396382017 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-lambda.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-lambda.test.ts @@ -6,10 +6,10 @@ import * as appsync from '../lib'; // GLOBAL GIVEN let stack: cdk.Stack; -let api: appsync.GraphQLApi; +let api: appsync.GraphqlApi; beforeEach(() => { stack = new cdk.Stack(); - api = new appsync.GraphQLApi(stack, 'baseApi', { + api = new appsync.GraphqlApi(stack, 'baseApi', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), }); @@ -70,7 +70,7 @@ describe('Lambda Data Source configuration', () => { expect(() => { api.addLambdaDataSource('ds', func); api.addLambdaDataSource('ds', func); - }).toThrow("There is already a Construct with name 'ds' in GraphQLApi [baseApi]"); + }).toThrow("There is already a Construct with name 'ds' in GraphqlApi [baseApi]"); }); }); @@ -86,7 +86,7 @@ describe('adding lambda data source from imported api', () => { test('imported api can add LambdaDbDataSource from id', () => { // WHEN - const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, }); importedApi.addLambdaDataSource('ds', func); @@ -100,7 +100,7 @@ describe('adding lambda data source from imported api', () => { test('imported api can add LambdaDataSource from attributes', () => { // WHEN - const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, graphqlApiArn: api.arn, }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-none.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-none.test.ts index f2b52c7dfba03..3985cebc30719 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-none.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-none.test.ts @@ -5,10 +5,10 @@ import * as appsync from '../lib'; // GLOBAL GIVEN let stack: cdk.Stack; -let api: appsync.GraphQLApi; +let api: appsync.GraphqlApi; beforeEach(() => { stack = new cdk.Stack(); - api = new appsync.GraphQLApi(stack, 'baseApi', { + api = new appsync.GraphqlApi(stack, 'baseApi', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), }); @@ -60,7 +60,7 @@ describe('None Data Source configuration', () => { expect(() => { api.addNoneDataSource('ds'); api.addNoneDataSource('ds'); - }).toThrow("There is already a Construct with name 'ds' in GraphQLApi [baseApi]"); + }).toThrow("There is already a Construct with name 'ds' in GraphqlApi [baseApi]"); }); test('appsync errors when creating multiple none data sources with same name configuration', () => { @@ -75,7 +75,7 @@ describe('None Data Source configuration', () => { describe('adding none data source from imported api', () => { test('imported api can add NoneDataSource from id', () => { // WHEN - const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, }); importedApi.addNoneDataSource('none'); @@ -89,7 +89,7 @@ describe('adding none data source from imported api', () => { test('imported api can add NoneDataSource from attributes', () => { // WHEN - const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, graphqlApiArn: api.arn, }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-object-type.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-object-type.test.ts index a60a5242f6fe7..02f0d9b43ff57 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-object-type.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-object-type.test.ts @@ -4,11 +4,11 @@ import * as appsync from '../lib'; import * as t from './scalar-type-defintions'; let stack: cdk.Stack; -let api: appsync.GraphQLApi; +let api: appsync.GraphqlApi; beforeEach(() => { // GIVEN stack = new cdk.Stack(); - api = new appsync.GraphQLApi(stack, 'api', { + api = new appsync.GraphqlApi(stack, 'api', { name: 'api', }); }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-scalar-type.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-scalar-type.test.ts index 64fddd55bc3d3..312d7a3784b98 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-scalar-type.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-scalar-type.test.ts @@ -4,11 +4,11 @@ import * as appsync from '../lib'; import * as t from './scalar-type-defintions'; let stack: cdk.Stack; -let api: appsync.GraphQLApi; +let api: appsync.GraphqlApi; beforeEach(() => { // GIVEN stack = new cdk.Stack(); - api = new appsync.GraphQLApi(stack, 'api', { + api = new appsync.GraphqlApi(stack, 'api', { name: 'api', }); }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts index f60d63f1dec5c..95fe1ac7c500a 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts @@ -36,7 +36,7 @@ describe('basic testing schema definition mode `code`', () => { test('definition mode `code` produces empty schema definition', () => { // WHEN - new appsync.GraphQLApi(stack, 'API', { + new appsync.GraphqlApi(stack, 'API', { name: 'demo', }); @@ -48,7 +48,7 @@ describe('basic testing schema definition mode `code`', () => { test('definition mode `code` generates correct schema with addToSchema', () => { // WHEN - const api = new appsync.GraphQLApi(stack, 'API', { + const api = new appsync.GraphqlApi(stack, 'API', { name: 'demo', }); api.addType(type); @@ -63,7 +63,7 @@ describe('basic testing schema definition mode `code`', () => { test('definition mode `code` allows for api to addQuery', () => { // WHEN - const api = new appsync.GraphQLApi(stack, 'API', { + const api = new appsync.GraphqlApi(stack, 'API', { name: 'demo', }); api.addQuery('test', new appsync.ResolvableField({ @@ -79,7 +79,7 @@ describe('basic testing schema definition mode `code`', () => { test('definition mode `code` allows for schema to addQuery', () => { // WHEN const schema = new appsync.Schema(); - new appsync.GraphQLApi(stack, 'API', { + new appsync.GraphqlApi(stack, 'API', { name: 'demo', schema, }); @@ -95,7 +95,7 @@ describe('basic testing schema definition mode `code`', () => { test('definition mode `code` allows for api to addMutation', () => { // WHEN - const api = new appsync.GraphQLApi(stack, 'API', { + const api = new appsync.GraphqlApi(stack, 'API', { name: 'demo', }); api.addMutation('test', new appsync.ResolvableField({ @@ -111,7 +111,7 @@ describe('basic testing schema definition mode `code`', () => { test('definition mode `code` allows for schema to addMutation', () => { // WHEN const schema = new appsync.Schema(); - new appsync.GraphQLApi(stack, 'API', { + new appsync.GraphqlApi(stack, 'API', { name: 'demo', schema, }); @@ -130,7 +130,7 @@ describe('testing schema definition mode `file`', () => { test('definition mode `file` produces correct output', () => { // WHEN - new appsync.GraphQLApi(stack, 'API', { + new appsync.GraphqlApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), }); @@ -143,7 +143,7 @@ describe('testing schema definition mode `file`', () => { test('definition mode `file` errors when addType for object is called', () => { // WHEN - const api = new appsync.GraphQLApi(stack, 'API', { + const api = new appsync.GraphqlApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), }); @@ -158,7 +158,7 @@ describe('testing schema definition mode `file`', () => { test('definition mode `file` errors when addType for interface is called', () => { // WHEN - const api = new appsync.GraphQLApi(stack, 'API', { + const api = new appsync.GraphqlApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), }); @@ -173,7 +173,7 @@ describe('testing schema definition mode `file`', () => { test('definition mode `file` errors when addToSchema is called', () => { // WHEN - const api = new appsync.GraphQLApi(stack, 'API', { + const api = new appsync.GraphqlApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), }); @@ -186,7 +186,7 @@ describe('testing schema definition mode `file`', () => { test('definition mode `file` errors when addQuery is called', () => { // WHEN - const api = new appsync.GraphQLApi(stack, 'API', { + const api = new appsync.GraphqlApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), }); @@ -199,7 +199,7 @@ describe('testing schema definition mode `file`', () => { test('definition mode `file` errors when addMutation is called', () => { // WHEN - const api = new appsync.GraphQLApi(stack, 'API', { + const api = new appsync.GraphqlApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync.test.ts index 9dc6808a672e1..debdfa71ce4f0 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync.test.ts @@ -4,10 +4,10 @@ import * as cdk from '@aws-cdk/core'; import * as appsync from '../lib'; let stack: cdk.Stack; -let api: appsync.GraphQLApi; +let api: appsync.GraphqlApi; beforeEach(() => { stack = new cdk.Stack(); - api = new appsync.GraphQLApi(stack, 'api', { + api = new appsync.GraphqlApi(stack, 'api', { authorizationConfig: {}, name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), @@ -61,7 +61,7 @@ test('appsync should configure resolver as unit when pipelineConfig is empty arr test('when xray is enabled should not throw an Error', () => { // WHEN - new appsync.GraphQLApi(stack, 'api-x-ray', { + new appsync.GraphqlApi(stack, 'api-x-ray', { authorizationConfig: {}, name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), diff --git a/packages/@aws-cdk/aws-appsync/test/integ.api-import.ts b/packages/@aws-cdk/aws-appsync/test/integ.api-import.ts index b36c6a1bef7b1..8781f83fe117e 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.api-import.ts +++ b/packages/@aws-cdk/aws-appsync/test/integ.api-import.ts @@ -11,7 +11,7 @@ import * as appsync from '../lib'; * * Stack verification steps: * Install dependencies and deploy integration test. Check if data sources are - * connected to the graphQL Api + * connected to the GraphQL Api * * -- cdk deploy --app 'node integ.api-import.js' stack -- start -- * -- aws appsync list-graphql-apis -- obtain api id -- @@ -22,13 +22,13 @@ import * as appsync from '../lib'; const app = new cdk.App(); const baseStack = new cdk.Stack(app, 'baseStack'); -const baseApi = new appsync.GraphQLApi(baseStack, 'baseApi', { +const baseApi = new appsync.GraphqlApi(baseStack, 'baseApi', { name: 'baseApi', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), }); const stack = new cdk.Stack(app, 'stack'); -const api = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'Api', { +const api = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'Api', { graphqlApiId: `${baseApi.apiId}`, }); @@ -57,7 +57,7 @@ testDS.createResolver({ responseMappingTemplate: appsync.MappingTemplate.dynamoDbResultItem(), }); -const api2 = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'api2', { +const api2 = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'api2', { graphqlApiId: baseApi.apiId, graphqlApiArn: baseApi.arn, }); diff --git a/packages/@aws-cdk/aws-appsync/test/integ.graphql-iam.ts b/packages/@aws-cdk/aws-appsync/test/integ.graphql-iam.ts index 0d4c95a10ea3f..185fc8ef3e729 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.graphql-iam.ts +++ b/packages/@aws-cdk/aws-appsync/test/integ.graphql-iam.ts @@ -6,7 +6,7 @@ import { Code, Function, Runtime } from '@aws-cdk/aws-lambda'; import { App, RemovalPolicy, Stack } from '@aws-cdk/core'; import { AuthorizationType, - GraphQLApi, + GraphqlApi, MappingTemplate, PrimaryKey, UserPoolDefaultAction, @@ -36,7 +36,7 @@ const userPool = new UserPool(stack, 'Pool', { userPoolName: 'myPool', }); -const api = new GraphQLApi(stack, 'Api', { +const api = new GraphqlApi(stack, 'Api', { name: 'Integ_Test_IAM', schema: Schema.fromAsset(join(__dirname, 'integ.graphql-iam.graphql')), authorizationConfig: { @@ -98,14 +98,14 @@ new Function(stack, 'testQuery', { code: Code.fromAsset('verify'), handler: 'iam-query.handler', runtime: Runtime.NODEJS_12_X, - environment: { APPSYNC_ENDPOINT: api.graphQlUrl }, + environment: { APPSYNC_ENDPOINT: api.graphqlUrl }, role: lambdaIAM, }); new Function(stack, 'testFail', { code: Code.fromAsset('verify'), handler: 'iam-query.handler', runtime: Runtime.NODEJS_12_X, - environment: { APPSYNC_ENDPOINT: api.graphQlUrl }, + environment: { APPSYNC_ENDPOINT: api.graphqlUrl }, }); app.synth(); diff --git a/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.ts b/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.ts index 8bde313c6f724..8cb3daafab11a 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.ts +++ b/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.ts @@ -29,7 +29,7 @@ const node = schema.addType(new appsync.InterfaceType('Node', { }, })); -const api = new appsync.GraphQLApi(stack, 'code-first-api', { +const api = new appsync.GraphqlApi(stack, 'code-first-api', { name: 'api', schema: schema, }); diff --git a/packages/@aws-cdk/aws-appsync/test/integ.graphql.ts b/packages/@aws-cdk/aws-appsync/test/integ.graphql.ts index 9882fead1cf12..1de80995c90a0 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.graphql.ts +++ b/packages/@aws-cdk/aws-appsync/test/integ.graphql.ts @@ -4,7 +4,7 @@ import { AttributeType, BillingMode, Table } from '@aws-cdk/aws-dynamodb'; import { App, RemovalPolicy, Stack } from '@aws-cdk/core'; import { AuthorizationType, - GraphQLApi, + GraphqlApi, KeyCondition, MappingTemplate, PrimaryKey, @@ -33,7 +33,7 @@ const userPool = new UserPool(stack, 'Pool', { userPoolName: 'myPool', }); -const api = new GraphQLApi(stack, 'Api', { +const api = new GraphqlApi(stack, 'Api', { name: 'demoapi', schema: Schema.fromAsset(join(__dirname, 'integ.graphql.graphql')), authorizationConfig: { From 51edc01b01fb75896770ca1d28647f2a12be755f Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Mon, 31 Aug 2020 15:04:47 -0700 Subject: [PATCH 4/9] Revert "refactor(appsync): graphQLApi to graphqlApi for better snakecasing" This reverts commit f3c77e35237abb980e50ab300fb39eb72a1f3934. --- .../@aws-cdk/aws-appsync/lib/graphqlapi.ts | 14 +++--- packages/@aws-cdk/aws-appsync/lib/schema.ts | 4 +- packages/@aws-cdk/aws-appsync/package.json | 3 +- .../aws-appsync/test/appsync-auth.test.ts | 46 +++++++++---------- .../test/appsync-code-first.test.ts | 16 +++---- .../aws-appsync/test/appsync-dynamodb.test.ts | 10 ++-- .../aws-appsync/test/appsync-grant.test.ts | 4 +- .../aws-appsync/test/appsync-http.test.ts | 10 ++-- .../test/appsync-interface-type.test.ts | 4 +- .../aws-appsync/test/appsync-lambda.test.ts | 10 ++-- .../aws-appsync/test/appsync-none.test.ts | 10 ++-- .../test/appsync-object-type.test.ts | 4 +- .../test/appsync-scalar-type.test.ts | 4 +- .../aws-appsync/test/appsync-schema.test.ts | 24 +++++----- .../@aws-cdk/aws-appsync/test/appsync.test.ts | 6 +-- .../aws-appsync/test/integ.api-import.ts | 8 ++-- .../aws-appsync/test/integ.graphql-iam.ts | 8 ++-- .../aws-appsync/test/integ.graphql-schema.ts | 2 +- .../aws-appsync/test/integ.graphql.ts | 4 +- 19 files changed, 96 insertions(+), 95 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts index 052e3ecd53392..4251336f017ea 100644 --- a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts +++ b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts @@ -206,7 +206,7 @@ export interface LogConfig { /** * Properties for an AppSync GraphQL API */ -export interface GraphqlApiProps { +export interface GraphQLApiProps { /** * the name of the GraphQL API */ @@ -293,7 +293,7 @@ export class IamResource { * * @param api The GraphQL API to give permissions */ - public resourceArns(api: GraphqlApi): string[] { + public resourceArns(api: GraphQLApi): string[] { return this.arns.map((arn) => Stack.of(api).formatArn({ service: 'appsync', resource: `apis/${api.apiId}`, @@ -325,7 +325,7 @@ export interface GraphqlApiAttributes { * * @resource AWS::AppSync::GraphQLApi */ -export class GraphqlApi extends GraphqlApiBase { +export class GraphQLApi extends GraphqlApiBase { /** * Import a GraphQL API through this function * @@ -362,9 +362,9 @@ export class GraphqlApi extends GraphqlApiBase { /** * the URL of the endpoint created by AppSync * - * @attribute GraphQlUrl + * @attribute */ - public readonly graphqlUrl: string; + public readonly graphQlUrl: string; /** * the name of the API @@ -387,7 +387,7 @@ export class GraphqlApi extends GraphqlApiBase { private api: CfnGraphQLApi; private apiKeyResource?: CfnApiKey; - constructor(scope: Construct, id: string, props: GraphqlApiProps) { + constructor(scope: Construct, id: string, props: GraphQLApiProps) { super(scope, id); const defaultMode = props.authorizationConfig?.defaultAuthorization ?? @@ -409,7 +409,7 @@ export class GraphqlApi extends GraphqlApiBase { this.apiId = this.api.attrApiId; this.arn = this.api.attrArn; - this.graphqlUrl = this.api.attrGraphQlUrl; + this.graphQlUrl = this.api.attrGraphQlUrl; this.name = this.api.name; this.schema = props.schema ?? new Schema(); this.schemaResource = this.schema.bind(this); diff --git a/packages/@aws-cdk/aws-appsync/lib/schema.ts b/packages/@aws-cdk/aws-appsync/lib/schema.ts index 0efb28074fc27..f7751f38a3182 100644 --- a/packages/@aws-cdk/aws-appsync/lib/schema.ts +++ b/packages/@aws-cdk/aws-appsync/lib/schema.ts @@ -1,7 +1,7 @@ import { readFileSync } from 'fs'; import { Lazy } from '@aws-cdk/core'; import { CfnGraphQLSchema } from './appsync.generated'; -import { GraphqlApi } from './graphqlapi'; +import { GraphQLApi } from './graphqlapi'; import { SchemaMode, shapeAddition } from './private'; import { IIntermediateType } from './schema-base'; import { ResolvableField } from './schema-field'; @@ -72,7 +72,7 @@ export class Schema { * * @param api The binding GraphQL Api */ - public bind(api: GraphqlApi): CfnGraphQLSchema { + public bind(api: GraphQLApi): CfnGraphQLSchema { if (!this.schema) { this.schema = new CfnGraphQLSchema(api, 'Schema', { apiId: api.apiId, diff --git a/packages/@aws-cdk/aws-appsync/package.json b/packages/@aws-cdk/aws-appsync/package.json index 6726dc41c43a4..7c38409b37325 100644 --- a/packages/@aws-cdk/aws-appsync/package.json +++ b/packages/@aws-cdk/aws-appsync/package.json @@ -98,7 +98,8 @@ "no-unused-type:@aws-cdk/aws-appsync.ApiKeyConfig", "no-unused-type:@aws-cdk/aws-appsync.UserPoolConfig", "no-unused-type:@aws-cdk/aws-appsync.UserPoolDefaultAction", - "props-physical-name:@aws-cdk/aws-appsync.GraphqlApiProps" + "props-physical-name:@aws-cdk/aws-appsync.GraphQLApiProps", + "from-method:@aws-cdk/aws-appsync.GraphQLApi" ] }, "stability": "experimental", diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts index 5815908198feb..fabde1d59c95e 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts @@ -13,7 +13,7 @@ beforeEach(() => { describe('AppSync API Key Authorization', () => { test('AppSync creates default api key', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), }); @@ -24,7 +24,7 @@ describe('AppSync API Key Authorization', () => { test('AppSync creates api key from additionalAuthorizationModes', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -41,7 +41,7 @@ describe('AppSync API Key Authorization', () => { test('AppSync does not create unspecified api key from additionalAuthorizationModes', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -55,7 +55,7 @@ describe('AppSync API Key Authorization', () => { test('appsync does not create unspecified api key with empty additionalAuthorizationModes', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -70,7 +70,7 @@ describe('AppSync API Key Authorization', () => { test('appsync creates configured api key with additionalAuthorizationModes', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -90,7 +90,7 @@ describe('AppSync API Key Authorization', () => { test('appsync creates configured api key with additionalAuthorizationModes (not as first element)', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -117,7 +117,7 @@ describe('AppSync API Key Authorization', () => { test('appsync fails when empty default and API_KEY in additional', () => { // THEN expect(() => { - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -132,7 +132,7 @@ describe('AppSync API Key Authorization', () => { test('appsync fails when multiple API_KEY auth modes', () => { // THEN expect(() => { - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -148,7 +148,7 @@ describe('AppSync API Key Authorization', () => { test('appsync fails when multiple API_KEY auth modes in additionalXxx', () => { // THEN expect(() => { - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -166,7 +166,7 @@ describe('AppSync API Key Authorization', () => { describe('AppSync IAM Authorization', () => { test('Iam authorization configurable in default authorization', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -182,7 +182,7 @@ describe('AppSync IAM Authorization', () => { test('Iam authorization configurable in additional authorization', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -199,7 +199,7 @@ describe('AppSync IAM Authorization', () => { test('appsync fails when multiple iam auth modes', () => { // THEN expect(() => { - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -213,7 +213,7 @@ describe('AppSync IAM Authorization', () => { test('appsync fails when multiple IAM auth modes in additionalXxx', () => { // THEN expect(() => { - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -234,7 +234,7 @@ describe('AppSync User Pool Authorization', () => { }); test('User Pool authorization configurable in default authorization has default configuration', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -258,7 +258,7 @@ describe('AppSync User Pool Authorization', () => { test('User Pool authorization configurable in default authorization', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -287,7 +287,7 @@ describe('AppSync User Pool Authorization', () => { test('User Pool authorization configurable in additional authorization has default configuration', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -312,7 +312,7 @@ describe('AppSync User Pool Authorization', () => { test('User Pool property defaultAction does not configure when in additional auth', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -342,7 +342,7 @@ describe('AppSync User Pool Authorization', () => { test('User Pool property defaultAction does not configure when in additional auth', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -399,7 +399,7 @@ describe('AppSync User Pool Authorization', () => { describe('AppSync OIDC Authorization', () => { test('OIDC authorization configurable in default authorization has default configuration', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -421,7 +421,7 @@ describe('AppSync OIDC Authorization', () => { test('User Pool authorization configurable in default authorization', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -451,7 +451,7 @@ describe('AppSync OIDC Authorization', () => { test('OIDC authorization configurable in additional authorization has default configuration', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -475,7 +475,7 @@ describe('AppSync OIDC Authorization', () => { test('User Pool authorization configurable in additional authorization', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -507,7 +507,7 @@ describe('AppSync OIDC Authorization', () => { test('User Pool authorization configurable in with multiple authorization', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-code-first.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-code-first.test.ts index 98460fd8be00d..0b39cab4c4c24 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-code-first.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-code-first.test.ts @@ -10,10 +10,10 @@ beforeEach(() => { }); describe('code-first implementation through GraphQL Api functions`', () => { - let api: appsync.GraphqlApi; + let api: appsync.GraphQLApi; beforeEach(() => { // GIVEN - api = new appsync.GraphqlApi(stack, 'api', { + api = new appsync.GraphQLApi(stack, 'api', { name: 'api', }); }); @@ -164,7 +164,7 @@ describe('code-first implementation through Schema functions`', () => { schema.addType(test); test.addField('dupid', t.dup_id); - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema, }); @@ -190,7 +190,7 @@ describe('code-first implementation through Schema functions`', () => { schema.addType(test); test.addField('dupid', t.dup_id); - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema, }); @@ -215,7 +215,7 @@ describe('code-first implementation through Schema functions`', () => { }, })); - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema, }); @@ -241,7 +241,7 @@ describe('code-first implementation through Schema functions`', () => { })); test.addField('dupid', t.dup_id); - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema, }); @@ -265,7 +265,7 @@ describe('code-first implementation through Schema functions`', () => { dupid: t.dup_id, }, })); - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema, }); @@ -290,7 +290,7 @@ describe('code-first implementation through Schema functions`', () => { })); test.addField('dupid', t.dup_id); - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema, }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-dynamodb.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-dynamodb.test.ts index 07565edd1fba5..e54a9576396d1 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-dynamodb.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-dynamodb.test.ts @@ -10,10 +10,10 @@ function joined(str: string): string { // GLOBAL GIVEN let stack: cdk.Stack; -let api: appsync.GraphqlApi; +let api: appsync.GraphQLApi; beforeEach(() => { stack = new cdk.Stack(); - api = new appsync.GraphqlApi(stack, 'baseApi', { + api = new appsync.GraphQLApi(stack, 'baseApi', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), }); @@ -75,7 +75,7 @@ describe('DynamoDb Data Source configuration', () => { expect(() => { api.addDynamoDbDataSource('ds', table); api.addDynamoDbDataSource('ds', table); - }).toThrow("There is already a Construct with name 'ds' in GraphqlApi [baseApi]"); + }).toThrow("There is already a Construct with name 'ds' in GraphQLApi [baseApi]"); }); }); @@ -160,7 +160,7 @@ describe('adding DynamoDb data source from imported api', () => { test('imported api can add DynamoDbDataSource from id', () => { // WHEN - const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, }); importedApi.addDynamoDbDataSource('ds', table); @@ -174,7 +174,7 @@ describe('adding DynamoDb data source from imported api', () => { test('imported api can add DynamoDbDataSource from attributes', () => { // WHEN - const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, graphqlApiArn: api.arn, }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-grant.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-grant.test.ts index d59b7c5d363cb..44251cd7fabee 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-grant.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-grant.test.ts @@ -6,14 +6,14 @@ import * as appsync from '../lib'; let stack: cdk.Stack; let role: iam.Role; -let api: appsync.GraphqlApi; +let api: appsync.GraphQLApi; beforeEach(() => { // GIVEN stack = new cdk.Stack(); role = new iam.Role(stack, 'Role', { assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'), }); - api = new appsync.GraphqlApi(stack, 'API', { + api = new appsync.GraphQLApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), authorizationConfig: { diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts index 6bc237e0f5c71..899a76ebd19f4 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts @@ -5,11 +5,11 @@ import * as appsync from '../lib'; // GLOBAL GIVEN let stack: cdk.Stack; -let api: appsync.GraphqlApi; +let api: appsync.GraphQLApi; let endpoint: string; beforeEach(() => { stack = new cdk.Stack(); - api = new appsync.GraphqlApi(stack, 'baseApi', { + api = new appsync.GraphQLApi(stack, 'baseApi', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), }); @@ -62,14 +62,14 @@ describe('Http Data Source configuration', () => { expect(() => { api.addHttpDataSource('ds', endpoint); api.addHttpDataSource('ds', endpoint); - }).toThrow("There is already a Construct with name 'ds' in GraphqlApi [baseApi]"); + }).toThrow("There is already a Construct with name 'ds' in GraphQLApi [baseApi]"); }); }); describe('adding http data source from imported api', () => { test('imported api can add HttpDataSource from id', () => { // WHEN - const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, }); importedApi.addHttpDataSource('ds', endpoint); @@ -83,7 +83,7 @@ describe('adding http data source from imported api', () => { test('imported api can add HttpDataSource from attributes', () => { // WHEN - const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, graphqlApiArn: api.arn, }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-interface-type.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-interface-type.test.ts index 644e7fae42354..981ec8b60a039 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-interface-type.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-interface-type.test.ts @@ -4,11 +4,11 @@ import * as appsync from '../lib'; import * as t from './scalar-type-defintions'; let stack: cdk.Stack; -let api: appsync.GraphqlApi; +let api: appsync.GraphQLApi; beforeEach(() => { // GIVEN stack = new cdk.Stack(); - api = new appsync.GraphqlApi(stack, 'api', { + api = new appsync.GraphQLApi(stack, 'api', { name: 'api', }); }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-lambda.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-lambda.test.ts index 0cc8396382017..a67fd4b1691b7 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-lambda.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-lambda.test.ts @@ -6,10 +6,10 @@ import * as appsync from '../lib'; // GLOBAL GIVEN let stack: cdk.Stack; -let api: appsync.GraphqlApi; +let api: appsync.GraphQLApi; beforeEach(() => { stack = new cdk.Stack(); - api = new appsync.GraphqlApi(stack, 'baseApi', { + api = new appsync.GraphQLApi(stack, 'baseApi', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), }); @@ -70,7 +70,7 @@ describe('Lambda Data Source configuration', () => { expect(() => { api.addLambdaDataSource('ds', func); api.addLambdaDataSource('ds', func); - }).toThrow("There is already a Construct with name 'ds' in GraphqlApi [baseApi]"); + }).toThrow("There is already a Construct with name 'ds' in GraphQLApi [baseApi]"); }); }); @@ -86,7 +86,7 @@ describe('adding lambda data source from imported api', () => { test('imported api can add LambdaDbDataSource from id', () => { // WHEN - const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, }); importedApi.addLambdaDataSource('ds', func); @@ -100,7 +100,7 @@ describe('adding lambda data source from imported api', () => { test('imported api can add LambdaDataSource from attributes', () => { // WHEN - const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, graphqlApiArn: api.arn, }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-none.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-none.test.ts index 3985cebc30719..f2b52c7dfba03 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-none.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-none.test.ts @@ -5,10 +5,10 @@ import * as appsync from '../lib'; // GLOBAL GIVEN let stack: cdk.Stack; -let api: appsync.GraphqlApi; +let api: appsync.GraphQLApi; beforeEach(() => { stack = new cdk.Stack(); - api = new appsync.GraphqlApi(stack, 'baseApi', { + api = new appsync.GraphQLApi(stack, 'baseApi', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), }); @@ -60,7 +60,7 @@ describe('None Data Source configuration', () => { expect(() => { api.addNoneDataSource('ds'); api.addNoneDataSource('ds'); - }).toThrow("There is already a Construct with name 'ds' in GraphqlApi [baseApi]"); + }).toThrow("There is already a Construct with name 'ds' in GraphQLApi [baseApi]"); }); test('appsync errors when creating multiple none data sources with same name configuration', () => { @@ -75,7 +75,7 @@ describe('None Data Source configuration', () => { describe('adding none data source from imported api', () => { test('imported api can add NoneDataSource from id', () => { // WHEN - const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, }); importedApi.addNoneDataSource('none'); @@ -89,7 +89,7 @@ describe('adding none data source from imported api', () => { test('imported api can add NoneDataSource from attributes', () => { // WHEN - const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, graphqlApiArn: api.arn, }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-object-type.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-object-type.test.ts index 02f0d9b43ff57..a60a5242f6fe7 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-object-type.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-object-type.test.ts @@ -4,11 +4,11 @@ import * as appsync from '../lib'; import * as t from './scalar-type-defintions'; let stack: cdk.Stack; -let api: appsync.GraphqlApi; +let api: appsync.GraphQLApi; beforeEach(() => { // GIVEN stack = new cdk.Stack(); - api = new appsync.GraphqlApi(stack, 'api', { + api = new appsync.GraphQLApi(stack, 'api', { name: 'api', }); }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-scalar-type.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-scalar-type.test.ts index 312d7a3784b98..64fddd55bc3d3 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-scalar-type.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-scalar-type.test.ts @@ -4,11 +4,11 @@ import * as appsync from '../lib'; import * as t from './scalar-type-defintions'; let stack: cdk.Stack; -let api: appsync.GraphqlApi; +let api: appsync.GraphQLApi; beforeEach(() => { // GIVEN stack = new cdk.Stack(); - api = new appsync.GraphqlApi(stack, 'api', { + api = new appsync.GraphQLApi(stack, 'api', { name: 'api', }); }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts index 95fe1ac7c500a..f60d63f1dec5c 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts @@ -36,7 +36,7 @@ describe('basic testing schema definition mode `code`', () => { test('definition mode `code` produces empty schema definition', () => { // WHEN - new appsync.GraphqlApi(stack, 'API', { + new appsync.GraphQLApi(stack, 'API', { name: 'demo', }); @@ -48,7 +48,7 @@ describe('basic testing schema definition mode `code`', () => { test('definition mode `code` generates correct schema with addToSchema', () => { // WHEN - const api = new appsync.GraphqlApi(stack, 'API', { + const api = new appsync.GraphQLApi(stack, 'API', { name: 'demo', }); api.addType(type); @@ -63,7 +63,7 @@ describe('basic testing schema definition mode `code`', () => { test('definition mode `code` allows for api to addQuery', () => { // WHEN - const api = new appsync.GraphqlApi(stack, 'API', { + const api = new appsync.GraphQLApi(stack, 'API', { name: 'demo', }); api.addQuery('test', new appsync.ResolvableField({ @@ -79,7 +79,7 @@ describe('basic testing schema definition mode `code`', () => { test('definition mode `code` allows for schema to addQuery', () => { // WHEN const schema = new appsync.Schema(); - new appsync.GraphqlApi(stack, 'API', { + new appsync.GraphQLApi(stack, 'API', { name: 'demo', schema, }); @@ -95,7 +95,7 @@ describe('basic testing schema definition mode `code`', () => { test('definition mode `code` allows for api to addMutation', () => { // WHEN - const api = new appsync.GraphqlApi(stack, 'API', { + const api = new appsync.GraphQLApi(stack, 'API', { name: 'demo', }); api.addMutation('test', new appsync.ResolvableField({ @@ -111,7 +111,7 @@ describe('basic testing schema definition mode `code`', () => { test('definition mode `code` allows for schema to addMutation', () => { // WHEN const schema = new appsync.Schema(); - new appsync.GraphqlApi(stack, 'API', { + new appsync.GraphQLApi(stack, 'API', { name: 'demo', schema, }); @@ -130,7 +130,7 @@ describe('testing schema definition mode `file`', () => { test('definition mode `file` produces correct output', () => { // WHEN - new appsync.GraphqlApi(stack, 'API', { + new appsync.GraphQLApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), }); @@ -143,7 +143,7 @@ describe('testing schema definition mode `file`', () => { test('definition mode `file` errors when addType for object is called', () => { // WHEN - const api = new appsync.GraphqlApi(stack, 'API', { + const api = new appsync.GraphQLApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), }); @@ -158,7 +158,7 @@ describe('testing schema definition mode `file`', () => { test('definition mode `file` errors when addType for interface is called', () => { // WHEN - const api = new appsync.GraphqlApi(stack, 'API', { + const api = new appsync.GraphQLApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), }); @@ -173,7 +173,7 @@ describe('testing schema definition mode `file`', () => { test('definition mode `file` errors when addToSchema is called', () => { // WHEN - const api = new appsync.GraphqlApi(stack, 'API', { + const api = new appsync.GraphQLApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), }); @@ -186,7 +186,7 @@ describe('testing schema definition mode `file`', () => { test('definition mode `file` errors when addQuery is called', () => { // WHEN - const api = new appsync.GraphqlApi(stack, 'API', { + const api = new appsync.GraphQLApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), }); @@ -199,7 +199,7 @@ describe('testing schema definition mode `file`', () => { test('definition mode `file` errors when addMutation is called', () => { // WHEN - const api = new appsync.GraphqlApi(stack, 'API', { + const api = new appsync.GraphQLApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync.test.ts index debdfa71ce4f0..9dc6808a672e1 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync.test.ts @@ -4,10 +4,10 @@ import * as cdk from '@aws-cdk/core'; import * as appsync from '../lib'; let stack: cdk.Stack; -let api: appsync.GraphqlApi; +let api: appsync.GraphQLApi; beforeEach(() => { stack = new cdk.Stack(); - api = new appsync.GraphqlApi(stack, 'api', { + api = new appsync.GraphQLApi(stack, 'api', { authorizationConfig: {}, name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), @@ -61,7 +61,7 @@ test('appsync should configure resolver as unit when pipelineConfig is empty arr test('when xray is enabled should not throw an Error', () => { // WHEN - new appsync.GraphqlApi(stack, 'api-x-ray', { + new appsync.GraphQLApi(stack, 'api-x-ray', { authorizationConfig: {}, name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), diff --git a/packages/@aws-cdk/aws-appsync/test/integ.api-import.ts b/packages/@aws-cdk/aws-appsync/test/integ.api-import.ts index 8781f83fe117e..b36c6a1bef7b1 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.api-import.ts +++ b/packages/@aws-cdk/aws-appsync/test/integ.api-import.ts @@ -11,7 +11,7 @@ import * as appsync from '../lib'; * * Stack verification steps: * Install dependencies and deploy integration test. Check if data sources are - * connected to the GraphQL Api + * connected to the graphQL Api * * -- cdk deploy --app 'node integ.api-import.js' stack -- start -- * -- aws appsync list-graphql-apis -- obtain api id -- @@ -22,13 +22,13 @@ import * as appsync from '../lib'; const app = new cdk.App(); const baseStack = new cdk.Stack(app, 'baseStack'); -const baseApi = new appsync.GraphqlApi(baseStack, 'baseApi', { +const baseApi = new appsync.GraphQLApi(baseStack, 'baseApi', { name: 'baseApi', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), }); const stack = new cdk.Stack(app, 'stack'); -const api = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'Api', { +const api = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'Api', { graphqlApiId: `${baseApi.apiId}`, }); @@ -57,7 +57,7 @@ testDS.createResolver({ responseMappingTemplate: appsync.MappingTemplate.dynamoDbResultItem(), }); -const api2 = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'api2', { +const api2 = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'api2', { graphqlApiId: baseApi.apiId, graphqlApiArn: baseApi.arn, }); diff --git a/packages/@aws-cdk/aws-appsync/test/integ.graphql-iam.ts b/packages/@aws-cdk/aws-appsync/test/integ.graphql-iam.ts index 185fc8ef3e729..0d4c95a10ea3f 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.graphql-iam.ts +++ b/packages/@aws-cdk/aws-appsync/test/integ.graphql-iam.ts @@ -6,7 +6,7 @@ import { Code, Function, Runtime } from '@aws-cdk/aws-lambda'; import { App, RemovalPolicy, Stack } from '@aws-cdk/core'; import { AuthorizationType, - GraphqlApi, + GraphQLApi, MappingTemplate, PrimaryKey, UserPoolDefaultAction, @@ -36,7 +36,7 @@ const userPool = new UserPool(stack, 'Pool', { userPoolName: 'myPool', }); -const api = new GraphqlApi(stack, 'Api', { +const api = new GraphQLApi(stack, 'Api', { name: 'Integ_Test_IAM', schema: Schema.fromAsset(join(__dirname, 'integ.graphql-iam.graphql')), authorizationConfig: { @@ -98,14 +98,14 @@ new Function(stack, 'testQuery', { code: Code.fromAsset('verify'), handler: 'iam-query.handler', runtime: Runtime.NODEJS_12_X, - environment: { APPSYNC_ENDPOINT: api.graphqlUrl }, + environment: { APPSYNC_ENDPOINT: api.graphQlUrl }, role: lambdaIAM, }); new Function(stack, 'testFail', { code: Code.fromAsset('verify'), handler: 'iam-query.handler', runtime: Runtime.NODEJS_12_X, - environment: { APPSYNC_ENDPOINT: api.graphqlUrl }, + environment: { APPSYNC_ENDPOINT: api.graphQlUrl }, }); app.synth(); diff --git a/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.ts b/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.ts index 8cb3daafab11a..8bde313c6f724 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.ts +++ b/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.ts @@ -29,7 +29,7 @@ const node = schema.addType(new appsync.InterfaceType('Node', { }, })); -const api = new appsync.GraphqlApi(stack, 'code-first-api', { +const api = new appsync.GraphQLApi(stack, 'code-first-api', { name: 'api', schema: schema, }); diff --git a/packages/@aws-cdk/aws-appsync/test/integ.graphql.ts b/packages/@aws-cdk/aws-appsync/test/integ.graphql.ts index 1de80995c90a0..9882fead1cf12 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.graphql.ts +++ b/packages/@aws-cdk/aws-appsync/test/integ.graphql.ts @@ -4,7 +4,7 @@ import { AttributeType, BillingMode, Table } from '@aws-cdk/aws-dynamodb'; import { App, RemovalPolicy, Stack } from '@aws-cdk/core'; import { AuthorizationType, - GraphqlApi, + GraphQLApi, KeyCondition, MappingTemplate, PrimaryKey, @@ -33,7 +33,7 @@ const userPool = new UserPool(stack, 'Pool', { userPoolName: 'myPool', }); -const api = new GraphqlApi(stack, 'Api', { +const api = new GraphQLApi(stack, 'Api', { name: 'demoapi', schema: Schema.fromAsset(join(__dirname, 'integ.graphql.graphql')), authorizationConfig: { From 4f32d9da46b6892b4f4bd2cf98466bcfed99ff4d Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Fri, 4 Sep 2020 14:07:01 -0700 Subject: [PATCH 5/9] integ changes --- .../aws-appsync/test/integ.graphql-schema.expected.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.expected.json b/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.expected.json index 27a7eefce492d..32b65b1d6b093 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.expected.json +++ b/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.expected.json @@ -16,7 +16,7 @@ "ApiId" ] }, - "Definition": "schema {\n query: Query\n mutation: Mutation\n subscription: Subscription\n}\ninterface Node {\n created: String\n edited: String\n id: ID!\n}\ntype Planet {\n name: String\n diameter: Int\n rotationPeriod: Int\n orbitalPeriod: Int\n gravity: String\n population: [String]\n climates: [String]\n terrains: [String]\n surfaceWater: Float\n created: String\n edited: String\n id: ID!\n}\ntype Species implements Node {\n name: String\n classification: String\n designation: String\n averageHeight: Float\n averageLifespan: Int\n eyeColors: [String]\n hairColors: [String]\n skinColors: [String]\n language: String\n homeworld: Planet\n created: String\n edited: String\n id: ID!\n}\ntype Query {\n getPlanets: [Planet]\n}\ntype Mutation {\n addPlanet(name: String diameter: Int rotationPeriod: Int orbitalPeriod: Int gravity: String population: [String] climates: [String] terrains: [String] surfaceWater: Float): Planet\n}\ntype Subscription {\n addedPlanets(id: ID!): Planet\n}\n" + "Definition": "schema {\n query: Query\n mutation: Mutation\n subscription: Subscription\n}\ninterface Node {\n created: String\n edited: String\n id: ID!\n}\ntype Planet {\n name: String\n diameter: Int\n rotationPeriod: Int\n orbitalPeriod: Int\n gravity: String\n population: [String]\n climates: [String]\n terrains: [String]\n surfaceWater: Float\n created: String\n edited: String\n id: ID!\n}\ntype Species implements Node {\n name: String\n classification: String\n designation: String\n averageHeight: Float\n averageLifespan: Int\n eyeColors: [String]\n hairColors: [String]\n skinColors: [String]\n language: String\n homeworld: Planet\n created: String\n edited: String\n id: ID!\n}\ntype Query {\n getPlanets: [Planet]\n}\ntype Mutation {\n addPlanet(name: String diameter: Int rotationPeriod: Int orbitalPeriod: Int gravity: String population: [String] climates: [String] terrains: [String] surfaceWater: Float): Planet\n}\ntype Subscription {\n addedPlanets(id: ID!): Planet\n}\ninput input {\n awesomeInput: String\n}\n" } }, "codefirstapiDefaultApiKey89863A80": { From 69eb74b5fb0393a216be303afdc2520dba0ce628 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Fri, 4 Sep 2020 15:33:33 -0700 Subject: [PATCH 6/9] add directives for subscriptions --- .../@aws-cdk/aws-appsync/lib/schema-base.ts | 59 ++++++++++++++++--- packages/@aws-cdk/aws-appsync/lib/schema.ts | 4 ++ .../aws-appsync/test/appsync-schema.test.ts | 18 ++++++ .../test/integ.graphql-schema.expected.json | 2 +- .../aws-appsync/test/integ.graphql-schema.ts | 1 + 5 files changed, 74 insertions(+), 10 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/lib/schema-base.ts b/packages/@aws-cdk/aws-appsync/lib/schema-base.ts index 96e537a17d815..a639c747ca208 100644 --- a/packages/@aws-cdk/aws-appsync/lib/schema-base.ts +++ b/packages/@aws-cdk/aws-appsync/lib/schema-base.ts @@ -169,6 +169,18 @@ export interface IIntermediateType { addField(options: AddFieldOptions): void; } +interface DirectiveOptions { + /** + * The authorization type of this directive + */ + readonly mode?: AuthorizationType; + + /** + * Mutation fields for a subscription directive + */ + readonly mutationFields?: string[]; +} + /** * Directives for types * @@ -181,21 +193,21 @@ export class Directive { * Add the @aws_iam directive */ public static iam(): Directive { - return new Directive('@aws_iam', AuthorizationType.IAM); + return new Directive('@aws_iam', { mode: AuthorizationType.IAM }); } /** * Add the @aws_oidc directive */ public static oidc(): Directive { - return new Directive('@aws_oidc', AuthorizationType.OIDC); + return new Directive('@aws_oidc', { mode: AuthorizationType.OIDC }); } /** * Add the @aws_api_key directive */ public static apiKey(): Directive { - return new Directive('@aws_api_key', AuthorizationType.API_KEY); + return new Directive('@aws_api_key', { mode: AuthorizationType.API_KEY }); } /** @@ -209,9 +221,25 @@ export class Directive { } // this function creates the cognito groups as a string (i.e. ["group1", "group2", "group3"]) const stringify = (array: string[]): string => { - return array.reduce((acc, element) => `${acc}"${element}", `, '[').slice(0, -2) + ']'; + return array.reduce((acc, element) => `${acc}"${element}", `, '').slice(0, -2); + }; + return new Directive(`@aws_auth(cognito_groups: [${stringify(groups)}])`, { mode: AuthorizationType.USER_POOL }); + } + + /** + * Add the @aws_subscribe directive. Only use for top level Subscription type. + * + * @param mutations the mutation fields to link to + */ + public static subscribe(...mutations: string[]): Directive { + if (mutations.length === 0) { + throw new Error(`Subscribe directive requires at least one mutation field to be supplied. Received: ${mutations.length}`); + } + // this function creates the subscribe directive as a string (i.e. ["mutation_field_1", "mutation_field_2"]) + const stringify = (array: string[]): string => { + return array.reduce((acc, mutation) => `${acc}"${mutation}", `, '').slice(0, -2); }; - return new Directive(`@aws_auth(cognito_groups: ${stringify(groups)})`, AuthorizationType.USER_POOL); + return new Directive(`@aws_subscribe(mutations: [${stringify(mutations)}])`, { mutationFields: mutations }); } /** @@ -223,6 +251,20 @@ export class Directive { return new Directive(statement); } + /** + * The authorization type of this directive + * + * @default - not an authorization directive + */ + public readonly mode?: AuthorizationType; + + /** + * Mutation fields for a subscription directive + * + * @default - not a subscription directive + */ + public readonly mutationFields?: string[]; + /** * the directive statement */ @@ -233,11 +275,10 @@ export class Directive { */ protected modes?: AuthorizationType[]; - private readonly mode?: AuthorizationType; - - private constructor(statement: string, mode?: AuthorizationType) { + private constructor(statement: string, options?: DirectiveOptions) { this.statement = statement; - this.mode = mode; + this.mode = options?.mode; + this.mutationFields = options?.mutationFields; } /** diff --git a/packages/@aws-cdk/aws-appsync/lib/schema.ts b/packages/@aws-cdk/aws-appsync/lib/schema.ts index 1823c24d6bf96..8965625529039 100644 --- a/packages/@aws-cdk/aws-appsync/lib/schema.ts +++ b/packages/@aws-cdk/aws-appsync/lib/schema.ts @@ -173,6 +173,10 @@ export class Schema { this.subscription = new ObjectType('Subscription', { definition: {} }); this.addType(this.subscription); } + const directives = field.fieldOptions?.directives?.filter((directive) => directive.mutationFields); + if (directives && directives.length > 1) { + throw new Error(`Subscription fields must not have more than one @aws_subscribe directives. Received: ${directives.length}`); + } this.subscription.addField({ fieldName, field }); return this.subscription; } diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts index 0481dd5c913c8..4ce2978935477 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts @@ -156,6 +156,24 @@ describe('basic testing schema definition mode `code`', () => { Definition: 'schema {\n subscription: Subscription\n}\ntype Subscription {\n test: String\n}\n', }); }); + + test('definition mode `code` addSubscription w/ @aws_subscribe', () => { + // WHE + const api = new appsync.GraphqlApi(stack, 'API', { + name: 'demo', + }); + api.addSubscription('test', new appsync.ResolvableField({ + returnType: t.string, + directives: [appsync.Directive.subscribe('test1')], + })); + + const out = 'schema {\n subscription: Subscription\n}\ntype Subscription {\n test: String\n @aws_subscribe(mutations: ["test1"])\n}\n'; + + // THEN + expect(stack).toHaveResourceLike('AWS::AppSync::GraphQLSchema', { + Definition: out, + }); + }); }); describe('testing schema definition mode `file`', () => { diff --git a/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.expected.json b/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.expected.json index 32b65b1d6b093..f3fcafc1df90b 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.expected.json +++ b/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.expected.json @@ -16,7 +16,7 @@ "ApiId" ] }, - "Definition": "schema {\n query: Query\n mutation: Mutation\n subscription: Subscription\n}\ninterface Node {\n created: String\n edited: String\n id: ID!\n}\ntype Planet {\n name: String\n diameter: Int\n rotationPeriod: Int\n orbitalPeriod: Int\n gravity: String\n population: [String]\n climates: [String]\n terrains: [String]\n surfaceWater: Float\n created: String\n edited: String\n id: ID!\n}\ntype Species implements Node {\n name: String\n classification: String\n designation: String\n averageHeight: Float\n averageLifespan: Int\n eyeColors: [String]\n hairColors: [String]\n skinColors: [String]\n language: String\n homeworld: Planet\n created: String\n edited: String\n id: ID!\n}\ntype Query {\n getPlanets: [Planet]\n}\ntype Mutation {\n addPlanet(name: String diameter: Int rotationPeriod: Int orbitalPeriod: Int gravity: String population: [String] climates: [String] terrains: [String] surfaceWater: Float): Planet\n}\ntype Subscription {\n addedPlanets(id: ID!): Planet\n}\ninput input {\n awesomeInput: String\n}\n" + "Definition": "schema {\n query: Query\n mutation: Mutation\n subscription: Subscription\n}\ninterface Node {\n created: String\n edited: String\n id: ID!\n}\ntype Planet {\n name: String\n diameter: Int\n rotationPeriod: Int\n orbitalPeriod: Int\n gravity: String\n population: [String]\n climates: [String]\n terrains: [String]\n surfaceWater: Float\n created: String\n edited: String\n id: ID!\n}\ntype Species implements Node {\n name: String\n classification: String\n designation: String\n averageHeight: Float\n averageLifespan: Int\n eyeColors: [String]\n hairColors: [String]\n skinColors: [String]\n language: String\n homeworld: Planet\n created: String\n edited: String\n id: ID!\n}\ntype Query {\n getPlanets: [Planet]\n}\ntype Mutation {\n addPlanet(name: String diameter: Int rotationPeriod: Int orbitalPeriod: Int gravity: String population: [String] climates: [String] terrains: [String] surfaceWater: Float): Planet\n}\ntype Subscription {\n addedPlanets(id: ID!): Planet\n @aws_subscribe(mutations: [\"addPlanet\"])\n}\ninput input {\n awesomeInput: String\n}\n" } }, "codefirstapiDefaultApiKey89863A80": { diff --git a/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.ts b/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.ts index b90f1bc19c83a..aaeb9602edb5e 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.ts +++ b/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.ts @@ -106,6 +106,7 @@ api.addMutation('addPlanet', new appsync.ResolvableField({ api.addSubscription('addedPlanets', new appsync.ResolvableField({ returnType: planet.attribute(), args: { id: ScalarType.required_id }, + directives: [appsync.Directive.subscribe('addPlanet')], })); api.addType(new appsync.InputType('input', { definition: { awesomeInput: ScalarType.string }, From 2b6d91540fb8ffed62cca59422cbfba26aac3da9 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Fri, 4 Sep 2020 15:37:58 -0700 Subject: [PATCH 7/9] update readme with directive --- packages/@aws-cdk/aws-appsync/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/@aws-cdk/aws-appsync/README.md b/packages/@aws-cdk/aws-appsync/README.md index 1e0c6b73e57e2..fda9b43971770 100644 --- a/packages/@aws-cdk/aws-appsync/README.md +++ b/packages/@aws-cdk/aws-appsync/README.md @@ -652,6 +652,7 @@ to the schema's `Subscription` type. api.addSubscription('addedFilm', new appsync.ResolvableField({ returnType: film.attribute(), args: { id: appsync.GraphqlType.id({ isRequired: true }) }, + directive: [appsync.Directive.subscribe('addFilm')], })); ``` From 5b3e44dd30e29092ec57df433d92b1dd0c555c3e Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Wed, 9 Sep 2020 09:46:09 -0700 Subject: [PATCH 8/9] edit readme --- packages/@aws-cdk/aws-appsync/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/README.md b/packages/@aws-cdk/aws-appsync/README.md index fda9b43971770..4447af5c46cb0 100644 --- a/packages/@aws-cdk/aws-appsync/README.md +++ b/packages/@aws-cdk/aws-appsync/README.md @@ -640,8 +640,9 @@ To learn more about top level operations, check out the docs [here](https://docs #### Subscription Every schema **can** have a top level Subscription type. The top level `Subscription` Type -is the only exposed type that users can access to invoke a response to a mutation. This means -you can make any data source real time by specificy a GraphQL Schema directive on a mutation. +is the only exposed type that users can access to invoke a response to a mutation. `Subscriptions` +notify users when a mutation specific mutation is called. This means you can make any data source +real time by specificy a GraphQL Schema directive on a mutation. **Note**: The AWS AppSync client SDK automatically handles subscription connection management. From 7495b0f4da9b08489f3e708d545272ebee8d2668 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Thu, 10 Sep 2020 13:37:42 -0700 Subject: [PATCH 9/9] address suggestions --- packages/@aws-cdk/aws-appsync/README.md | 2 +- packages/@aws-cdk/aws-appsync/lib/schema.ts | 6 +++--- packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/README.md b/packages/@aws-cdk/aws-appsync/README.md index 4447af5c46cb0..12acd0f4ac142 100644 --- a/packages/@aws-cdk/aws-appsync/README.md +++ b/packages/@aws-cdk/aws-appsync/README.md @@ -642,7 +642,7 @@ To learn more about top level operations, check out the docs [here](https://docs Every schema **can** have a top level Subscription type. The top level `Subscription` Type is the only exposed type that users can access to invoke a response to a mutation. `Subscriptions` notify users when a mutation specific mutation is called. This means you can make any data source -real time by specificy a GraphQL Schema directive on a mutation. +real time by specify a GraphQL Schema directive on a mutation. **Note**: The AWS AppSync client SDK automatically handles subscription connection management. diff --git a/packages/@aws-cdk/aws-appsync/lib/schema.ts b/packages/@aws-cdk/aws-appsync/lib/schema.ts index 8965625529039..ec5bbfa14241d 100644 --- a/packages/@aws-cdk/aws-appsync/lib/schema.ts +++ b/packages/@aws-cdk/aws-appsync/lib/schema.ts @@ -121,7 +121,7 @@ export class Schema { */ public addQuery(fieldName: string, field: ResolvableField): ObjectType { if (this.mode !== SchemaMode.CODE) { - throw new Error(`Unable to add query. Schema definition mode must be ${SchemaMode.CODE} Received: ${this.mode}`); + throw new Error(`Unable to add query. Schema definition mode must be ${SchemaMode.CODE}. Received: ${this.mode}`); } if (!this.query) { this.query = new ObjectType('Query', { definition: {} }); @@ -144,7 +144,7 @@ export class Schema { */ public addMutation(fieldName: string, field: ResolvableField): ObjectType { if (this.mode !== SchemaMode.CODE) { - throw new Error(`Unable to add mutation. Schema definition mode must be ${SchemaMode.CODE} Received: ${this.mode}`); + throw new Error(`Unable to add mutation. Schema definition mode must be ${SchemaMode.CODE}. Received: ${this.mode}`); } if (!this.mutation) { this.mutation = new ObjectType('Mutation', { definition: {} }); @@ -167,7 +167,7 @@ export class Schema { */ public addSubscription(fieldName: string, field: ResolvableField): ObjectType { if (this.mode !== SchemaMode.CODE) { - throw new Error(`Unable to add subscription. Schema definition mode must be ${SchemaMode.CODE} Received: ${this.mode}`); + throw new Error(`Unable to add subscription. Schema definition mode must be ${SchemaMode.CODE}. Received: ${this.mode}`); } if (!this.subscription) { this.subscription = new ObjectType('Subscription', { definition: {} }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts index 4ce2978935477..fafc4e20c2e8a 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts @@ -244,7 +244,7 @@ describe('testing schema definition mode `file`', () => { // THEN expect(() => { api.addQuery('blah', new appsync.ResolvableField({ returnType: t.string })); - }).toThrowError('Unable to add query. Schema definition mode must be CODE Received: FILE'); + }).toThrowError('Unable to add query. Schema definition mode must be CODE. Received: FILE'); }); test('definition mode `file` errors when addMutation is called', () => { @@ -257,7 +257,7 @@ describe('testing schema definition mode `file`', () => { // THEN expect(() => { api.addMutation('blah', new appsync.ResolvableField({ returnType: t.string })); - }).toThrowError('Unable to add mutation. Schema definition mode must be CODE Received: FILE'); + }).toThrowError('Unable to add mutation. Schema definition mode must be CODE. Received: FILE'); }); test('definition mode `file` errors when addSubscription is called', () => { @@ -270,6 +270,6 @@ describe('testing schema definition mode `file`', () => { // THEN expect(() => { api.addSubscription('blah', new appsync.ResolvableField({ returnType: t.string })); - }).toThrowError('Unable to add subscription. Schema definition mode must be CODE Received: FILE'); + }).toThrowError('Unable to add subscription. Schema definition mode must be CODE. Received: FILE'); }); }); \ No newline at end of file