Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: export Typescript definitions and fix resulting type errors #2452

Merged
merged 5 commits into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -718,6 +718,49 @@ export class ModelConnectionTransformer extends Transformer {
}
}

private extendTypeWithConnection(
ctx: TransformerContext,
parent: ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode,
field: FieldDefinitionNode,
returnType: ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode,
sortKeyInfo?: { fieldName: string, typeName: SortKeyFieldInfoTypeName, model?: string, keyName?: string }
) {
this.generateModelXConnectionType(ctx, returnType)

// Extensions are not allowed to redeclare fields so we must replace
// it in place.
const type = ctx.getType(parent.name.value) as ObjectTypeDefinitionNode
if (
type &&
(type.kind === Kind.OBJECT_TYPE_DEFINITION || type.kind === Kind.INTERFACE_TYPE_DEFINITION)
) {
// 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, [...f.directives])
return updated
}
return f;
}
)
const updatedType = {
...type,
fields: newFields
}
ctx.putType(updatedType)

if (!this.typeExist('ModelSortDirection', ctx)) {
const modelSortDirection = makeModelSortDirectionEnumObject()
ctx.addEnum(modelSortDirection)
}

this.generateFilterAndKeyConditionInputs(ctx, returnType, sortKeyInfo)
} else {
throw new InvalidDirectiveError(`Could not find a object or interface type named ${parent.name.value}.`)
}
}

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