From ac2e40144d2b9e39a2f28c518a525414bd4c143a Mon Sep 17 00:00:00 2001 From: Ian Copp Date: Mon, 5 Mar 2018 00:15:59 -0800 Subject: [PATCH 1/3] Improved generic typings for makeExecutableSchema --- src/Interfaces.ts | 40 ++++++++++++++++++++-------------------- src/index.ts | 1 + src/schemaGenerator.ts | 4 ++-- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/Interfaces.ts b/src/Interfaces.ts index b7b015f5fed..2cf163e6caa 100644 --- a/src/Interfaces.ts +++ b/src/Interfaces.ts @@ -21,11 +21,11 @@ export interface IResolverValidationOptions { allowResolversNotInSchema?: boolean; } -export interface IResolverOptions { - resolve?: IFieldResolver; - subscribe?: IFieldResolver; - __resolveType?: GraphQLTypeResolver; - __isTypeOf?: GraphQLIsTypeOfFn; +export interface IResolverOptions { + resolve?: IFieldResolver; + subscribe?: IFieldResolver; + __resolveType?: GraphQLTypeResolver; + __isTypeOf?: GraphQLIsTypeOfFn; } export type MergeInfo = { @@ -47,14 +47,14 @@ export type IFieldResolver = ( export type ITypedef = (() => ITypedef[]) | string | DocumentNode; export type ITypeDefinitions = ITypedef | ITypedef[]; -export type IResolverObject = { - [key: string]: IFieldResolver | IResolverOptions; +export type IResolverObject = { + [key: string]: IFieldResolver | IResolverOptions; }; export type IEnumResolver = { [key: string]: string | number }; -export interface IResolvers { +export interface IResolvers { [key: string]: | (() => any) - | IResolverObject + | IResolverObject | GraphQLScalarType | IEnumResolver; } @@ -62,22 +62,22 @@ export interface ILogger { log: (message: string | Error) => void; } -export interface IConnectorCls { - new (context?: any): any; +export interface IConnectorCls { + new (context?: TContext): any; } -export type IConnectorFn = (context?: any) => any; -export type IConnector = IConnectorCls | IConnectorFn; +export type IConnectorFn = (context?: TContext) => any; +export type IConnector = IConnectorCls | IConnectorFn; -export type IConnectors = { [key: string]: IConnector }; +export type IConnectors = { [key: string]: IConnector }; -export interface IExecutableSchemaDefinition { +export interface IExecutableSchemaDefinition { typeDefs: ITypeDefinitions; - resolvers?: IResolvers | Array; - connectors?: IConnectors; + resolvers?: IResolvers | Array>; + connectors?: IConnectors; logger?: ILogger; allowUndefinedInResolve?: boolean; resolverValidationOptions?: IResolverValidationOptions; - directiveResolvers?: IDirectiveResolvers; + directiveResolvers?: IDirectiveResolvers; parseOptions?: GraphQLParseOptions; } @@ -88,7 +88,7 @@ export type IFieldIteratorFn = ( ) => void; export type NextResolverFn = () => Promise; -export type DirectiveResolverFn = ( +export type DirectiveResolverFn = ( next: NextResolverFn, source: TSource, args: { [argName: string]: any }, @@ -96,7 +96,7 @@ export type DirectiveResolverFn = ( info: GraphQLResolveInfo, ) => any; -export interface IDirectiveResolvers { +export interface IDirectiveResolvers { [directiveName: string]: DirectiveResolverFn; } diff --git a/src/index.ts b/src/index.ts index a758157fff0..bea5d6aaa99 100755 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ +export * from './interfaces'; export * from './schemaGenerator'; export * from './mock'; export * from './stitching'; diff --git a/src/schemaGenerator.ts b/src/schemaGenerator.ts index 7fa00786f2f..d543523ca8d 100644 --- a/src/schemaGenerator.ts +++ b/src/schemaGenerator.ts @@ -111,7 +111,7 @@ function _generateSchema( return schema; } -function makeExecutableSchema({ +function makeExecutableSchema({ typeDefs, resolvers = {}, connectors, @@ -120,7 +120,7 @@ function makeExecutableSchema({ resolverValidationOptions = {}, directiveResolvers = null, parseOptions = {}, -}: IExecutableSchemaDefinition) { +}: IExecutableSchemaDefinition) { const jsSchema = _generateSchema( typeDefs, resolvers, From 1ad8d0501c7a5f39592c90840c6c85c961f70da7 Mon Sep 17 00:00:00 2001 From: Ian Copp Date: Mon, 5 Mar 2018 00:21:30 -0800 Subject: [PATCH 2/3] Add changelog entry for PR #662 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f1be3acf1c..5b633c1f745 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ### vNEXT * When concatenating errors maintain a reference to the original for use downstream [Issue #480](https://github.com/apollographql/graphql-tools/issues/480) [PR #637](https://github.com/apollographql/graphql-tools/pull/637) - +* Improve generic typings for several resolver-related interfaces [PR #662](https://github.com/apollographql/graphql-tools/pull/662) ### v2.21.0 From 2da6f13ad40771bf607b259e71e7ad045185f3bf Mon Sep 17 00:00:00 2001 From: Mikhail Novikov Date: Tue, 13 Mar 2018 11:13:40 +0200 Subject: [PATCH 3/3] Update index.ts --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index bea5d6aaa99..4f3e3249c93 100755 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -export * from './interfaces'; +export * from './Interfaces'; export * from './schemaGenerator'; export * from './mock'; export * from './stitching';