Skip to content

Commit 2bd1e41

Browse files
chore(appsync): removes codefirst schema generation (#23250)
Removes all of the code first schema generation code in favor of this living in a separate module. This will make stabilizing the other constructs easier while allowing for continuing development of high level utilities within the `aws-cdk-appsync-utilities` library. BREAKING CHANGE: Renames `Schema` to `SchemaFile` that implements `ISchema`. Removes all `addXxx` type methods from `GraphQlApi`. ---- ### All Submissions: * [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Construct Runtime Dependencies: * [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent bb0de2b commit 2bd1e41

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+139
-4408
lines changed

packages/@aws-cdk/aws-appsync/README.md

Lines changed: 12 additions & 556 deletions
Large diffs are not rendered by default.

packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts

Lines changed: 5 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ import { ArnFormat, CfnResource, Duration, Expiration, IResolvable, Stack } from
77
import { Construct } from 'constructs';
88
import { CfnApiKey, CfnGraphQLApi, CfnGraphQLSchema, CfnDomainName, CfnDomainNameApiAssociation } from './appsync.generated';
99
import { IGraphqlApi, GraphqlApiBase } from './graphqlapi-base';
10-
import { Schema } from './schema';
11-
import { IIntermediateType } from './schema-base';
12-
import { ResolvableField } from './schema-field';
13-
import { ObjectType } from './schema-intermediate';
10+
import { ISchema } from './schema';
1411

1512
/**
1613
* enum with all possible values for AppSync authorization type
@@ -307,7 +304,7 @@ export interface GraphqlApiProps {
307304
* @default - schema will be generated code-first (i.e. addType, addObjectType, etc.)
308305
*
309306
*/
310-
readonly schema?: Schema;
307+
readonly schema: ISchema;
311308
/**
312309
* A flag indicating whether or not X-Ray tracing is enabled for the GraphQL API.
313310
*
@@ -456,7 +453,7 @@ export class GraphqlApi extends GraphqlApiBase {
456453
/**
457454
* the schema attached to this api
458455
*/
459-
public readonly schema: Schema;
456+
public readonly schema: ISchema;
460457

461458
/**
462459
* The Authorization Types for this GraphQL Api
@@ -507,8 +504,8 @@ export class GraphqlApi extends GraphqlApiBase {
507504
this.arn = this.api.attrArn;
508505
this.graphqlUrl = this.api.attrGraphQlUrl;
509506
this.name = this.api.name;
510-
this.schema = props.schema ?? new Schema();
511-
this.schemaResource = this.schema.bind(this);
507+
this.schema = props.schema;
508+
this.schemaResource = new CfnGraphQLSchema(this, 'Schema', this.schema.bind(this));
512509

513510
if (props.domainName) {
514511
this.domainNameResource = new CfnDomainName(this, 'DomainName', {
@@ -707,75 +704,6 @@ export class GraphqlApi extends GraphqlApiBase {
707704
});
708705
}
709706

710-
/**
711-
* Escape hatch to append to Schema as desired. Will always result
712-
* in a newline.
713-
*
714-
* @param addition the addition to add to schema
715-
* @param delimiter the delimiter between schema and addition
716-
* @default - ''
717-
*
718-
*/
719-
public addToSchema(addition: string, delimiter?: string): void {
720-
this.schema.addToSchema(addition, delimiter);
721-
}
722-
723-
/**
724-
* Add type to the schema
725-
*
726-
* @param type the intermediate type to add to the schema
727-
*
728-
*/
729-
public addType(type: IIntermediateType): IIntermediateType {
730-
return this.schema.addType(type);
731-
}
732-
733-
/**
734-
* Add a query field to the schema's Query. CDK will create an
735-
* Object Type called 'Query'. For example,
736-
*
737-
* type Query {
738-
* fieldName: Field.returnType
739-
* }
740-
*
741-
* @param fieldName the name of the query
742-
* @param field the resolvable field to for this query
743-
*/
744-
public addQuery(fieldName: string, field: ResolvableField): ObjectType {
745-
return this.schema.addQuery(fieldName, field);
746-
}
747-
748-
/**
749-
* Add a mutation field to the schema's Mutation. CDK will create an
750-
* Object Type called 'Mutation'. For example,
751-
*
752-
* type Mutation {
753-
* fieldName: Field.returnType
754-
* }
755-
*
756-
* @param fieldName the name of the Mutation
757-
* @param field the resolvable field to for this Mutation
758-
*/
759-
public addMutation(fieldName: string, field: ResolvableField): ObjectType {
760-
return this.schema.addMutation(fieldName, field);
761-
}
762-
763-
/**
764-
* Add a subscription field to the schema's Subscription. CDK will create an
765-
* Object Type called 'Subscription'. For example,
766-
*
767-
* type Subscription {
768-
* fieldName: Field.returnType
769-
* }
770-
*
771-
* @param fieldName the name of the Subscription
772-
* @param field the resolvable field to for this Subscription
773-
*/
774-
public addSubscription(fieldName: string, field: ResolvableField): ObjectType {
775-
return this.schema.addSubscription(fieldName, field);
776-
}
777-
778-
779707
/**
780708
* The AppSyncDomainName of the associated custom domain
781709
*/

packages/@aws-cdk/aws-appsync/lib/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,5 @@ export * from './data-source';
88
export * from './mapping-template';
99
export * from './resolver';
1010
export * from './schema';
11-
export * from './schema-intermediate';
12-
export * from './schema-field';
13-
export * from './schema-base';
1411
export * from './graphqlapi';
1512
export * from './graphqlapi-base';
Lines changed: 0 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,3 @@
1-
import { AuthorizationType } from './graphqlapi';
2-
import { Directive } from './schema-base';
3-
import { InterfaceType } from './schema-intermediate';
4-
5-
/**
6-
* Utility enum for Schema class
7-
*/
8-
export enum SchemaMode {
9-
FILE = 'FILE',
10-
CODE = 'CODE',
11-
};
12-
13-
/**
14-
* Generates an addition to the schema
15-
*
16-
* ```
17-
* prefix name interfaces directives {
18-
* field
19-
* field
20-
* ...
21-
* }
22-
* ```
23-
*/
24-
export interface SchemaAdditionOptions {
25-
/**
26-
* the prefix for this additon (type, interface, enum, input, schema)
27-
*/
28-
readonly prefix: string;
29-
/**
30-
* the name for this addition (some additions dont need this [i.e. schema])
31-
*
32-
* @default - no name
33-
*/
34-
readonly name?: string;
35-
/**
36-
* the interface types if this is creating an object type
37-
*
38-
* @default - no interfaces
39-
*/
40-
readonly interfaceTypes?: InterfaceType[];
41-
/**
42-
* the directives for this type
43-
*
44-
* @default - no directives
45-
*/
46-
readonly directives?: Directive[];
47-
/**
48-
* the fields to reduce onto the addition
49-
*/
50-
readonly fields: string[];
51-
/**
52-
* the authorization modes for this graphql type
53-
*/
54-
readonly modes?: AuthorizationType[];
55-
}
56-
57-
/**
58-
* Generates an addition to the schema
59-
*
60-
* @param options the options to produced a stringfied addition
61-
*
62-
* @returns the following shape:
63-
*
64-
* ```
65-
* prefix name interfaces directives {
66-
* field
67-
* field
68-
* ...
69-
* }
70-
* ```
71-
*/
72-
export function shapeAddition(options: SchemaAdditionOptions): string {
73-
const typeName = (): string => { return options.name ? ` ${options.name}` : ''; };
74-
const interfaces = generateInterfaces(options.interfaceTypes);
75-
const directives = generateDirectives({
76-
directives: options.directives,
77-
modes: options.modes,
78-
});
79-
return options.fields.reduce((acc, field) =>
80-
`${acc} ${field}\n`, `${options.prefix}${typeName()}${interfaces}${directives} {\n`) + '}';
81-
}
82-
831
/**
842
* Utility class to represent DynamoDB key conditions.
853
*/
@@ -193,45 +111,3 @@ function concatAndDedup<T>(left: T[], right: T[]): T[] {
193111
return index === self.indexOf(elem);
194112
});
195113
}
196-
197-
/**
198-
* Utility function to generate interfaces for object types
199-
*
200-
* @param interfaceTypes the interfaces this object type implements
201-
*/
202-
function generateInterfaces(interfaceTypes?: InterfaceType[]): string {
203-
if (!interfaceTypes || interfaceTypes.length === 0) return '';
204-
return interfaceTypes.reduce((acc, interfaceType) =>
205-
`${acc} ${interfaceType.name} &`, ' implements').slice(0, -2);
206-
}
207-
208-
/**
209-
* options to generate directives
210-
*/
211-
interface generateDirectivesOptions {
212-
/**
213-
* the directives of a given type
214-
*/
215-
readonly directives?: Directive[];
216-
/**
217-
* thee separator betweeen directives
218-
*
219-
* @default - a space
220-
*/
221-
readonly delimiter?: string;
222-
/**
223-
* the authorization modes
224-
*/
225-
readonly modes?: AuthorizationType[];
226-
}
227-
228-
/**
229-
* Utility function to generate directives
230-
*/
231-
function generateDirectives(options: generateDirectivesOptions): string {
232-
if (!options.directives || options.directives.length === 0) return '';
233-
// reduce over all directives and get string version of the directive
234-
// pass in the auth modes for checks to happen on compile time
235-
return options.directives.reduce((acc, directive) =>
236-
`${acc}${directive._bindToAuthModes(options.modes).toString()}${options.delimiter ?? ' '}`, ' ').slice(0, -1);
237-
}

0 commit comments

Comments
 (0)