createResolver method

Future<CreateResolverResponse> createResolver({
  1. required String apiId,
  2. required String fieldName,
  3. required String typeName,
  4. CachingConfig? cachingConfig,
  5. String? dataSourceName,
  6. ResolverKind? kind,
  7. PipelineConfig? pipelineConfig,
  8. String? requestMappingTemplate,
  9. String? responseMappingTemplate,
  10. 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 ConcurrentModificationException. May throw NotFoundException. May throw UnauthorizedException. May throw InternalFailureException.

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 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. A UNIT resolver enables you to execute a GraphQL query against a single data source.
  • PIPELINE: A PIPELINE resolver type. A PIPELINE resolver enables you to execute a series of Function in a serial manner. You can use a pipeline resolver to execute a GraphQL query against multiple data sources.

Parameter pipelineConfig : The PipelineConfig.

Parameter requestMappingTemplate : The mapping template to be used 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 a Lambda data source. For all other data sources, VTL request and response mapping templates are required.

Parameter responseMappingTemplate : The mapping template to be used for responses from the data source.

Parameter syncConfig : The SyncConfig for a resolver attached to a versioned datasource.

Implementation

Future<CreateResolverResponse> createResolver({
  required String apiId,
  required String fieldName,
  required String typeName,
  CachingConfig? cachingConfig,
  String? dataSourceName,
  ResolverKind? kind,
  PipelineConfig? pipelineConfig,
  String? requestMappingTemplate,
  String? responseMappingTemplate,
  SyncConfig? syncConfig,
}) async {
  ArgumentError.checkNotNull(apiId, 'apiId');
  ArgumentError.checkNotNull(fieldName, 'fieldName');
  _s.validateStringLength(
    'fieldName',
    fieldName,
    1,
    65536,
    isRequired: true,
  );
  ArgumentError.checkNotNull(typeName, 'typeName');
  _s.validateStringLength(
    'typeName',
    typeName,
    1,
    65536,
    isRequired: true,
  );
  _s.validateStringLength(
    'dataSourceName',
    dataSourceName,
    1,
    65536,
  );
  _s.validateStringLength(
    'requestMappingTemplate',
    requestMappingTemplate,
    1,
    65536,
  );
  _s.validateStringLength(
    'responseMappingTemplate',
    responseMappingTemplate,
    1,
    65536,
  );
  final $payload = <String, dynamic>{
    'fieldName': fieldName,
    if (cachingConfig != null) 'cachingConfig': cachingConfig,
    if (dataSourceName != null) 'dataSourceName': dataSourceName,
    if (kind != null) 'kind': kind.toValue(),
    if (pipelineConfig != null) 'pipelineConfig': pipelineConfig,
    if (requestMappingTemplate != null)
      'requestMappingTemplate': requestMappingTemplate,
    if (responseMappingTemplate != null)
      'responseMappingTemplate': responseMappingTemplate,
    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);
}