Skip to content

[aws-appsync] code-first implementation of mutation definition #9310

@BryanPan342

Description

@BryanPan342

Allow mutation definition for schema.

Use Case

Would allow for definition of mutation type fields alongside resolvers for a code-first approach.

Proposed Solution

const api = new GraphQLApi(stack, 'ExampleApi', {
  name: 'example',
  schemaDefinition: SCHEMA.CODE,
  ...
}

const example = api.addType('Example', {
  definition: {
    ScalarType.int('id').required(),
    ScalarType.string('content').required(), 
  },
  authorization: AUTH.AWS_IAM,
});

api.addMutation( 'addExample', {
  type: ObjectType.custom(example),
  args: {
    version: {
      type: type.string(),
      required: true,
    },
  },
  resolve: [{
    dataSource: exampleDS,
    request: MappingTemplate.dynamoDbPutItem(PrimaryKey.partition('id').auto(), Values.projecting('example')),
    response: MappingTemplate.dynamoDbResultItem(),
  }],
  authorization: AUTH.AWS_IAM,
});

Mutation is defined through a code-first approach and resolvers are mapped inline.

Other

Tracked by: #9305


This is a 🚀 Feature Request

Metadata

Metadata

Labels

@aws-cdk/aws-appsyncRelated to AWS AppSynceffort/mediumMedium work item – several days of effortfeature-requestA feature should be added or improved.in-progressThis issue is being actively worked on.p2

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions