Skip to content

Commit

Permalink
fix: export Typescript definitions and fix resulting type errors (#2452)
Browse files Browse the repository at this point in the history
* fix: export Typescript definitions and fix resulting type errors

Few of the modules export their Typescript definitions, despite being written in Typescript. This
makes them more difficult to use standalone from Typescript code. As a result of exporting the
definitions, some minor type errors emerge.

#2451

* chore: appsync-resource-processor to use
API_KEY as default.

* chore: versioned-model-transformer to drop import
of ModelAuthTransformer

* fix: build error
  • Loading branch information
alexmcmanus authored and attilah committed Oct 9, 2019
1 parent 82762d6 commit 7de3845
Show file tree
Hide file tree
Showing 20 changed files with 77 additions and 63 deletions.
2 changes: 2 additions & 0 deletions packages/amplify-appsync-simulator/src/type-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface AppSyncSimulatorFunctionResolverConfig {
responseMappingTemplateLocation: string;
}
export type AppSyncSimulatorMappingTemplate = AppSyncMockFile;
export type AppSyncSimulatorTable = string;
export interface AppSyncSimulatorUnitResolver extends AppSyncSimulatorUnitResolverConfig {
datSourceName: string;
}
Expand Down Expand Up @@ -123,6 +124,7 @@ export type AmplifyAppSyncSimulatorConfig = {
functions?: AppSyncSimulatorFunctionsConfig[];
dataSources?: AppSyncSimulatorDataSourceConfig[];
mappingTemplates?: AppSyncSimulatorMappingTemplate[];
tables?: AppSyncSimulatorTable[];
appSync: AmplifyAppSyncAPIConfig;
};

Expand Down
3 changes: 2 additions & 1 deletion packages/amplify-appsync-simulator/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"es2015",
"es2016.array.include",
"esnext.asynciterable"
]
],
"declaration": true
},
"exclude": [
"node_modules",
Expand Down
3 changes: 2 additions & 1 deletion packages/amplify-e2e-tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"es2016.array.include",
"esnext.asynciterable",
"dom"
]
],
"declaration": true
},
"exclude": [
"node_modules",
Expand Down
1 change: 1 addition & 0 deletions packages/amplify-graphql-docs-generator/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"esnext.asynciterable",
"dom"
],
"declaration": true
},
"exclude": [
"node_modules",
Expand Down
1 change: 1 addition & 0 deletions packages/amplify-storage-simulator/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"es2015",
"esnext.asynciterable",
],
"declaration": true
},
"exclude": [
"node_modules",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CloudFormationParseContext } from './types';
import { isPlainObject } from 'lodash';
import { parseValue } from './field-parser';
import { AmplifyAppSyncSimulatorConfig, AmplifyAppSyncAPIConfig } from 'amplify-appsync-simulator';
import { AmplifyAppSyncSimulatorConfig, AmplifyAppSyncAPIConfig, AmplifyAppSyncSimulatorAuthenticationType } from 'amplify-appsync-simulator';
const CFN_DEFAULT_PARAMS = {
'AWS::Region': 'us-east-1-fake',
'AWS::AccountId': '12345678910',
Expand Down Expand Up @@ -120,7 +120,9 @@ export function graphQLAPIResourceHandler(
}
),
}
: {}),
: {
additionalAuthenticationProviders: []
}),
};
return processedResource;
}
Expand Down Expand Up @@ -257,16 +259,20 @@ export function processResources(
resources: {},
exports: {},
};
const processedResources = {
schema: {},
const processedResources: AmplifyAppSyncSimulatorConfig = {
schema: {
content: ''
},
resolvers: [],
functions: [],
dataSources: [],
mappingTemplates: [],
tables: [],
appSync: {
name: '',
defaultAuthenticationType: {},
defaultAuthenticationType: {
authenticationType: AmplifyAppSyncSimulatorAuthenticationType.API_KEY
},
apiKey: null,
additionalAuthenticationProviders: []
},
Expand Down Expand Up @@ -313,13 +319,13 @@ export function processResources(
Object.entries(transformResult.resolvers).forEach(([path, content]) => {
processedResources.mappingTemplates.push({
path: `resolvers/${path}`,
content,
content: content as string,
});
});
Object.entries(transformResult.pipelineFunctions).forEach(([path, content]) => {
processedResources.mappingTemplates.push({
path: `pipelineFunctions/${path}`,
content,
content: content as string,
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import DynamoDBModelTransformer from 'graphql-dynamodb-transformer';
import GraphQLTransform from 'graphql-transformer-core';
import {
default as ModelAuthTransformer,
default as VersionedModelTransformer,
} from 'graphql-versioned-transformer';
import { VersionedModelTransformer } from 'graphql-versioned-transformer';
import { GraphQLClient } from './utils/graphql-client';
import { deploy, launchDDBLocal, terminateDDB, logDebug } from './utils/index';

Expand All @@ -29,14 +26,6 @@ beforeAll(async () => {
const transformer = new GraphQLTransform({
transformers: [
new DynamoDBModelTransformer(),
new ModelAuthTransformer({
authConfig: {
defaultAuthentication: {
authenticationType: 'API_KEY',
},
additionalAuthenticationProviders: [],
},
}),
new VersionedModelTransformer(),
],
});
Expand Down
1 change: 1 addition & 0 deletions packages/amplify-util-mock/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"es2017",
"esnext.asynciterable"
],
"declaration": true,
"skipLibCheck": true
},
"exclude": [
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql-auth-transformer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"es2016.array.include",
"esnext.asynciterable",
"dom"
]
],
"declaration": true
},
"exclude": [
"node_modules",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,35 @@ export class ModelConnectionTransformer extends Transformer {
ctx.addObjectExtension(makeModelConnectionType(typeDef.name.value));
}

private generateFilterAndKeyConditionInputs(
ctx: TransformerContext,
field: ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode,
sortKeyInfo?: { fieldName: string; typeName: SortKeyFieldInfoTypeName }
): void {
const scalarFilters = makeScalarFilterInputs();
for (const filter of scalarFilters) {
if (!this.typeExist(filter.name.value, ctx)) {
ctx.addInput(filter);
}
}

// Create the ModelXFilterInput
const tableXQueryFilterInput = makeModelXFilterInputObject(field, ctx);
if (!this.typeExist(tableXQueryFilterInput.name.value, ctx)) {
ctx.addInput(tableXQueryFilterInput);
}

// Create sort key condition inputs for valid sort key types
// We only create the KeyConditionInput if it is being used.
// Don't create a key condition input for composite sort keys since it already done by @key.
if (sortKeyInfo && sortKeyInfo.typeName !== 'Composite') {
const sortKeyConditionInput = makeScalarKeyConditionForType(makeNamedType(sortKeyInfo.typeName));
if (!this.typeExist(sortKeyConditionInput.name.value, ctx)) {
ctx.addInput(sortKeyConditionInput);
}
}
}

private extendTypeWithConnection(
ctx: TransformerContext,
parent: ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode,
Expand All @@ -666,8 +695,7 @@ export class ModelConnectionTransformer extends Transformer {
// Find the field and replace it in place.
const newFields = type.fields.map((f: FieldDefinitionNode) => {
if (f.name.value === field.name.value) {
const updated = makeModelConnectionField(field.name.value, returnType.name.value, sortKeyInfo);
updated.directives = f.directives;
const updated = makeModelConnectionField(field.name.value, returnType.name.value, sortKeyInfo, [...f.directives]);
return updated;
}
return f;
Expand All @@ -689,35 +717,6 @@ export class ModelConnectionTransformer extends Transformer {
}
}

private generateFilterAndKeyConditionInputs(
ctx: TransformerContext,
field: ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode,
sortKeyInfo?: { fieldName: string; typeName: SortKeyFieldInfoTypeName }
): void {
const scalarFilters = makeScalarFilterInputs();
for (const filter of scalarFilters) {
if (!this.typeExist(filter.name.value, ctx)) {
ctx.addInput(filter);
}
}

// Create the ModelXFilterInput
const tableXQueryFilterInput = makeModelXFilterInputObject(field, ctx);
if (!this.typeExist(tableXQueryFilterInput.name.value, ctx)) {
ctx.addInput(tableXQueryFilterInput);
}

// Create sort key condition inputs for valid sort key types
// We only create the KeyConditionInput if it is being used.
// Don't create a key condition input for composite sort keys since it already done by @key.
if (sortKeyInfo && sortKeyInfo.typeName !== 'Composite') {
const sortKeyConditionInput = makeScalarKeyConditionForType(makeNamedType(sortKeyInfo.typeName));
if (!this.typeExist(sortKeyConditionInput.name.value, ctx)) {
ctx.addInput(sortKeyConditionInput);
}
}
}

private getPrimaryKeyField(ctx: TransformerContext, type: ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode): FieldDefinitionNode {
let field: FieldDefinitionNode;

Expand Down
3 changes: 2 additions & 1 deletion packages/graphql-connection-transformer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"es2016.array.include",
"esnext.asynciterable",
"dom"
]
],
"declaration": true
},
"exclude": [
"node_modules",
Expand Down
9 changes: 6 additions & 3 deletions packages/graphql-dynamodb-transformer/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
EnumTypeDefinitionNode, ObjectTypeExtensionNode,
TypeDefinitionNode,
NamedTypeNode,
DirectiveNode,
InterfaceTypeDefinitionNode,
} from 'graphql'
import {
wrapNonNull, unwrapNonNull, makeNamedType, toUpper, graphqlName, makeListType,
Expand Down Expand Up @@ -251,7 +253,7 @@ export function makeDeleteInputObject(obj: ObjectTypeDefinitionNode): InputObjec
}

export function makeModelXFilterInputObject(
obj: ObjectTypeDefinitionNode,
obj: ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode,
ctx: TransformerContext
): InputObjectTypeDefinitionNode {
const name = ModelResourceIDs.ModelFilterInputTypeName(obj.name.value)
Expand Down Expand Up @@ -539,7 +541,7 @@ export interface SortKeyFieldInfo {
keyName?: string;
}

export function makeModelConnectionField(fieldName: string, returnTypeName: string, sortKeyInfo?: SortKeyFieldInfo): FieldDefinitionNode {
export function makeModelConnectionField(fieldName: string, returnTypeName: string, sortKeyInfo?: SortKeyFieldInfo, directives?: DirectiveNode[]): FieldDefinitionNode {
const args = [
makeInputValueDefinition('filter', makeNamedType(ModelResourceIDs.ModelFilterInputTypeName(returnTypeName))),
makeInputValueDefinition('sortDirection', makeNamedType('ModelSortDirection')),
Expand All @@ -561,7 +563,8 @@ export function makeModelConnectionField(fieldName: string, returnTypeName: stri
return makeField(
fieldName,
args,
makeNamedType(ModelResourceIDs.ModelConnectionTypeName(returnTypeName))
makeNamedType(ModelResourceIDs.ModelConnectionTypeName(returnTypeName)),
directives
);
}

Expand Down
3 changes: 2 additions & 1 deletion packages/graphql-dynamodb-transformer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"es2016.array.include",
"esnext.asynciterable",
"dom"
]
],
"declaration": true
},
"exclude": [
"node_modules",
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql-elasticsearch-transformer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"es2016.array.include",
"esnext.asynciterable",
"dom"
]
],
"declaration": true
},
"exclude": [
"node_modules",
Expand Down
1 change: 1 addition & 0 deletions packages/graphql-function-transformer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"esnext.asynciterable",
"dom"
],
"declaration": true,
"skipLibCheck": true
},
"exclude": [
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql-http-transformer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"es2016.array.include",
"esnext.asynciterable",
"dom"
]
],
"declaration": true
},
"exclude": [
"node_modules",
Expand Down
1 change: 1 addition & 0 deletions packages/graphql-key-transformer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"esnext.asynciterable",
"dom"
],
"declaration": true,
"skipLibCheck": true
},
"exclude": [
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql-relational-schema-transformer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"es2016.array.include",
"esnext.asynciterable",
"dom"
]
],
"declaration": true
},
"exclude": [
"node_modules",
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql-transformers-e2e-tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"es2016.array.include",
"esnext.asynciterable",
"dom"
]
],
"declaration": true
},
"exclude": [
"node_modules",
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql-versioned-transformer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"es2016.array.include",
"esnext.asynciterable",
"dom"
]
],
"declaration": true
},
"exclude": [
"node_modules",
Expand Down

0 comments on commit 7de3845

Please sign in to comment.