createFunction method

Future<CreateFunctionResponse> createFunction({
  1. required String apiId,
  2. required String dataSourceName,
  3. required String name,
  4. String? code,
  5. String? description,
  6. String? functionVersion,
  7. int? maxBatchSize,
  8. String? requestMappingTemplate,
  9. String? responseMappingTemplate,
  10. AppSyncRuntime? runtime,
  11. SyncConfig? syncConfig,
})

Creates a Function object.

A function is a reusable entity. You can use multiple functions to compose the resolver logic.

May throw BadRequestException. May throw ConcurrentModificationException. May throw InternalFailureException. May throw NotFoundException. May throw UnauthorizedException.

Parameter apiId : The GraphQL API ID.

Parameter dataSourceName : The Function DataSource name.

Parameter name : The Function name. The function name does not have to be unique.

Parameter code : The function code that contains the request and response functions. When code is used, the runtime is required. The runtime value must be APPSYNC_JS.

Parameter description : The Function description.

Parameter functionVersion : The version of the request mapping template. Currently, the supported value is 2018-05-29. Note that when using VTL and mapping templates, the functionVersion is required.

Parameter maxBatchSize : The maximum batching size for a resolver.

Parameter requestMappingTemplate : The Function request mapping template. Functions support only the 2018-05-29 version of the request mapping template.

Parameter responseMappingTemplate : The Function response mapping template.

Implementation

Future<CreateFunctionResponse> createFunction({
  required String apiId,
  required String dataSourceName,
  required String name,
  String? code,
  String? description,
  String? functionVersion,
  int? maxBatchSize,
  String? requestMappingTemplate,
  String? responseMappingTemplate,
  AppSyncRuntime? runtime,
  SyncConfig? syncConfig,
}) async {
  _s.validateNumRange(
    'maxBatchSize',
    maxBatchSize,
    0,
    2000,
  );
  final $payload = <String, dynamic>{
    'dataSourceName': dataSourceName,
    'name': name,
    if (code != null) 'code': code,
    if (description != null) 'description': description,
    if (functionVersion != null) 'functionVersion': functionVersion,
    if (maxBatchSize != null) 'maxBatchSize': maxBatchSize,
    if (requestMappingTemplate != null)
      'requestMappingTemplate': requestMappingTemplate,
    if (responseMappingTemplate != null)
      'responseMappingTemplate': responseMappingTemplate,
    if (runtime != null) 'runtime': runtime,
    if (syncConfig != null) 'syncConfig': syncConfig,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri: '/v1/apis/${Uri.encodeComponent(apiId)}/functions',
    exceptionFnMap: _exceptionFns,
  );
  return CreateFunctionResponse.fromJson(response);
}