Skip to content

Commit

Permalink
refactor(graphql-transformer-core): fix rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
danielleadams committed Jul 28, 2021
1 parent baf11d0 commit b07dd0a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const createSearchableDataSource = (
const { OpenSearchDataSourceLogicalID } = ResourceConstants.RESOURCES;
assert(region);
const dsEndpoint = 'https://' + domainEndpoint;
return graphqlApiProvider.addSearchableDataSource(
return graphqlApiProvider.host.addSearchableDataSource(
OpenSearchDataSourceLogicalID,
region,
dsEndpoint,
Expand Down
32 changes: 14 additions & 18 deletions packages/amplify-graphql-transformer-core/src/transform-host.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { TransformHostProvider } from '@aws-amplify/graphql-transformer-interfaces';
import {
ElasticSearchDataSourceOptions,
MappingTemplateProvider
} from '@aws-amplify/graphql-transformer-interfaces/lib/graphql-api-provider';
import { SearchableDataSourceOptions, MappingTemplateProvider } from '@aws-amplify/graphql-transformer-interfaces/lib/graphql-api-provider';
import { Duration, Stack, Token } from '@aws-cdk/core';
import { ElasticsearchDataSource } from './cdk-compat/elasticsearch-datasource';
import { SearchableDataSource } from './cdk-compat/searchable-datasource';
import {
BaseDataSource, CfnResolver,
BaseDataSource,
CfnResolver,
DataSourceOptions,
DynamoDbDataSource,
HttpDataSource,
HttpDataSourceOptions,
LambdaDataSource,
NoneDataSource
NoneDataSource,
} from '@aws-cdk/aws-appsync';
import { ITable } from '@aws-cdk/aws-dynamodb';
import { CfnFunction, Code, Function, IFunction, ILayerVersion, Runtime } from '@aws-cdk/aws-lambda';
Expand All @@ -22,14 +20,12 @@ import { InlineTemplate, S3MappingFunctionCode } from './cdk-compat/template-ass
import { toCamelCase } from 'graphql-transformer-common';
import { GraphQLApi } from './graphql-api';


export interface DefaultTransformHostOptions {
readonly api: GraphQLApi;
}


export class DefaultTransformHost implements TransformHostProvider {
private dataSources: Map<string, BaseDataSource> = new Map()
private dataSources: Map<string, BaseDataSource> = new Map();
private api: GraphQLApi;

public constructor(options: DefaultTransformHostOptions) {
Expand All @@ -49,17 +45,17 @@ export class DefaultTransformHost implements TransformHostProvider {
}
};

addElasticSearchDataSource(
addSearchableDataSource(
name: string,
awsRegion: string,
endpoint: string,
options?: ElasticSearchDataSourceOptions,
options?: SearchableDataSourceOptions,
stack?: Stack,
): ElasticsearchDataSource {
): SearchableDataSource {
if (this.dataSources.has(name)) {
throw new Error(`DataSource ${name} already exists in the API`);
}
const data = this.doAddElasticSearchDataSource(name, endpoint, awsRegion, options, stack);
const data = this.doAddSearchableDataSource(name, endpoint, awsRegion, options, stack);
this.dataSources.set(options?.name || name, data);
return data;
}
Expand Down Expand Up @@ -267,14 +263,14 @@ export class DefaultTransformHost implements TransformHostProvider {
* @param options The optional configuration for this data source
* @param stack Stack to which the elasticsearch datasource needs to be created in
*/
protected doAddElasticSearchDataSource(
protected doAddSearchableDataSource(
id: string,
endpoint: string,
region: string,
options?: ElasticSearchDataSourceOptions,
options?: SearchableDataSourceOptions,
stack?: Stack,
): ElasticsearchDataSource {
return new ElasticsearchDataSource(stack ?? this.api, id, {
): SearchableDataSource {
return new SearchableDataSource(stack ?? this.api, id, {
api: this.api,
name: options?.name,
endpoint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,30 @@ import {
GraphqlApiBase,
HttpDataSource,
LambdaDataSource,
NoneDataSource
NoneDataSource,
} from '@aws-cdk/aws-appsync';
import { ITable } from '@aws-cdk/aws-dynamodb';
import { IFunction, ILayerVersion, Runtime } from '@aws-cdk/aws-lambda';
import {
AppSyncFunctionConfigurationProvider,
DataSourceOptions,
ElasticSearchDataSourceOptions,
MappingTemplateProvider
SearchableDataSourceOptions,
MappingTemplateProvider,
} from './graphql-api-provider';
import { IRole } from '@aws-cdk/aws-iam';


export interface TransformHostProvider {
setAPI(api: GraphqlApiBase): void;

addHttpDataSource(name: string, endpoint: string, options?: DataSourceOptions, stack?: Stack): HttpDataSource;
addDynamoDbDataSource(name: string, table: ITable, options?: DataSourceOptions, stack?: Stack): DynamoDbDataSource;
addNoneDataSource(name: string, options?: DataSourceOptions, stack?: Stack): NoneDataSource;
addLambdaDataSource(name: string, lambdaFunction: IFunction, options?: DataSourceOptions, stack?: Stack): LambdaDataSource;
addElasticSearchDataSource(
addSearchableDataSource(
name: string,
endpoint: string,
region: string,
options?: ElasticSearchDataSourceOptions,
options?: SearchableDataSourceOptions,
stack?: Stack,
): BaseDataSource;

Expand Down

0 comments on commit b07dd0a

Please sign in to comment.