Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@aws-amplify/graphql-searchable-transformer

Package Overview
Dependencies
Maintainers
7
Versions
440
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aws-amplify/graphql-searchable-transformer - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1-beta.0

13

CHANGELOG.md

@@ -6,2 +6,15 @@ # Change Log

## [0.4.1-beta.0](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-searchable-transformer@0.4.0...@aws-amplify/graphql-searchable-transformer@0.4.1-beta.0) (2021-08-06)
### Bug Fixes
* **graphql-model-transformer:** model input fields transform ([#7857](https://github.com/aws-amplify/amplify-cli/issues/7857)) ([12ff663](https://github.com/aws-amplify/amplify-cli/commit/12ff663a94a4896bd9eacef3847be15b7631d8df))
* misc [@model](https://github.com/model) v2 VTL cleanup ([#7856](https://github.com/aws-amplify/amplify-cli/issues/7856)) ([98d81d8](https://github.com/aws-amplify/amplify-cli/commit/98d81d8e2e13fc1525389ba21e6ad4b372e671fb))
* use improved pluralization in graphql transformer v2 ([#7817](https://github.com/aws-amplify/amplify-cli/issues/7817)) ([38e2599](https://github.com/aws-amplify/amplify-cli/commit/38e25996ee00479031c88714af3b9d40ef9e079c))
# [0.4.0](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-searchable-transformer@0.3.2...@aws-amplify/graphql-searchable-transformer@0.4.0) (2021-07-30)

@@ -8,0 +21,0 @@

2

lib/definitions.d.ts

@@ -7,2 +7,4 @@ import { ObjectTypeDefinitionNode, InputObjectTypeDefinitionNode, DocumentNode, EnumTypeDefinitionNode } from 'graphql';

export declare function makeSearchableXSortInputObject(obj: ObjectTypeDefinitionNode): InputObjectTypeDefinitionNode;
export declare function makeSearchableAggregateTypeEnumObject(): EnumTypeDefinitionNode;
export declare function makeSearchableXAggregationInputObject(obj: ObjectTypeDefinitionNode): InputObjectTypeDefinitionNode;
//# sourceMappingURL=definitions.d.ts.map

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.makeSearchableXSortInputObject = exports.makeSearchableXSortableFieldsEnumObject = exports.makeSearchableSortDirectionEnumObject = exports.makeSearchableXFilterInputObject = exports.makeSearchableScalarInputObject = void 0;
exports.makeSearchableXAggregationInputObject = exports.makeSearchableAggregateTypeEnumObject = exports.makeSearchableXSortInputObject = exports.makeSearchableXSortableFieldsEnumObject = exports.makeSearchableSortDirectionEnumObject = exports.makeSearchableXFilterInputObject = exports.makeSearchableScalarInputObject = void 0;
const graphql_1 = require("graphql");

@@ -177,2 +177,52 @@ const graphql_transformer_common_1 = require("graphql-transformer-common");

exports.makeSearchableXSortInputObject = makeSearchableXSortInputObject;
function makeSearchableAggregateTypeEnumObject() {
const name = graphql_transformer_common_1.graphqlName('SearchableAggregateType');
const values = ['terms', 'avg', 'min', 'max', 'sum'].map((type) => ({
kind: graphql_1.Kind.ENUM_VALUE_DEFINITION,
name: { kind: 'Name', value: type },
directives: [],
}));
return {
kind: graphql_1.Kind.ENUM_TYPE_DEFINITION,
name: {
kind: 'Name',
value: name,
},
values,
directives: [],
};
}
exports.makeSearchableAggregateTypeEnumObject = makeSearchableAggregateTypeEnumObject;
function makeSearchableXAggregationInputObject(obj) {
const name = graphql_transformer_common_1.graphqlName(`Searchable${obj.name.value}AggregationInput`);
return {
kind: graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION,
name: {
kind: 'Name',
value: name,
},
fields: [
{
kind: graphql_1.Kind.INPUT_VALUE_DEFINITION,
name: { kind: 'Name', value: 'name' },
type: graphql_transformer_common_1.makeNonNullType(graphql_transformer_common_1.makeNamedType('String')),
directives: [],
},
{
kind: graphql_1.Kind.INPUT_VALUE_DEFINITION,
name: { kind: 'Name', value: 'type' },
type: graphql_transformer_common_1.makeNonNullType(graphql_transformer_common_1.makeNamedType('SearchableAggregateType')),
directives: [],
},
{
kind: graphql_1.Kind.INPUT_VALUE_DEFINITION,
name: { kind: 'Name', value: 'field' },
type: graphql_transformer_common_1.makeNonNullType(graphql_transformer_common_1.makeNamedType('String')),
directives: [],
},
],
directives: [],
};
}
exports.makeSearchableXAggregationInputObject = makeSearchableXAggregationInputObject;
function getScalarFilterInputType(condition, type, filterInputName) {

@@ -179,0 +229,0 @@ switch (condition) {

@@ -11,2 +11,3 @@ "use strict";

graphql_mapping_template_1.set(graphql_mapping_template_1.ref('sortValues'), graphql_mapping_template_1.list([])),
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('aggregateValues'), graphql_mapping_template_1.obj({})),
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('primaryKey'), graphql_mapping_template_1.str(primaryKey)),

@@ -22,3 +23,6 @@ graphql_mapping_template_1.ifElse(graphql_mapping_template_1.ref('util.isNullOrEmpty($context.args.sort)'), graphql_mapping_template_1.compoundExpression([

])),
graphql_mapping_template_1.ElasticsearchMappingTemplate.searchItem({
graphql_mapping_template_1.forEach(graphql_mapping_template_1.ref('aggItem'), graphql_mapping_template_1.ref('context.args.aggregates'), [
graphql_mapping_template_1.ifElse(graphql_mapping_template_1.ref('nonKeywordFields.contains($aggItem.field)'), graphql_mapping_template_1.qref('$aggregateValues.put("$aggItem.name", {"$aggItem.type": {"field": "$aggItem.field"}})'), graphql_mapping_template_1.qref('$aggregateValues.put("$aggItem.name", {"$aggItem.type": {"field": "${aggItem.field}.keyword"}})')),
]),
graphql_mapping_template_1.ElasticsearchMappingTemplate.searchTemplate({
path: graphql_mapping_template_1.str('$indexPath'),

@@ -33,2 +37,3 @@ size: graphql_mapping_template_1.ifElse(graphql_mapping_template_1.ref('context.args.limit'), graphql_mapping_template_1.ref('context.args.limit'), graphql_mapping_template_1.int(graphql_transformer_common_1.ResourceConstants.DEFAULT_SEARCHABLE_PAGE_LIMIT), true),

sort: graphql_mapping_template_1.ref('sortValues'),
aggs: graphql_mapping_template_1.ref('util.toJson($aggregateValues)'),
}),

@@ -41,2 +46,3 @@ ]));

graphql_mapping_template_1.set(graphql_mapping_template_1.ref('es_items'), graphql_mapping_template_1.list([])),
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('aggregateValues'), graphql_mapping_template_1.list([])),
graphql_mapping_template_1.forEach(graphql_mapping_template_1.ref('entry'), graphql_mapping_template_1.ref('context.result.hits.hits'), [

@@ -46,6 +52,24 @@ graphql_mapping_template_1.iff(graphql_mapping_template_1.raw('!$foreach.hasNext'), graphql_mapping_template_1.set(graphql_mapping_template_1.ref('nextToken'), graphql_mapping_template_1.ref('util.base64Encode($util.toJson($entry.sort))'))),

]),
graphql_mapping_template_1.forEach(graphql_mapping_template_1.ref('aggItem'), graphql_mapping_template_1.ref('context.result.aggregations.keySet()'), [
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('aggResult'), graphql_mapping_template_1.obj({})),
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('aggResultValue'), graphql_mapping_template_1.obj({})),
graphql_mapping_template_1.qref('$aggResult.put("name", $aggItem)'),
graphql_mapping_template_1.iff(graphql_mapping_template_1.raw('!$util.isNullOrEmpty($context.result.aggregations)'), graphql_mapping_template_1.compoundExpression([
graphql_mapping_template_1.iff(graphql_mapping_template_1.raw('!$util.isNullOrEmpty($context.result.aggregations.get($aggItem).buckets)'), graphql_mapping_template_1.compoundExpression([
graphql_mapping_template_1.qref('$aggResultValue.put("__typename", "SearchableAggregateBucketResult")'),
graphql_mapping_template_1.qref('$aggResultValue.put("buckets", $context.result.aggregations.get($aggItem).buckets)'),
])),
graphql_mapping_template_1.iff(graphql_mapping_template_1.raw('!$util.isNullOrEmpty($context.result.aggregations.get($aggItem).value)'), graphql_mapping_template_1.compoundExpression([
graphql_mapping_template_1.qref('$aggResultValue.put("__typename", "SearchableAggregateScalarResult")'),
graphql_mapping_template_1.qref('$aggResultValue.put("value", $context.result.aggregations.get($aggItem).value)'),
])),
])),
graphql_mapping_template_1.qref('$aggResult.put("result", $aggResultValue)'),
graphql_mapping_template_1.qref('$aggregateValues.add($aggResult)'),
]),
graphql_mapping_template_1.toJson(graphql_mapping_template_1.obj({
items: graphql_mapping_template_1.ref('es_items'),
total: graphql_mapping_template_1.ref('ctx.result.hits.total'),
total: graphql_mapping_template_1.ref('ctx.result.hits.total.value'),
nextToken: graphql_mapping_template_1.ref('nextToken'),
aggregateItems: graphql_mapping_template_1.ref('aggregateValues'),
})),

@@ -52,0 +76,0 @@ ]));

@@ -13,4 +13,10 @@ import { TransformerPluginBase } from '@aws-amplify/graphql-transformer-core';

private generateSearchableXConnectionType;
private generateSearchableAggregateTypes;
private generateSearchableGenericResultType;
private generateSearchableAggregateScalarResultType;
private generateSearchableAggregateBucketResultItemType;
private generateSearchableAggregateBucketResultType;
private generateSearchableAggregateResultType;
private generateSearchableInputs;
}
//# sourceMappingURL=graphql-searchable-transformer.d.ts.map

@@ -86,3 +86,3 @@ "use strict";

? searchFieldNameOverride
: graphql_transformer_common_1.graphqlName(`search${graphql_transformer_common_1.plurality(graphql_transformer_common_1.toUpper(definition.name.value), ctx.featureFlags.getBoolean('improvePluralization', true))}`);
: graphql_transformer_common_1.graphqlName(`search${graphql_transformer_common_1.plurality(graphql_transformer_common_1.toUpper(definition.name.value), true)}`);
this.searchableObjectTypeDefinitions.push({

@@ -95,2 +95,3 @@ node: definition,

this.generateSearchableXConnectionType(ctx, definition);
this.generateSearchableAggregateTypes(ctx);
const queryField = graphql_transformer_common_1.makeField(fieldName, [

@@ -102,2 +103,3 @@ graphql_transformer_common_1.makeInputValueDefinition('filter', graphql_transformer_common_1.makeNamedType(`Searchable${definition.name.value}FilterInput`)),

graphql_transformer_common_1.makeInputValueDefinition('from', graphql_transformer_common_1.makeNamedType('Int')),
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`));

@@ -123,5 +125,80 @@ ctx.output.addQueryFields([queryField]);

graphql_transformer_common_1.makeField('total', [], graphql_transformer_common_1.makeNamedType('Int')),
graphql_transformer_common_1.makeField('aggregateItems', [], graphql_transformer_common_1.makeListType(graphql_transformer_common_1.makeNamedType(`SearchableAggregateResult`))),
]);
ctx.output.addObjectExtension(connectionTypeExtension);
}
generateSearchableAggregateTypes(ctx) {
this.generateSearchableAggregateResultType(ctx);
this.generateSearchableGenericResultType(ctx);
}
generateSearchableGenericResultType(ctx) {
const searchableAggregateGenericResult = `SearchableAggregateGenericResult`;
if (ctx.output.hasType(searchableAggregateGenericResult)) {
return;
}
let searchableAggregateGenericResultNode = graphql_transformer_common_1.defineUnionType(searchableAggregateGenericResult, [
graphql_transformer_common_1.makeNamedType(this.generateSearchableAggregateScalarResultType(ctx)),
graphql_transformer_common_1.makeNamedType(this.generateSearchableAggregateBucketResultType(ctx)),
]);
ctx.output.addUnion(searchableAggregateGenericResultNode);
}
generateSearchableAggregateScalarResultType(ctx) {
const searchableAggregateScalarResult = `SearchableAggregateScalarResult`;
if (ctx.output.hasType(searchableAggregateScalarResult)) {
return searchableAggregateScalarResult;
}
const aggregateScalarType = graphql_transformer_common_1.blankObject(searchableAggregateScalarResult);
ctx.output.addObject(aggregateScalarType);
let aggregateScalarTypeExtension = graphql_transformer_common_1.blankObjectExtension(searchableAggregateScalarResult);
aggregateScalarTypeExtension = graphql_transformer_common_1.extensionWithFields(aggregateScalarTypeExtension, [
graphql_transformer_common_1.makeField('value', [], graphql_transformer_common_1.makeNonNullType(graphql_transformer_common_1.makeNamedType('Float'))),
]);
ctx.output.addObjectExtension(aggregateScalarTypeExtension);
return searchableAggregateScalarResult;
}
generateSearchableAggregateBucketResultItemType(ctx) {
const searchableAggregateBucketResultItem = `SearchableAggregateBucketResultItem`;
if (ctx.output.hasType(searchableAggregateBucketResultItem)) {
return searchableAggregateBucketResultItem;
}
const aggregateBucketResultItemType = graphql_transformer_common_1.blankObject(searchableAggregateBucketResultItem);
ctx.output.addObject(aggregateBucketResultItemType);
let aggregateBucketResultItemTypeExtension = graphql_transformer_common_1.blankObjectExtension(searchableAggregateBucketResultItem);
aggregateBucketResultItemTypeExtension = graphql_transformer_common_1.extensionWithFields(aggregateBucketResultItemTypeExtension, [
graphql_transformer_common_1.makeField('key', [], graphql_transformer_common_1.makeNonNullType(graphql_transformer_common_1.makeNamedType('String'))),
graphql_transformer_common_1.makeField('doc_count', [], graphql_transformer_common_1.makeNonNullType(graphql_transformer_common_1.makeNamedType('Int'))),
]);
ctx.output.addObjectExtension(aggregateBucketResultItemTypeExtension);
return searchableAggregateBucketResultItem;
}
generateSearchableAggregateBucketResultType(ctx) {
const searchableAggregateBucketResult = `SearchableAggregateBucketResult`;
if (ctx.output.hasType(searchableAggregateBucketResult)) {
return searchableAggregateBucketResult;
}
const aggregateBucketResultType = graphql_transformer_common_1.blankObject(searchableAggregateBucketResult);
ctx.output.addObject(aggregateBucketResultType);
this.generateSearchableAggregateBucketResultItemType(ctx);
let aggregateBucketResultTypeExtension = graphql_transformer_common_1.blankObjectExtension(searchableAggregateBucketResult);
aggregateBucketResultTypeExtension = graphql_transformer_common_1.extensionWithFields(aggregateBucketResultTypeExtension, [
graphql_transformer_common_1.makeField('buckets', [], graphql_transformer_common_1.makeListType(graphql_transformer_common_1.makeNamedType('SearchableAggregateBucketResultItem'))),
]);
ctx.output.addObjectExtension(aggregateBucketResultTypeExtension);
return searchableAggregateBucketResult;
}
generateSearchableAggregateResultType(ctx) {
const searchableAggregateResult = `SearchableAggregateResult`;
if (ctx.output.hasType(searchableAggregateResult)) {
return searchableAggregateResult;
}
const aggregateResultType = graphql_transformer_common_1.blankObject(searchableAggregateResult);
ctx.output.addObject(aggregateResultType);
let aggregateResultTypeExtension = graphql_transformer_common_1.blankObjectExtension(searchableAggregateResult);
aggregateResultTypeExtension = graphql_transformer_common_1.extensionWithFields(aggregateResultTypeExtension, [
graphql_transformer_common_1.makeField('name', [], graphql_transformer_common_1.makeNonNullType(graphql_transformer_common_1.makeNamedType('String'))),
graphql_transformer_common_1.makeField('result', [], graphql_transformer_common_1.makeNamedType('SearchableAggregateGenericResult')),
]);
ctx.output.addObjectExtension(aggregateResultTypeExtension);
return searchableAggregateResult;
}
generateSearchableInputs(ctx, definition) {

@@ -149,2 +226,10 @@ const inputs = Object.keys(graphql_transformer_common_1.STANDARD_SCALARS);

}
if (!ctx.output.hasType(`Searchable${definition.name.value}AggregationInput`)) {
const searchableXAggregationInputDirection = definitions_1.makeSearchableXAggregationInputObject(definition);
ctx.output.addInput(searchableXAggregationInputDirection);
}
if (!ctx.output.hasType('SearchableAggregateType')) {
const searchableAggregateTypeEnum = definitions_1.makeSearchableAggregateTypeEnumObject();
ctx.output.addEnum(searchableAggregateTypeEnum);
}
}

@@ -151,0 +236,0 @@ }

12

package.json
{
"name": "@aws-amplify/graphql-searchable-transformer",
"version": "0.4.0",
"version": "0.4.1-beta.0",
"description": "Amplfy GraphQL @searchable transformer",

@@ -30,4 +30,4 @@ "repository": {

"dependencies": {
"@aws-amplify/graphql-transformer-core": "0.8.0",
"@aws-amplify/graphql-transformer-interfaces": "1.8.0",
"@aws-amplify/graphql-transformer-core": "0.8.1-beta.0",
"@aws-amplify/graphql-transformer-interfaces": "1.8.1-beta.0",
"@aws-cdk/aws-appsync": "~1.72.0",

@@ -41,4 +41,4 @@ "@aws-cdk/aws-dynamodb": "~1.72.0",

"graphql": "^14.5.8",
"graphql-mapping-template": "4.18.1",
"graphql-transformer-common": "4.19.6"
"graphql-mapping-template": "4.18.2-beta.0",
"graphql-transformer-common": "4.19.7-beta.0"
},

@@ -66,3 +66,3 @@ "devDependencies": {

},
"gitHead": "7564914b8bcdcb667b88789cbdaed9fdbc8cdb82"
"gitHead": "047b541e0e6e005ebb798d69516c5170653c0d42"
}

@@ -12,3 +12,12 @@ import {

} from 'graphql';
import { graphqlName, makeNamedType, isScalar, isEnum, makeListType, getBaseType, SearchableResourceIDs } from 'graphql-transformer-common';
import {
graphqlName,
makeNamedType,
isScalar,
isEnum,
makeListType,
makeNonNullType,
getBaseType,
SearchableResourceIDs,
} from 'graphql-transformer-common';

@@ -230,2 +239,53 @@ const ID_CONDITIONS = [

export function makeSearchableAggregateTypeEnumObject(): EnumTypeDefinitionNode {
const name = graphqlName('SearchableAggregateType');
const values: EnumValueDefinitionNode[] = ['terms', 'avg', 'min', 'max', 'sum'].map((type: string) => ({
kind: Kind.ENUM_VALUE_DEFINITION,
name: { kind: 'Name', value: type },
directives: [],
}));
return {
kind: Kind.ENUM_TYPE_DEFINITION,
name: {
kind: 'Name',
value: name,
},
values,
directives: [],
};
}
export function makeSearchableXAggregationInputObject(obj: ObjectTypeDefinitionNode): InputObjectTypeDefinitionNode {
const name = graphqlName(`Searchable${obj.name.value}AggregationInput`);
return {
kind: Kind.INPUT_OBJECT_TYPE_DEFINITION,
name: {
kind: 'Name',
value: name,
},
fields: [
{
kind: Kind.INPUT_VALUE_DEFINITION,
name: { kind: 'Name', value: 'name' },
type: makeNonNullType(makeNamedType('String')),
directives: [],
},
{
kind: Kind.INPUT_VALUE_DEFINITION,
name: { kind: 'Name', value: 'type' },
type: makeNonNullType(makeNamedType('SearchableAggregateType')),
directives: [],
},
{
kind: Kind.INPUT_VALUE_DEFINITION,
name: { kind: 'Name', value: 'field' },
type: makeNonNullType(makeNamedType('String')),
directives: [],
},
],
directives: [],
};
}
function getScalarFilterInputType(condition: string, type: string, filterInputName: string): TypeNode {

@@ -232,0 +292,0 @@ switch (condition) {

@@ -29,2 +29,3 @@ import {

set(ref('sortValues'), list([])),
set(ref('aggregateValues'), obj({})),
set(ref('primaryKey'), str(primaryKey)),

@@ -42,25 +43,28 @@ ifElse(

]),
forEach(
ref('sortItem'),
ref('context.args.sort'),
[
forEach(ref('sortItem'), ref('context.args.sort'), [
ifElse(
ref('util.isNullOrEmpty($sortItem.field)'),
ifElse(
ref('util.isNullOrEmpty($sortItem.field)'),
ifElse(
ref('nonKeywordFields.contains($primaryKey)'),
set(ref('sortField'), ref('util.toJson($primaryKey)')),
set(ref('sortField'), ref('util.toJson("${primaryKey}.keyword")')),
),
ifElse(
ref('nonKeywordFields.contains($sortItem.field)'),
set(ref('sortField'), ref('util.toJson($sortItem.field)')),
set(ref('sortField'), ref('util.toJson("${sortItem.field}.keyword")')),
),
ref('nonKeywordFields.contains($primaryKey)'),
set(ref('sortField'), ref('util.toJson($primaryKey)')),
set(ref('sortField'), ref('util.toJson("${primaryKey}.keyword")')),
),
set(ref('sortDirection'), ref('util.toJson({"order": $sortItem.direction})')),
qref('$sortValues.add("{$sortField: $sortDirection}")'),
],
ifElse(
ref('nonKeywordFields.contains($sortItem.field)'),
set(ref('sortField'), ref('util.toJson($sortItem.field)')),
set(ref('sortField'), ref('util.toJson("${sortItem.field}.keyword")')),
),
),
set(ref('sortDirection'), ref('util.toJson({"order": $sortItem.direction})')),
qref('$sortValues.add("{$sortField: $sortDirection}")'),
]),
),
forEach(ref('aggItem'), ref('context.args.aggregates'), [
ifElse(
ref('nonKeywordFields.contains($aggItem.field)'),
qref('$aggregateValues.put("$aggItem.name", {"$aggItem.type": {"field": "$aggItem.field"}})'),
qref('$aggregateValues.put("$aggItem.name", {"$aggItem.type": {"field": "${aggItem.field}.keyword"}})'),
),
),
ElasticsearchMappingTemplate.searchItem({
]),
ElasticsearchMappingTemplate.searchTemplate({
path: str('$indexPath'),

@@ -79,2 +83,3 @@ size: ifElse(ref('context.args.limit'), ref('context.args.limit'), int(ResourceConstants.DEFAULT_SEARCHABLE_PAGE_LIMIT), true),

sort: ref('sortValues'),
aggs: ref('util.toJson($aggregateValues)'),
}),

@@ -89,2 +94,3 @@ ]),

set(ref('es_items'), list([])),
set(ref('aggregateValues'), list([])),
forEach(ref('entry'), ref('context.result.hits.hits'), [

@@ -94,7 +100,34 @@ iff(raw('!$foreach.hasNext'), set(ref('nextToken'), ref('util.base64Encode($util.toJson($entry.sort))'))),

]),
forEach(ref('aggItem'), ref('context.result.aggregations.keySet()'), [
set(ref('aggResult'), obj({})),
set(ref('aggResultValue'), obj({})),
qref('$aggResult.put("name", $aggItem)'),
iff(
raw('!$util.isNullOrEmpty($context.result.aggregations)'),
compoundExpression([
iff(
raw('!$util.isNullOrEmpty($context.result.aggregations.get($aggItem).buckets)'),
compoundExpression([
qref('$aggResultValue.put("__typename", "SearchableAggregateBucketResult")'),
qref('$aggResultValue.put("buckets", $context.result.aggregations.get($aggItem).buckets)'),
]),
),
iff(
raw('!$util.isNullOrEmpty($context.result.aggregations.get($aggItem).value)'),
compoundExpression([
qref('$aggResultValue.put("__typename", "SearchableAggregateScalarResult")'),
qref('$aggResultValue.put("value", $context.result.aggregations.get($aggItem).value)'),
]),
),
]),
),
qref('$aggResult.put("result", $aggResultValue)'),
qref('$aggregateValues.add($aggResult)'),
]),
toJson(
obj({
items: ref('es_items'),
total: ref('ctx.result.hits.total'),
total: ref('ctx.result.hits.total.value'),
nextToken: ref('nextToken'),
aggregateItems: ref('aggregateValues'),
}),

@@ -101,0 +134,0 @@ ),

@@ -19,2 +19,3 @@ import { TransformerPluginBase, InvalidDirectiveError, MappingTemplate, DirectiveWrapper } from '@aws-amplify/graphql-transformer-core';

blankObjectExtension,
defineUnionType,
extensionWithFields,

@@ -24,2 +25,3 @@ makeField,

makeNamedType,
makeNonNullType,
makeInputValueDefinition,

@@ -38,2 +40,4 @@ graphqlName,

makeSearchableXSortInputObject,
makeSearchableXAggregationInputObject,
makeSearchableAggregateTypeEnumObject,
} from './definitions';

@@ -166,3 +170,3 @@ import assert from 'assert';

? searchFieldNameOverride
: graphqlName(`search${plurality(toUpper(definition.name.value), ctx.featureFlags.getBoolean('improvePluralization', true))}`);
: graphqlName(`search${plurality(toUpper(definition.name.value), true)}`);
this.searchableObjectTypeDefinitions.push({

@@ -176,2 +180,3 @@ node: definition,

this.generateSearchableXConnectionType(ctx, definition);
this.generateSearchableAggregateTypes(ctx);
const queryField = makeField(

@@ -185,2 +190,3 @@ fieldName,

makeInputValueDefinition('from', makeNamedType('Int')),
makeInputValueDefinition('aggregates', makeListType(makeNamedType(`Searchable${definition.name.value}AggregationInput`))),
],

@@ -212,2 +218,3 @@ makeNamedType(`Searchable${definition.name.value}Connection`),

makeField('total', [], makeNamedType('Int')),
makeField('aggregateItems', [], makeListType(makeNamedType(`SearchableAggregateResult`))),
]);

@@ -217,2 +224,100 @@ ctx.output.addObjectExtension(connectionTypeExtension);

private generateSearchableAggregateTypes(ctx: TransformerSchemaVisitStepContextProvider): void {
this.generateSearchableAggregateResultType(ctx);
this.generateSearchableGenericResultType(ctx);
}
private generateSearchableGenericResultType(ctx: TransformerSchemaVisitStepContextProvider): void {
const searchableAggregateGenericResult = `SearchableAggregateGenericResult`;
if (ctx.output.hasType(searchableAggregateGenericResult)) {
return;
}
let searchableAggregateGenericResultNode = defineUnionType(searchableAggregateGenericResult, [
makeNamedType(this.generateSearchableAggregateScalarResultType(ctx)),
makeNamedType(this.generateSearchableAggregateBucketResultType(ctx)),
]);
ctx.output.addUnion(searchableAggregateGenericResultNode);
}
private generateSearchableAggregateScalarResultType(ctx: TransformerSchemaVisitStepContextProvider): string {
const searchableAggregateScalarResult = `SearchableAggregateScalarResult`;
if (ctx.output.hasType(searchableAggregateScalarResult)) {
return searchableAggregateScalarResult;
}
// Create the SearchableAggregateScalarResult
const aggregateScalarType = blankObject(searchableAggregateScalarResult);
ctx.output.addObject(aggregateScalarType);
// Create SearchableAggregateScalarResult type with value
let aggregateScalarTypeExtension = blankObjectExtension(searchableAggregateScalarResult);
aggregateScalarTypeExtension = extensionWithFields(aggregateScalarTypeExtension, [
makeField('value', [], makeNonNullType(makeNamedType('Float'))),
]);
ctx.output.addObjectExtension(aggregateScalarTypeExtension);
return searchableAggregateScalarResult;
}
private generateSearchableAggregateBucketResultItemType(ctx: TransformerSchemaVisitStepContextProvider): string {
const searchableAggregateBucketResultItem = `SearchableAggregateBucketResultItem`;
if (ctx.output.hasType(searchableAggregateBucketResultItem)) {
return searchableAggregateBucketResultItem;
}
// Create the SearchableAggregateBucketResultItem
const aggregateBucketResultItemType = blankObject(searchableAggregateBucketResultItem);
ctx.output.addObject(aggregateBucketResultItemType);
// Create SearchableAggregateBucketResultItem type with key and doc_count
let aggregateBucketResultItemTypeExtension = blankObjectExtension(searchableAggregateBucketResultItem);
aggregateBucketResultItemTypeExtension = extensionWithFields(aggregateBucketResultItemTypeExtension, [
makeField('key', [], makeNonNullType(makeNamedType('String'))),
makeField('doc_count', [], makeNonNullType(makeNamedType('Int'))),
]);
ctx.output.addObjectExtension(aggregateBucketResultItemTypeExtension);
return searchableAggregateBucketResultItem;
}
private generateSearchableAggregateBucketResultType(ctx: TransformerSchemaVisitStepContextProvider): string {
const searchableAggregateBucketResult = `SearchableAggregateBucketResult`;
if (ctx.output.hasType(searchableAggregateBucketResult)) {
return searchableAggregateBucketResult;
}
// Create the SearchableAggregateBucketResultItem
const aggregateBucketResultType = blankObject(searchableAggregateBucketResult);
ctx.output.addObject(aggregateBucketResultType);
this.generateSearchableAggregateBucketResultItemType(ctx);
// Create SearchableAggregateBucketResultItem type with buckets
let aggregateBucketResultTypeExtension = blankObjectExtension(searchableAggregateBucketResult);
aggregateBucketResultTypeExtension = extensionWithFields(aggregateBucketResultTypeExtension, [
makeField('buckets', [], makeListType(makeNamedType('SearchableAggregateBucketResultItem'))),
]);
ctx.output.addObjectExtension(aggregateBucketResultTypeExtension);
return searchableAggregateBucketResult;
}
private generateSearchableAggregateResultType(ctx: TransformerSchemaVisitStepContextProvider): string {
const searchableAggregateResult = `SearchableAggregateResult`;
if (ctx.output.hasType(searchableAggregateResult)) {
return searchableAggregateResult;
}
// Create the SearchableAggregateResult
const aggregateResultType = blankObject(searchableAggregateResult);
ctx.output.addObject(aggregateResultType);
// Create SearchableAggregateResult type with name and result
let aggregateResultTypeExtension = blankObjectExtension(searchableAggregateResult);
aggregateResultTypeExtension = extensionWithFields(aggregateResultTypeExtension, [
makeField('name', [], makeNonNullType(makeNamedType('String'))),
makeField('result', [], makeNamedType('SearchableAggregateGenericResult')),
]);
ctx.output.addObjectExtension(aggregateResultTypeExtension);
return searchableAggregateResult;
}
private generateSearchableInputs(ctx: TransformerSchemaVisitStepContextProvider, definition: ObjectTypeDefinitionNode): void {

@@ -244,2 +349,12 @@ const inputs: string[] = Object.keys(STANDARD_SCALARS);

}
if (!ctx.output.hasType(`Searchable${definition.name.value}AggregationInput`)) {
const searchableXAggregationInputDirection = makeSearchableXAggregationInputObject(definition);
ctx.output.addInput(searchableXAggregationInputDirection);
}
if (!ctx.output.hasType('SearchableAggregateType')) {
const searchableAggregateTypeEnum = makeSearchableAggregateTypeEnumObject();
ctx.output.addEnum(searchableAggregateTypeEnum);
}
}

@@ -246,0 +361,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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc