Skip to content

Commit a82e09c

Browse files
committed
improve d.ts
1 parent ba175a6 commit a82e09c

1 file changed

Lines changed: 43 additions & 13 deletions

File tree

index.d.ts

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@ import { WebSocketServer } from "ws";
55

66
import { ServiceSchema } from "moleculer";
77
import { ApiRouteSchema, GatewayResponse, IncomingRequest } from "moleculer-web";
8-
import { ApolloServer as ApolloServerBase, BaseContext } from "@apollo/server";
8+
import { ApolloServer as ApolloServerBase, BaseContext, ApolloServerOptions as BaseApolloServerOptions } from "@apollo/server";
99
import { ServerOptions as WsServerOptions } from "graphql-ws";
1010

1111
declare module "moleculer-apollo-server" {
1212

1313
export { GraphQLError } from "graphql";
1414

15-
export type ContextCreator = (req: IncomingRequest, res: GatewayResponse,) => BaseContext | Promise<BaseContext>;
15+
export type ContextCreator = (args: { req: IncomingRequest; res: GatewayResponse }) => BaseContext | Promise<BaseContext>;
1616

1717
export interface ApolloServerOptions {
1818
path: string;
1919
subscriptions?: boolean | WsServerOptions;
2020
}
2121

2222
export class ApolloServer extends ApolloServerBase {
23-
createHandler(context: ContextCreator): void;
23+
createHandler(context: ContextCreator): (req: IncomingRequest, res: GatewayResponse) => Promise<void>;
2424
}
2525

2626
export interface ActionResolverSchema {
@@ -34,12 +34,39 @@ declare module "moleculer-apollo-server" {
3434
params?: { [key: string]: any };
3535
}
3636

37+
export interface GraphQLActionOptions {
38+
query?: string | string[];
39+
mutation?: string | string[];
40+
subscription?: string | string[];
41+
type?: string | string[];
42+
interface?: string | string[];
43+
union?: string | string[];
44+
enum?: string | string[];
45+
input?: string | string[];
46+
tags?: string[];
47+
filter?: string;
48+
dataLoaderOptions?: any;
49+
dataLoaderBatchParam?: string;
50+
}
51+
3752
export interface ServiceResolverSchema {
3853
[key: string]: {
3954
[key: string]: ActionResolverSchema;
4055
};
4156
}
4257

58+
export interface ServiceGraphQLSettings {
59+
query?: string | string[];
60+
mutation?: string | string[];
61+
subscription?: string | string[];
62+
type?: string | string[];
63+
interface?: string | string[];
64+
union?: string | string[];
65+
enum?: string | string[];
66+
input?: string | string[];
67+
resolvers?: ServiceResolverSchema;
68+
}
69+
4370
type CorsMethods = "GET" | "POST" | "PUT" | "DELETE" | "OPTIONS";
4471

4572
export interface ServiceRouteCorsOptions {
@@ -52,7 +79,9 @@ declare module "moleculer-apollo-server" {
5279
}
5380

5481
export interface ApolloServiceOptions {
55-
serverOptions?: ApolloServerOptions;
82+
serverOptions?: BaseApolloServerOptions<BaseContext> & {
83+
subscriptions?: boolean | WsServerOptions;
84+
};
5685
routeOptions?: ApiRouteSchema;
5786

5887
typeDefs?: string | string[];
@@ -73,17 +102,18 @@ declare module "moleculer-apollo-server" {
73102
invalidateGraphQLSchema(): void;
74103
getFieldName(declaration: string): string;
75104
getResolverActionName(service: string, action: string): string;
76-
createServiceResolvers(serviceName: string, resolvers: ServiceResolverSchema): { [key: string]: ActionResolverSchema };
77-
createActionResolver(serviceName: string, actionName: string, resolver: ActionResolverSchema): Function;
105+
createServiceResolvers(serviceName: string, resolvers: { [key: string]: ActionResolverSchema }): { [key: string]: Function };
106+
createActionResolver(actionName: string, def?: ActionResolverSchema): Function;
78107
getDataLoaderMapKey(actionName: string, staticParams: object, args: object): string;
79-
// buildDataLoader();
80-
//buildLoaderOptionMap(services: ServiceSchema[]): void;
81-
// createAsyncIteratorResolver
82-
generateGraphQLSchema(services: ServiceSchema[]): Promise<string>;
108+
buildDataLoader(ctx: any, actionName: string, batchedParamKey: string, staticParams: object, args: object, options?: { hashCacheKey?: boolean }): any;
109+
buildLoaderOptionMap(services: ServiceSchema[]): void;
110+
createAsyncIteratorResolver(actionName: string, tags?: string[], filter?: string): { subscribe: Function; resolve: Function };
111+
generateGraphQLSchema(services: ServiceSchema[]): GraphQLSchema;
83112
makeExecutableSchema(schemaDef: IExecutableSchemaDefinition): GraphQLSchema;
84113
createPubSub(): PubSub | Promise<PubSub>;
85114
prepareGraphQLSchema(): Promise<void>;
86-
createGraphqlContext(args: unknown): BaseContext;
115+
createGraphqlContext(args: { req: any }): BaseContext;
116+
prepareContextParams?(mergedParams: any, actionName: string, context: BaseContext, root: any, args: any): Promise<any>;
87117
}
88118

89119
export interface ApolloServiceLocalVars {
@@ -99,8 +129,8 @@ declare module "moleculer-apollo-server" {
99129

100130
export function ApolloService(options: ApolloServiceOptions): ServiceSchema;
101131

102-
export function moleculerGql<T>(
132+
export function moleculerGql(
103133
typeString: TemplateStringsArray | string,
104-
...placeholders: T[]
134+
...placeholders: any[]
105135
): string;
106136
}

0 commit comments

Comments
 (0)