createResolver method
- required String apiId,
- required String fieldName,
- required String typeName,
- CachingConfig? cachingConfig,
- String? code,
- String? dataSourceName,
- ResolverKind? kind,
- int? maxBatchSize,
- ResolverLevelMetricsConfig? metricsConfig,
- PipelineConfig? pipelineConfig,
- String? requestMappingTemplate,
- String? responseMappingTemplate,
- AppSyncRuntime? runtime,
- SyncConfig? syncConfig,
Creates a Resolver object.
A resolver converts incoming requests into a format that a data source can understand, and converts the data source's responses into GraphQL.
May throw BadRequestException.
May throw ConcurrentModificationException.
May throw InternalFailureException.
May throw NotFoundException.
May throw UnauthorizedException.
Parameter apiId :
The ID for the GraphQL API for which the resolver is being created.
Parameter fieldName :
The name of the field to attach the resolver to.
Parameter typeName :
The name of the Type.
Parameter cachingConfig :
The caching configuration for the resolver.
Parameter code :
The resolver code that contains the request and response
functions. When code is used, the runtime is required. The
runtime value must be APPSYNC_JS.
Parameter dataSourceName :
The name of the data source for which the resolver is being created.
Parameter kind :
The resolver type.
- UNIT: A UNIT resolver type. A UNIT resolver is the default resolver type. You can use a UNIT resolver to run a GraphQL query against a single data source.
-
PIPELINE: A PIPELINE resolver type. You can use a PIPELINE resolver
to invoke a series of
Functionobjects in a serial manner. You can use a pipeline resolver to run a GraphQL query against multiple data sources.
Parameter maxBatchSize :
The maximum batching size for a resolver.
Parameter metricsConfig :
Enables or disables enhanced resolver metrics for specified resolvers.
Note that metricsConfig won't be used unless the
resolverLevelMetricsBehavior value is set to
PER_RESOLVER_METRICS. If the
resolverLevelMetricsBehavior is set to
FULL_REQUEST_RESOLVER_METRICS instead,
metricsConfig will be ignored. However, you can still set its
value.
metricsConfig can be ENABLED or
DISABLED.
Parameter pipelineConfig :
The PipelineConfig.
Parameter requestMappingTemplate :
The mapping template to use for requests.
A resolver uses a request mapping template to convert a GraphQL expression into a format that a data source can understand. Mapping templates are written in Apache Velocity Template Language (VTL).
VTL request mapping templates are optional when using an Lambda data source. For all other data sources, VTL request and response mapping templates are required.
Parameter responseMappingTemplate :
The mapping template to use for responses from the data source.
Parameter syncConfig :
The SyncConfig for a resolver attached to a versioned data
source.
Implementation
Future<CreateResolverResponse> createResolver({
required String apiId,
required String fieldName,
required String typeName,
CachingConfig? cachingConfig,
String? code,
String? dataSourceName,
ResolverKind? kind,
int? maxBatchSize,
ResolverLevelMetricsConfig? metricsConfig,
PipelineConfig? pipelineConfig,
String? requestMappingTemplate,
String? responseMappingTemplate,
AppSyncRuntime? runtime,
SyncConfig? syncConfig,
}) async {
_s.validateNumRange(
'maxBatchSize',
maxBatchSize,
0,
2000,
);
final $payload = <String, dynamic>{
'fieldName': fieldName,
if (cachingConfig != null) 'cachingConfig': cachingConfig,
if (code != null) 'code': code,
if (dataSourceName != null) 'dataSourceName': dataSourceName,
if (kind != null) 'kind': kind.value,
if (maxBatchSize != null) 'maxBatchSize': maxBatchSize,
if (metricsConfig != null) 'metricsConfig': metricsConfig.value,
if (pipelineConfig != null) 'pipelineConfig': pipelineConfig,
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)}/types/${Uri.encodeComponent(typeName)}/resolvers',
exceptionFnMap: _exceptionFns,
);
return CreateResolverResponse.fromJson(response);
}