-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Closed
Labels
@aws-cdk/aws-appsyncRelated to AWS AppSyncRelated to AWS AppSynceffort/largeLarge work item – several weeks of effortLarge work item – several weeks of effortfeature-requestA feature should be added or improved.A feature should be added or improved.management/trackingIssues that track a subject or multiple issuesIssues that track a subject or multiple issuesp2
Description
Allow definition of the schema to happen within the cdk stack. The generated schema would be directly inserted into the CloudFormation Template at runtime.
Use Case
Currently there are only two ways to define schema: ,inline or with a file.
Inline
const inlineSchemaDefintion = `
...
`;
const api = new appsync.GraphQLApi(stack, 'api', {
name: 'api',
schemaDefinition: `${inlineSchemaDefinition}`,
});File
const api = new appsync.GraphQLApi(stack, 'api', {
name: 'api',
schemaDefinitionFile: join(__dirname, 'schema.graphql'),
});A code-first approach would allow for definition of the GraphQL schema to happen inline alongside resolvers.
Proposed Solution
Write the schema definition along with the resolvers inline.
Implementation
const api = new GraphQLApi(stack, 'ExampleApi', {
name: 'example',
schemaDefinition: SCHEMA.CODE,
...
}
const exampleTable = new db.Table(...);
const exampleDS = api.addDynamoDbDataSource('exampleDataSource', 'Table for Demos', exampleTable);
// NEW IMPLEMENTATION STARTS HERE
// Defining attribute types (i.e. Int! and String!)
const t_int_r = AttributeType.int().required();
const t_string_r = AttributeType.string().required();
// Defining Object Type ( i.e. type Example @aws_iam { id: Int! content: String! } )
const example = api.addType('Example', {
definition: {
id: t_int_r,
content: t_string_r,
},
directives: Directives.iam(),
});
// Defining the attribute type for the Object Type 'Example'
const t_example = AttributeType.object(t_example);
const t_example_l = AttributeType.object(t_example).list();
api.addQuery( 'getExamples', {
type: t_example_l,
resolve: [{
dataSource: exampleDS,
request: MappingTemplate.dynamoDbScanTable(),
response: MappingTemplate.dynamoDbResultList(),
}],
});
api.addMutation( 'addExample', {
type: t_example,
args: {
version: t_string_r,
},
resolve: [{
dataSource: exampleDS,
request: MappingTemplate.dynamoDbPutItem(PrimaryKey.partition('id').auto(), Values.projecting('example')),
response: MappingTemplate.dynamoDbResultItem(),
}],
directives: Directives.iam(),
});Other
I will be using this issue as a way to track the smaller components of this feature request and as a point of discussion for implementation.
Visit this repository to see how to generate SWAPI in a code-first approach.
Features
- in memory schema generation (pr: refactor(appsync): strongly type schema definition mode #9283)
- code-first generation of object types (issue: [aws-appsync] code-first generation of object types for schema #9307 pr: feat(appsync): code-first schema allows for object type definition #9417)
- code-first generation of queries (issue: [aws-appsync] code-first implementation of query definition #9308 pr: feat(appsync): support query & mutation generation for code-first approach #9992)
- code-first generation of mutations (issue: [aws-appsync] code-first implementation of mutation definition #9310 pr: feat(appsync): support query & mutation generation for code-first approach #9992)
- code-first generation of subscriptions (issue: [aws-appsync] code-first implementation for subscription definition #9345 pr: feat(appsync): add support for subscriptions for code-first schema generation #10078)
- code-first generation of interfaces (pr: feat(appsync): code-first schema allows for object type definition #9417)
- code-first generation of enum (pr: feat(appsync): support enumeration types for code-first approach #10023)
- code-first generation of inputs (pr: feat(appsync): support Input Types for code-first approach #10024)
- code-first generation of unions (pr: feat(appsync): support union types for code-first approach #10025)
- directives (pr: [appsync]: support directives #9879)
This is a 🚀 Feature Request
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
@aws-cdk/aws-appsyncRelated to AWS AppSyncRelated to AWS AppSynceffort/largeLarge work item – several weeks of effortLarge work item – several weeks of effortfeature-requestA feature should be added or improved.A feature should be added or improved.management/trackingIssues that track a subject or multiple issuesIssues that track a subject or multiple issuesp2