@aws-amplify/graphql-searchable-transformer
Advanced tools
Comparing version 0.8.0-beta.2 to 0.9.1-graphql-vnext-dev-preview.12
150
CHANGELOG.md
@@ -6,17 +6,21 @@ # Change Log | ||
# [0.8.0-beta.2](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-searchable-transformer@0.8.0-beta.1...@aws-amplify/graphql-searchable-transformer@0.8.0-beta.2) (2021-11-10) | ||
## [0.9.1-graphql-vnext-dev-preview.12](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-searchable-transformer@0.7.0...@aws-amplify/graphql-searchable-transformer@0.9.1-graphql-vnext-dev-preview.12) (2021-11-15) | ||
**Note:** Version bump only for package @aws-amplify/graphql-searchable-transformer | ||
### Bug Fixes | ||
* append apiKey if global auth is enabled and its not default auth ([#8843](https://github.com/aws-amplify/amplify-cli/issues/8843)) ([c54070c](https://github.com/aws-amplify/amplify-cli/commit/c54070c4b940fab7ed9f172417ee2d3e5c91f602)) | ||
* **graphql:** add enum to aggregate field type ([#8846](https://github.com/aws-amplify/amplify-cli/issues/8846)) ([f7a580f](https://github.com/aws-amplify/amplify-cli/commit/f7a580fa217a71d4dedcad22b9cb7137fd4dbba9)) | ||
# [0.8.0-beta.1](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-searchable-transformer@0.8.0-beta.0...@aws-amplify/graphql-searchable-transformer@0.8.0-beta.1) (2021-11-06) | ||
## [0.9.1-graphql-vnext-dev-preview.11](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-searchable-transformer@0.7.0...@aws-amplify/graphql-searchable-transformer@0.9.1-graphql-vnext-dev-preview.11) (2021-11-15) | ||
### Bug Fixes | ||
* **graphql-model-transformer:** override resource logical id to fix v1 to v2 transformer migration ([#8597](https://github.com/aws-amplify/amplify-cli/issues/8597)) ([e3a2afb](https://github.com/aws-amplify/amplify-cli/commit/e3a2afbbed6e97f143fc7c83064e2193f4c91bdd)) | ||
* searchable fix and migration e2e tests ([#8666](https://github.com/aws-amplify/amplify-cli/issues/8666)) ([d5f9397](https://github.com/aws-amplify/amplify-cli/commit/d5f9397fa860f32e748f6f880929b1e5856a68e2)) | ||
* append apiKey if global auth is enabled and its not default auth ([#8843](https://github.com/aws-amplify/amplify-cli/issues/8843)) ([c54070c](https://github.com/aws-amplify/amplify-cli/commit/c54070c4b940fab7ed9f172417ee2d3e5c91f602)) | ||
* **graphql:** add enum to aggregate field type ([#8846](https://github.com/aws-amplify/amplify-cli/issues/8846)) ([f7a580f](https://github.com/aws-amplify/amplify-cli/commit/f7a580fa217a71d4dedcad22b9cb7137fd4dbba9)) | ||
@@ -27,3 +31,3 @@ | ||
# [0.8.0-beta.0](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-searchable-transformer@0.6.3...@aws-amplify/graphql-searchable-transformer@0.8.0-beta.0) (2021-10-29) | ||
## [0.9.1-graphql-vnext-dev-preview.10](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-searchable-transformer@0.7.0...@aws-amplify/graphql-searchable-transformer@0.9.1-graphql-vnext-dev-preview.10) (2021-11-15) | ||
@@ -33,6 +37,140 @@ | ||
* append apiKey if global auth is enabled and its not default auth ([#8843](https://github.com/aws-amplify/amplify-cli/issues/8843)) ([c54070c](https://github.com/aws-amplify/amplify-cli/commit/c54070c4b940fab7ed9f172417ee2d3e5c91f602)) | ||
* **graphql:** add enum to aggregate field type ([#8846](https://github.com/aws-amplify/amplify-cli/issues/8846)) ([f7a580f](https://github.com/aws-amplify/amplify-cli/commit/f7a580fa217a71d4dedcad22b9cb7137fd4dbba9)) | ||
## [0.9.1-graphql-vnext-dev-preview.9](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-searchable-transformer@0.7.0...@aws-amplify/graphql-searchable-transformer@0.9.1-graphql-vnext-dev-preview.9) (2021-11-15) | ||
### Bug Fixes | ||
* append apiKey if global auth is enabled and its not default auth ([#8843](https://github.com/aws-amplify/amplify-cli/issues/8843)) ([c54070c](https://github.com/aws-amplify/amplify-cli/commit/c54070c4b940fab7ed9f172417ee2d3e5c91f602)) | ||
* **graphql:** add enum to aggregate field type ([#8846](https://github.com/aws-amplify/amplify-cli/issues/8846)) ([f7a580f](https://github.com/aws-amplify/amplify-cli/commit/f7a580fa217a71d4dedcad22b9cb7137fd4dbba9)) | ||
## [0.9.1-graphql-vnext-dev-preview.8](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-searchable-transformer@0.7.0...@aws-amplify/graphql-searchable-transformer@0.9.1-graphql-vnext-dev-preview.8) (2021-11-15) | ||
### Bug Fixes | ||
* append apiKey if global auth is enabled and its not default auth ([#8843](https://github.com/aws-amplify/amplify-cli/issues/8843)) ([c54070c](https://github.com/aws-amplify/amplify-cli/commit/c54070c4b940fab7ed9f172417ee2d3e5c91f602)) | ||
* **graphql:** add enum to aggregate field type ([#8846](https://github.com/aws-amplify/amplify-cli/issues/8846)) ([f7a580f](https://github.com/aws-amplify/amplify-cli/commit/f7a580fa217a71d4dedcad22b9cb7137fd4dbba9)) | ||
## [0.9.1-graphql-vnext-dev-preview.7](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-searchable-transformer@0.7.0...@aws-amplify/graphql-searchable-transformer@0.9.1-graphql-vnext-dev-preview.7) (2021-11-15) | ||
### Bug Fixes | ||
* append apiKey if global auth is enabled and its not default auth ([#8843](https://github.com/aws-amplify/amplify-cli/issues/8843)) ([c54070c](https://github.com/aws-amplify/amplify-cli/commit/c54070c4b940fab7ed9f172417ee2d3e5c91f602)) | ||
* **graphql:** add enum to aggregate field type ([#8846](https://github.com/aws-amplify/amplify-cli/issues/8846)) ([f7a580f](https://github.com/aws-amplify/amplify-cli/commit/f7a580fa217a71d4dedcad22b9cb7137fd4dbba9)) | ||
## [0.9.1-graphql-vnext-dev-preview.6](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-searchable-transformer@0.7.0...@aws-amplify/graphql-searchable-transformer@0.9.1-graphql-vnext-dev-preview.6) (2021-11-15) | ||
### Bug Fixes | ||
* append apiKey if global auth is enabled and its not default auth ([#8843](https://github.com/aws-amplify/amplify-cli/issues/8843)) ([c54070c](https://github.com/aws-amplify/amplify-cli/commit/c54070c4b940fab7ed9f172417ee2d3e5c91f602)) | ||
* **graphql:** add enum to aggregate field type ([#8846](https://github.com/aws-amplify/amplify-cli/issues/8846)) ([f7a580f](https://github.com/aws-amplify/amplify-cli/commit/f7a580fa217a71d4dedcad22b9cb7137fd4dbba9)) | ||
## [0.9.1-graphql-vnext-dev-preview.5](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-searchable-transformer@0.7.0...@aws-amplify/graphql-searchable-transformer@0.9.1-graphql-vnext-dev-preview.5) (2021-11-15) | ||
### Bug Fixes | ||
* append apiKey if global auth is enabled and its not default auth ([#8843](https://github.com/aws-amplify/amplify-cli/issues/8843)) ([c54070c](https://github.com/aws-amplify/amplify-cli/commit/c54070c4b940fab7ed9f172417ee2d3e5c91f602)) | ||
* **graphql:** add enum to aggregate field type ([#8846](https://github.com/aws-amplify/amplify-cli/issues/8846)) ([f7a580f](https://github.com/aws-amplify/amplify-cli/commit/f7a580fa217a71d4dedcad22b9cb7137fd4dbba9)) | ||
## [0.9.1-graphql-vnext-dev-preview.4](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-searchable-transformer@0.7.0...@aws-amplify/graphql-searchable-transformer@0.9.1-graphql-vnext-dev-preview.4) (2021-11-15) | ||
### Bug Fixes | ||
* append apiKey if global auth is enabled and its not default auth ([#8843](https://github.com/aws-amplify/amplify-cli/issues/8843)) ([c54070c](https://github.com/aws-amplify/amplify-cli/commit/c54070c4b940fab7ed9f172417ee2d3e5c91f602)) | ||
* **graphql:** add enum to aggregate field type ([#8846](https://github.com/aws-amplify/amplify-cli/issues/8846)) ([f7a580f](https://github.com/aws-amplify/amplify-cli/commit/f7a580fa217a71d4dedcad22b9cb7137fd4dbba9)) | ||
## [0.9.1-graphql-vnext-dev-preview.3](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-searchable-transformer@0.7.0...@aws-amplify/graphql-searchable-transformer@0.9.1-graphql-vnext-dev-preview.3) (2021-11-15) | ||
### Bug Fixes | ||
* append apiKey if global auth is enabled and its not default auth ([#8843](https://github.com/aws-amplify/amplify-cli/issues/8843)) ([c54070c](https://github.com/aws-amplify/amplify-cli/commit/c54070c4b940fab7ed9f172417ee2d3e5c91f602)) | ||
* **graphql:** add enum to aggregate field type ([#8846](https://github.com/aws-amplify/amplify-cli/issues/8846)) ([f7a580f](https://github.com/aws-amplify/amplify-cli/commit/f7a580fa217a71d4dedcad22b9cb7137fd4dbba9)) | ||
## [0.9.1-graphql-vnext-dev-preview.2](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-searchable-transformer@0.7.0...@aws-amplify/graphql-searchable-transformer@0.9.1-graphql-vnext-dev-preview.2) (2021-11-15) | ||
### Bug Fixes | ||
* append apiKey if global auth is enabled and its not default auth ([#8843](https://github.com/aws-amplify/amplify-cli/issues/8843)) ([c54070c](https://github.com/aws-amplify/amplify-cli/commit/c54070c4b940fab7ed9f172417ee2d3e5c91f602)) | ||
* **graphql:** add enum to aggregate field type ([#8846](https://github.com/aws-amplify/amplify-cli/issues/8846)) ([f7a580f](https://github.com/aws-amplify/amplify-cli/commit/f7a580fa217a71d4dedcad22b9cb7137fd4dbba9)) | ||
## [0.9.1-graphql-vnext-dev-preview.1](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-searchable-transformer@0.7.0...@aws-amplify/graphql-searchable-transformer@0.9.1-graphql-vnext-dev-preview.1) (2021-11-15) | ||
### Bug Fixes | ||
* append apiKey if global auth is enabled and its not default auth ([#8843](https://github.com/aws-amplify/amplify-cli/issues/8843)) ([c54070c](https://github.com/aws-amplify/amplify-cli/commit/c54070c4b940fab7ed9f172417ee2d3e5c91f602)) | ||
* **graphql:** add enum to aggregate field type ([#8846](https://github.com/aws-amplify/amplify-cli/issues/8846)) ([f7a580f](https://github.com/aws-amplify/amplify-cli/commit/f7a580fa217a71d4dedcad22b9cb7137fd4dbba9)) | ||
## [0.9.1-graphql-vnext-dev-preview.0](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-searchable-transformer@0.7.0...@aws-amplify/graphql-searchable-transformer@0.9.1-graphql-vnext-dev-preview.0) (2021-11-15) | ||
### Bug Fixes | ||
* append apiKey if global auth is enabled and its not default auth ([#8843](https://github.com/aws-amplify/amplify-cli/issues/8843)) ([c54070c](https://github.com/aws-amplify/amplify-cli/commit/c54070c4b940fab7ed9f172417ee2d3e5c91f602)) | ||
* **graphql:** add enum to aggregate field type ([#8846](https://github.com/aws-amplify/amplify-cli/issues/8846)) ([f7a580f](https://github.com/aws-amplify/amplify-cli/commit/f7a580fa217a71d4dedcad22b9cb7137fd4dbba9)) | ||
# [0.7.0](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-searchable-transformer@0.6.3...@aws-amplify/graphql-searchable-transformer@0.7.0) (2021-11-11) | ||
### Bug Fixes | ||
* [@auth](https://github.com/auth) fix relational auth, authv2 e2e with utils and fixes ([#8450](https://github.com/aws-amplify/amplify-cli/issues/8450)) ([aa320cd](https://github.com/aws-amplify/amplify-cli/commit/aa320cd2414665a484438f0764cf68fd78caa26a)) | ||
* add field auth on aggregation queries ([#8508](https://github.com/aws-amplify/amplify-cli/issues/8508)) ([c0fa85a](https://github.com/aws-amplify/amplify-cli/commit/c0fa85a87230d631ffaf376f18f4fc3c4ec9a1f9)) | ||
* **graphql-model-transformer:** override resource logical id to fix v1 to v2 transformer migration ([#8597](https://github.com/aws-amplify/amplify-cli/issues/8597)) ([e3a2afb](https://github.com/aws-amplify/amplify-cli/commit/e3a2afbbed6e97f143fc7c83064e2193f4c91bdd)) | ||
* **graphql:** change aggregate field type to enum ([#8484](https://github.com/aws-amplify/amplify-cli/issues/8484)) ([78d1e43](https://github.com/aws-amplify/amplify-cli/commit/78d1e43fb88dcb9d4924d0acf126910a5debdfa0)) | ||
* **graphql:** searchable default sort direction ([#8481](https://github.com/aws-amplify/amplify-cli/issues/8481)) ([12c1afa](https://github.com/aws-amplify/amplify-cli/commit/12c1afa80ca7d55337cf492c4822d4ab0f31565f)) | ||
* searchable fix and migration e2e tests ([#8666](https://github.com/aws-amplify/amplify-cli/issues/8666)) ([d5f9397](https://github.com/aws-amplify/amplify-cli/commit/d5f9397fa860f32e748f6f880929b1e5856a68e2)) | ||
* update searchable agg query to work in sandbox mode ([#8560](https://github.com/aws-amplify/amplify-cli/issues/8560)) ([8a12868](https://github.com/aws-amplify/amplify-cli/commit/8a1286897a2baa10fca0d011433dec218126d1a4)) | ||
@@ -39,0 +177,0 @@ |
@@ -1,2 +0,4 @@ | ||
import { ObjectTypeDefinitionNode, InputObjectTypeDefinitionNode, DocumentNode, EnumTypeDefinitionNode } from 'graphql'; | ||
import { ObjectTypeDefinitionNode, InputObjectTypeDefinitionNode, DocumentNode, EnumTypeDefinitionNode, DirectiveNode } from 'graphql'; | ||
import { TransformerTransformSchemaStepContextProvider } from '@aws-amplify/graphql-transformer-interfaces'; | ||
export declare const AGGREGATE_TYPES: string[]; | ||
export declare function makeSearchableScalarInputObject(type: string): InputObjectTypeDefinitionNode; | ||
@@ -6,6 +8,9 @@ export declare function makeSearchableXFilterInputObject(obj: ObjectTypeDefinitionNode, document: DocumentNode): InputObjectTypeDefinitionNode; | ||
export declare function makeSearchableXSortableFieldsEnumObject(obj: ObjectTypeDefinitionNode): EnumTypeDefinitionNode; | ||
export declare function makeSearchableXAggregateFieldEnumObject(obj: ObjectTypeDefinitionNode): EnumTypeDefinitionNode; | ||
export declare function makeSearchableXAggregateFieldEnumObject(obj: ObjectTypeDefinitionNode, document: DocumentNode): EnumTypeDefinitionNode; | ||
export declare function makeSearchableXSortInputObject(obj: ObjectTypeDefinitionNode): InputObjectTypeDefinitionNode; | ||
export declare function makeSearchableAggregateTypeEnumObject(): EnumTypeDefinitionNode; | ||
export declare function makeSearchableXAggregationInputObject(obj: ObjectTypeDefinitionNode): InputObjectTypeDefinitionNode; | ||
export declare const extendTypeWithDirectives: (ctx: TransformerTransformSchemaStepContextProvider, typeName: string, directives: Array<DirectiveNode>) => void; | ||
export declare const addDirectivesToField: (ctx: TransformerTransformSchemaStepContextProvider, typeName: string, fieldName: string, directives: Array<DirectiveNode>) => void; | ||
export declare const addDirectivesToOperation: (ctx: TransformerTransformSchemaStepContextProvider, typeName: string, operationName: string, directives: Array<DirectiveNode>) => void; | ||
//# sourceMappingURL=definitions.d.ts.map |
@@ -6,5 +6,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.makeSearchableXAggregationInputObject = exports.makeSearchableAggregateTypeEnumObject = exports.makeSearchableXSortInputObject = exports.makeSearchableXAggregateFieldEnumObject = exports.makeSearchableXSortableFieldsEnumObject = exports.makeSearchableSortDirectionEnumObject = exports.makeSearchableXFilterInputObject = exports.makeSearchableScalarInputObject = void 0; | ||
exports.addDirectivesToOperation = exports.addDirectivesToField = exports.extendTypeWithDirectives = exports.makeSearchableXAggregationInputObject = exports.makeSearchableAggregateTypeEnumObject = exports.makeSearchableXSortInputObject = exports.makeSearchableXAggregateFieldEnumObject = exports.makeSearchableXSortableFieldsEnumObject = exports.makeSearchableSortDirectionEnumObject = exports.makeSearchableXFilterInputObject = exports.makeSearchableScalarInputObject = exports.AGGREGATE_TYPES = void 0; | ||
const graphql_1 = require("graphql"); | ||
const graphql_transformer_common_1 = require("graphql-transformer-common"); | ||
const assert_1 = __importDefault(require("assert")); | ||
const ID_CONDITIONS = [ | ||
@@ -30,3 +31,8 @@ 'ne', | ||
const BOOLEAN_CONDITIONS = ['eq', 'ne']; | ||
const assert_1 = __importDefault(require("assert")); | ||
exports.AGGREGATE_TYPES = [ | ||
'SearchableAggregateResult', | ||
'SearchableAggregateScalarResult', | ||
'SearchableAggregateBucketResult', | ||
'SearchableAggregateBucketResultItem', | ||
]; | ||
function makeSearchableScalarInputObject(type) { | ||
@@ -152,7 +158,7 @@ const name = graphql_transformer_common_1.SearchableResourceIDs.SearchableFilterInputTypeName(type); | ||
exports.makeSearchableXSortableFieldsEnumObject = makeSearchableXSortableFieldsEnumObject; | ||
function makeSearchableXAggregateFieldEnumObject(obj) { | ||
function makeSearchableXAggregateFieldEnumObject(obj, document) { | ||
const name = graphql_transformer_common_1.graphqlName(`Searchable${obj.name.value}AggregateField`); | ||
assert_1.default(obj.fields); | ||
const values = obj.fields | ||
.filter((field) => graphql_transformer_common_1.isScalar(field.type)) | ||
.filter((field) => graphql_transformer_common_1.isScalar(field.type) || graphql_transformer_common_1.isEnum(field.type, document)) | ||
.map((field) => ({ | ||
@@ -276,2 +282,39 @@ kind: graphql_1.Kind.ENUM_VALUE_DEFINITION, | ||
} | ||
const extendTypeWithDirectives = (ctx, typeName, directives) => { | ||
let objectTypeExtension = graphql_transformer_common_1.blankObjectExtension(typeName); | ||
objectTypeExtension = graphql_transformer_common_1.extensionWithDirectives(objectTypeExtension, directives); | ||
ctx.output.addObjectExtension(objectTypeExtension); | ||
}; | ||
exports.extendTypeWithDirectives = extendTypeWithDirectives; | ||
const addDirectivesToField = (ctx, typeName, fieldName, directives) => { | ||
var _a; | ||
const type = ctx.output.getType(typeName); | ||
if (type) { | ||
const field = (_a = type.fields) === null || _a === void 0 ? void 0 : _a.find(f => f.name.value === fieldName); | ||
if (field) { | ||
const newFields = [...type.fields.filter(f => f.name.value !== field.name.value), graphql_transformer_common_1.extendFieldWithDirectives(field, directives)]; | ||
const newType = { | ||
...type, | ||
fields: newFields, | ||
}; | ||
ctx.output.putType(newType); | ||
} | ||
} | ||
}; | ||
exports.addDirectivesToField = addDirectivesToField; | ||
const addDirectivesToOperation = (ctx, typeName, operationName, directives) => { | ||
exports.addDirectivesToField(ctx, typeName, operationName, directives); | ||
const type = ctx.output.getType(typeName); | ||
if (type) { | ||
const field = type.fields.find(f => f.name.value === operationName); | ||
if (field) { | ||
const returnFieldType = field.type; | ||
if (returnFieldType.name) { | ||
const returnTypeName = returnFieldType.name.value; | ||
exports.extendTypeWithDirectives(ctx, returnTypeName, directives); | ||
} | ||
} | ||
} | ||
}; | ||
exports.addDirectivesToOperation = addDirectivesToOperation; | ||
//# sourceMappingURL=definitions.js.map |
import { TransformerPluginBase } from '@aws-amplify/graphql-transformer-core'; | ||
import { TransformerContextProvider, TransformerSchemaVisitStepContextProvider } from '@aws-amplify/graphql-transformer-interfaces'; | ||
import { TransformerContextProvider, TransformerSchemaVisitStepContextProvider, TransformerTransformSchemaStepContextProvider } from '@aws-amplify/graphql-transformer-interfaces'; | ||
import { DirectiveNode, ObjectTypeDefinitionNode } from 'graphql'; | ||
@@ -12,2 +12,3 @@ export declare class SearchableModelTransformer extends TransformerPluginBase { | ||
object: (definition: ObjectTypeDefinitionNode, directive: DirectiveNode, ctx: TransformerSchemaVisitStepContextProvider) => void; | ||
transformSchema: (ctx: TransformerTransformSchemaStepContextProvider) => void; | ||
private generateSearchableXConnectionType; | ||
@@ -14,0 +15,0 @@ private generateSearchableAggregateTypes; |
@@ -64,3 +64,3 @@ "use strict"; | ||
const resolver = context.resolvers.generateQueryResolver(typeName, def.fieldName, graphql_transformer_common_1.ResolverResourceIDs.ElasticsearchSearchResolverResourceID(type), datasource, graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(generate_resolver_vtl_1.requestTemplate(attributeName, getNonKeywordFields(def.node), context.isProjectUsingDataStore(), type, keyFields), `${typeName}.${def.fieldName}.req.vtl`), graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(generate_resolver_vtl_1.responseTemplate(false), `${typeName}.${def.fieldName}.res.vtl`)); | ||
resolver.addToSlot('postAuth', graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(generate_resolver_vtl_1.sandboxMappingTemplate(context.resourceHelper.api.sandboxModeEnabled, fields), `${typeName}.${def.fieldName}.{slotName}.{slotIndex}.res.vtl`)); | ||
resolver.addToSlot('postAuth', graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(generate_resolver_vtl_1.sandboxMappingTemplate(context.sandboxModeEnabled, fields), `${typeName}.${def.fieldName}.{slotName}.{slotIndex}.res.vtl`)); | ||
resolver.mapToStack(stack); | ||
@@ -72,4 +72,5 @@ context.resolvers.addResolver('Search', graphql_transformer_common_1.toUpper(type), resolver); | ||
this.object = (definition, directive, ctx) => { | ||
var _a; | ||
var _a, _b, _c; | ||
const modelDirective = (_a = definition === null || definition === void 0 ? void 0 : definition.directives) === null || _a === void 0 ? void 0 : _a.find(dir => dir.name.value === 'model'); | ||
const hasAuth = (_c = (_b = definition.directives) === null || _b === void 0 ? void 0 : _b.some(dir => dir.name.value === 'auth')) !== null && _c !== void 0 ? _c : false; | ||
if (!modelDirective) { | ||
@@ -101,2 +102,6 @@ throw new graphql_transformer_core_1.InvalidDirectiveError('Types annotated with @searchable must also be annotated with @model.'); | ||
this.generateSearchableAggregateTypes(ctx); | ||
const directives = []; | ||
if (!hasAuth && ctx.sandboxModeEnabled && ctx.authConfig.defaultAuthentication.authenticationType !== 'API_KEY') { | ||
directives.push(graphql_transformer_common_1.makeDirective('aws_api_key', [])); | ||
} | ||
const queryField = graphql_transformer_common_1.makeField(fieldName, [ | ||
@@ -109,6 +114,18 @@ graphql_transformer_common_1.makeInputValueDefinition('filter', graphql_transformer_common_1.makeNamedType(`Searchable${definition.name.value}FilterInput`)), | ||
graphql_transformer_common_1.makeInputValueDefinition('aggregates', graphql_transformer_common_1.makeListType(graphql_transformer_common_1.makeNamedType(`Searchable${definition.name.value}AggregationInput`))), | ||
], graphql_transformer_common_1.makeNamedType(`Searchable${definition.name.value}Connection`)); | ||
], graphql_transformer_common_1.makeNamedType(`Searchable${definition.name.value}Connection`), directives); | ||
ctx.output.addQueryFields([queryField]); | ||
} | ||
}; | ||
this.transformSchema = (ctx) => { | ||
var _a, _b; | ||
if (ctx.sandboxModeEnabled && ctx.authConfig.defaultAuthentication.authenticationType !== 'API_KEY') { | ||
for (let aggType of definitions_1.AGGREGATE_TYPES) { | ||
const aggObject = ctx.output.getObject(aggType); | ||
const hasApiKey = (_b = (_a = aggObject.directives) === null || _a === void 0 ? void 0 : _a.some(dir => dir.name.value === 'aws_api_key')) !== null && _b !== void 0 ? _b : false; | ||
if (!hasApiKey) { | ||
definitions_1.extendTypeWithDirectives(ctx, aggType, [graphql_transformer_common_1.makeDirective('aws_api_key', [])]); | ||
} | ||
} | ||
} | ||
}; | ||
this.searchableObjectTypeDefinitions = []; | ||
@@ -235,3 +252,3 @@ } | ||
if (!ctx.output.hasType(`Searchable${definition.name.value}AggregateField`)) { | ||
const searchableXAggregationField = definitions_1.makeSearchableXAggregateFieldEnumObject(definition); | ||
const searchableXAggregationField = definitions_1.makeSearchableXAggregateFieldEnumObject(definition, ctx.inputDocument); | ||
ctx.output.addEnum(searchableXAggregationField); | ||
@@ -238,0 +255,0 @@ } |
{ | ||
"name": "@aws-amplify/graphql-searchable-transformer", | ||
"version": "0.8.0-beta.2", | ||
"version": "0.9.1-graphql-vnext-dev-preview.12", | ||
"description": "Amplfy GraphQL @searchable transformer", | ||
@@ -30,4 +30,4 @@ "repository": { | ||
"dependencies": { | ||
"@aws-amplify/graphql-transformer-core": "0.11.0-beta.1", | ||
"@aws-amplify/graphql-transformer-interfaces": "1.11.1-beta.1", | ||
"@aws-amplify/graphql-transformer-core": "0.13.0-graphql-vnext-dev-preview.12", | ||
"@aws-amplify/graphql-transformer-interfaces": "1.12.1-graphql-vnext-dev-preview.12", | ||
"@aws-cdk/aws-appsync": "~1.124.0", | ||
@@ -41,4 +41,4 @@ "@aws-cdk/aws-dynamodb": "~1.124.0", | ||
"graphql": "^14.5.8", | ||
"graphql-mapping-template": "4.19.1-beta.0", | ||
"graphql-transformer-common": "4.21.0-beta.0" | ||
"graphql-mapping-template": "4.20.1-graphql-vnext-dev-preview.12", | ||
"graphql-transformer-common": "4.22.1-graphql-vnext-dev-preview.12" | ||
}, | ||
@@ -66,3 +66,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "3466e25bda63efc7ddeee82cfa115de34f9b4554" | ||
"gitHead": "73a2c5369870c5bb2b3931517a8b17c842d14c2a" | ||
} |
@@ -53,3 +53,3 @@ import { GraphQLTransform } from '@aws-amplify/graphql-transformer-core'; | ||
expect(parse(out.schema)).toBeDefined(); | ||
expect(out.pipelineFunctions).toMatchSnapshot(); | ||
expect(out.resolvers).toMatchSnapshot(); | ||
}); | ||
@@ -333,3 +333,3 @@ | ||
} | ||
enum EmploymentType { | ||
@@ -336,0 +336,0 @@ FULLTIME |
@@ -11,2 +11,4 @@ import { | ||
EnumValueDefinitionNode, | ||
DirectiveNode, | ||
NamedTypeNode, | ||
} from 'graphql'; | ||
@@ -22,4 +24,8 @@ import { | ||
SearchableResourceIDs, | ||
blankObjectExtension, | ||
extensionWithDirectives, | ||
extendFieldWithDirectives, | ||
} from 'graphql-transformer-common'; | ||
import assert from 'assert'; | ||
import { TransformerTransformSchemaStepContextProvider } from '@aws-amplify/graphql-transformer-interfaces'; | ||
const ID_CONDITIONS = [ | ||
@@ -45,4 +51,9 @@ 'ne', | ||
const BOOLEAN_CONDITIONS = ['eq', 'ne']; | ||
import assert from 'assert'; | ||
export const AGGREGATE_TYPES = [ | ||
'SearchableAggregateResult', | ||
'SearchableAggregateScalarResult', | ||
'SearchableAggregateBucketResult', | ||
'SearchableAggregateBucketResultItem', | ||
]; | ||
export function makeSearchableScalarInputObject(type: string): InputObjectTypeDefinitionNode { | ||
@@ -200,7 +211,7 @@ const name = SearchableResourceIDs.SearchableFilterInputTypeName(type); | ||
export function makeSearchableXAggregateFieldEnumObject(obj: ObjectTypeDefinitionNode): EnumTypeDefinitionNode { | ||
export function makeSearchableXAggregateFieldEnumObject(obj: ObjectTypeDefinitionNode, document: DocumentNode): EnumTypeDefinitionNode { | ||
const name = graphqlName(`Searchable${obj.name.value}AggregateField`); | ||
assert(obj.fields); | ||
const values: EnumValueDefinitionNode[] = obj.fields | ||
.filter((field: FieldDefinitionNode) => isScalar(field.type)) | ||
.filter((field: FieldDefinitionNode) => isScalar(field.type) || isEnum(field.type, document)) | ||
.map((field: FieldDefinitionNode) => ({ | ||
@@ -342,1 +353,58 @@ kind: Kind.ENUM_VALUE_DEFINITION, | ||
} | ||
export const extendTypeWithDirectives = ( | ||
ctx: TransformerTransformSchemaStepContextProvider, | ||
typeName: string, | ||
directives: Array<DirectiveNode>, | ||
): void => { | ||
let objectTypeExtension = blankObjectExtension(typeName); | ||
objectTypeExtension = extensionWithDirectives(objectTypeExtension, directives); | ||
ctx.output.addObjectExtension(objectTypeExtension); | ||
}; | ||
export const addDirectivesToField = ( | ||
ctx: TransformerTransformSchemaStepContextProvider, | ||
typeName: string, | ||
fieldName: string, | ||
directives: Array<DirectiveNode>, | ||
) => { | ||
const type = ctx.output.getType(typeName) as ObjectTypeDefinitionNode; | ||
if (type) { | ||
const field = type.fields?.find(f => f.name.value === fieldName); | ||
if (field) { | ||
const newFields = [...type.fields!.filter(f => f.name.value !== field.name.value), extendFieldWithDirectives(field, directives)]; | ||
const newType = { | ||
...type, | ||
fields: newFields, | ||
}; | ||
ctx.output.putType(newType); | ||
} | ||
} | ||
}; | ||
export const addDirectivesToOperation = ( | ||
ctx: TransformerTransformSchemaStepContextProvider, | ||
typeName: string, | ||
operationName: string, | ||
directives: Array<DirectiveNode>, | ||
) => { | ||
// add directives to the given operation | ||
addDirectivesToField(ctx, typeName, operationName, directives); | ||
// add the directives to the result type of the operation | ||
const type = ctx.output.getType(typeName) as ObjectTypeDefinitionNode; | ||
if (type) { | ||
const field = type.fields!.find(f => f.name.value === operationName); | ||
if (field) { | ||
const returnFieldType = field.type as NamedTypeNode; | ||
if (returnFieldType.name) { | ||
const returnTypeName = returnFieldType.name.value; | ||
extendTypeWithDirectives(ctx, returnTypeName, directives); | ||
} | ||
} | ||
} | ||
}; |
@@ -6,2 +6,3 @@ import { TransformerPluginBase, InvalidDirectiveError, MappingTemplate, DirectiveWrapper } from '@aws-amplify/graphql-transformer-core'; | ||
TransformerSchemaVisitStepContextProvider, | ||
TransformerTransformSchemaStepContextProvider, | ||
} from '@aws-amplify/graphql-transformer-interfaces'; | ||
@@ -31,2 +32,3 @@ import { DynamoDbDataSource } from '@aws-cdk/aws-appsync'; | ||
ResolverResourceIDs, | ||
makeDirective, | ||
} from 'graphql-transformer-common'; | ||
@@ -44,2 +46,4 @@ import { createParametersStack as createParametersInStack } from './cdk/create-cfnParameters'; | ||
makeSearchableAggregateTypeEnumObject, | ||
AGGREGATE_TYPES, | ||
extendTypeWithDirectives, | ||
} from './definitions'; | ||
@@ -152,3 +156,3 @@ import assert from 'assert'; | ||
MappingTemplate.s3MappingTemplateFromString( | ||
sandboxMappingTemplate((context as any).resourceHelper.api.sandboxModeEnabled, fields), | ||
sandboxMappingTemplate(context.sandboxModeEnabled, fields), | ||
`${typeName}.${def.fieldName}.{slotName}.{slotIndex}.res.vtl`, | ||
@@ -166,2 +170,3 @@ ), | ||
const modelDirective = definition?.directives?.find(dir => dir.name.value === 'model'); | ||
const hasAuth = definition.directives?.some(dir => dir.name.value === 'auth') ?? false; | ||
if (!modelDirective) { | ||
@@ -195,2 +200,6 @@ throw new InvalidDirectiveError('Types annotated with @searchable must also be annotated with @model.'); | ||
this.generateSearchableAggregateTypes(ctx); | ||
const directives = []; | ||
if (!hasAuth && ctx.sandboxModeEnabled && ctx.authConfig.defaultAuthentication.authenticationType !== 'API_KEY') { | ||
directives.push(makeDirective('aws_api_key', [])); | ||
} | ||
const queryField = makeField( | ||
@@ -207,4 +216,4 @@ fieldName, | ||
makeNamedType(`Searchable${definition.name.value}Connection`), | ||
directives, | ||
); | ||
ctx.output.addQueryFields([queryField]); | ||
@@ -214,2 +223,15 @@ } | ||
transformSchema = (ctx: TransformerTransformSchemaStepContextProvider) => { | ||
// add api key to aggregate types if sandbox mode is enabled | ||
if (ctx.sandboxModeEnabled && ctx.authConfig.defaultAuthentication.authenticationType !== 'API_KEY') { | ||
for (let aggType of AGGREGATE_TYPES) { | ||
const aggObject = ctx.output.getObject(aggType)!; | ||
const hasApiKey = aggObject.directives?.some(dir => dir.name.value === 'aws_api_key') ?? false; | ||
if (!hasApiKey) { | ||
extendTypeWithDirectives(ctx, aggType, [makeDirective('aws_api_key', [])]); | ||
} | ||
} | ||
} | ||
}; | ||
private generateSearchableXConnectionType(ctx: TransformerSchemaVisitStepContextProvider, definition: ObjectTypeDefinitionNode): void { | ||
@@ -369,3 +391,3 @@ const searchableXConnectionName = `Searchable${definition.name.value}Connection`; | ||
if (!ctx.output.hasType(`Searchable${definition.name.value}AggregateField`)) { | ||
const searchableXAggregationField = makeSearchableXAggregateFieldEnumObject(definition); | ||
const searchableXAggregationField = makeSearchableXAggregateFieldEnumObject(definition, ctx.inputDocument); | ||
ctx.output.addEnum(searchableXAggregationField); | ||
@@ -372,0 +394,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
423670
2915
+ Added@aws-amplify/graphql-transformer-core@0.13.0-graphql-vnext-dev-preview.12(transitive)
+ Added@aws-amplify/graphql-transformer-interfaces@1.12.1-graphql-vnext-dev-preview.12(transitive)
+ Addedgraphql-mapping-template@4.20.1-graphql-vnext-dev-preview.12(transitive)
+ Addedgraphql-transformer-common@4.22.1-graphql-vnext-dev-preview.12(transitive)
- Removed@aws-amplify/graphql-transformer-core@0.11.0-beta.1(transitive)
- Removed@aws-amplify/graphql-transformer-interfaces@1.11.1-beta.1(transitive)
- Removedgraphql-mapping-template@4.19.1-beta.0(transitive)
- Removedgraphql-transformer-common@4.21.0-beta.0(transitive)
Updated@aws-amplify/graphql-transformer-core@0.13.0-graphql-vnext-dev-preview.12
Updated@aws-amplify/graphql-transformer-interfaces@1.12.1-graphql-vnext-dev-preview.12
Updatedgraphql-mapping-template@4.20.1-graphql-vnext-dev-preview.12
Updatedgraphql-transformer-common@4.22.1-graphql-vnext-dev-preview.12