createFunction method

Future<CreateFunctionResponse> createFunction({
  1. required String apiId,
  2. required String dataSourceName,
  3. required String functionVersion,
  4. required String name,
  5. String? description,
  6. String? requestMappingTemplate,
  7. String? responseMappingTemplate,
})

Creates a Function object.

A function is a reusable entity. Multiple functions can be used to compose the resolver logic.

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

Parameter apiId : The GraphQL API ID.

Parameter dataSourceName : The Function DataSource name.

Parameter functionVersion : The version of the request mapping template. Currently the supported value is 2018-05-29.

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

Parameter description : The Function description.

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 functionVersion,
  required String name,
  String? description,
  String? requestMappingTemplate,
  String? responseMappingTemplate,
}) async {
  ArgumentError.checkNotNull(apiId, 'apiId');
  ArgumentError.checkNotNull(dataSourceName, 'dataSourceName');
  _s.validateStringLength(
    'dataSourceName',
    dataSourceName,
    1,
    65536,
    isRequired: true,
  );
  ArgumentError.checkNotNull(functionVersion, 'functionVersion');
  ArgumentError.checkNotNull(name, 'name');
  _s.validateStringLength(
    'name',
    name,
    1,
    65536,
    isRequired: true,
  );
  _s.validateStringLength(
    'requestMappingTemplate',
    requestMappingTemplate,
    1,
    65536,
  );
  _s.validateStringLength(
    'responseMappingTemplate',
    responseMappingTemplate,
    1,
    65536,
  );
  final $payload = <String, dynamic>{
    'dataSourceName': dataSourceName,
    'functionVersion': functionVersion,
    'name': name,
    if (description != null) 'description': description,
    if (requestMappingTemplate != null)
      'requestMappingTemplate': requestMappingTemplate,
    if (responseMappingTemplate != null)
      'responseMappingTemplate': responseMappingTemplate,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri: '/v1/apis/${Uri.encodeComponent(apiId)}/functions',
    exceptionFnMap: _exceptionFns,
  );
  return CreateFunctionResponse.fromJson(response);
}