-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathindex.d.ts
More file actions
169 lines (149 loc) · 4.57 KB
/
index.d.ts
File metadata and controls
169 lines (149 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import { IExecutableSchemaDefinition } from "@graphql-tools/schema";
import { GraphQLSchema, GraphQLScalarType } from "graphql";
import { PubSub } from "graphql-subscriptions";
import { WebSocketServer } from "ws";
import { Context, Service, ServiceSchema } from "moleculer";
import { ApiRouteSchema, GatewayResponse, IncomingRequest } from "moleculer-web";
import {
ApolloServer as ApolloServerBase,
BaseContext,
ApolloServerOptions as BaseApolloServerOptions
} from "@apollo/server";
import { ServerOptions as WsServerOptions } from "graphql-ws";
interface GraphQLActionOptions {
query?: string | string[];
mutation?: string | string[];
subscription?: string | string[];
type?: string | string[];
interface?: string | string[];
union?: string | string[];
enum?: string | string[];
input?: string | string[];
tags?: string[];
filter?: string;
dataLoaderOptions?: any;
dataLoaderBatchParam?: string;
}
declare module "moleculer-apollo-server" {
export { GraphQLError } from "graphql";
export type ContextCreator = (args: {
req: IncomingRequest;
res: GatewayResponse;
}) => BaseContext | Promise<BaseContext>;
export interface ApolloServerOptions {
path: string;
subscriptions?: boolean | WsServerOptions;
}
export class ApolloServer extends ApolloServerBase {
createHandler(
context: ContextCreator
): (req: IncomingRequest, res: GatewayResponse) => Promise<void>;
}
export interface ActionResolverSchema {
action: string;
rootParams?: {
[key: string]: string;
};
dataLoader?: boolean;
nullIfError?: boolean;
skipNullKeys?: boolean;
params?: { [key: string]: any };
}
export interface ServiceResolverSchema {
[key: string]:
| {
[key: string]: ActionResolverSchema;
}
| GraphQLScalarType;
}
export interface ServiceGraphQLSettings {
query?: string | string[];
mutation?: string | string[];
subscription?: string | string[];
type?: string | string[];
interface?: string | string[];
union?: string | string[];
enum?: string | string[];
input?: string | string[];
resolvers?: ServiceResolverSchema;
}
export interface ApolloMixinOptions {
serverOptions?: Partial<BaseApolloServerOptions<BaseContext>> & {
subscriptions?: boolean | WsServerOptions;
};
routeOptions?: ApiRouteSchema;
typeDefs?: string | string[];
resolvers?: ServiceResolverSchema;
subscriptionEventName?: string;
invalidateEventName?: string;
createAction?: boolean;
checkActionVisibility?: boolean;
autoUpdateSchema?: boolean;
}
export interface GraphQLContext extends BaseContext {
ctx: Context;
service: Service;
params: any;
dataLoaders: Map<string, any>;
}
export interface ApolloServiceMethods {
invalidateGraphQLSchema(): void;
getFieldName(declaration: string): string;
getResolverActionName(service: string, action: string): string;
createServiceResolvers(
serviceName: string,
resolvers: { [key: string]: ActionResolverSchema }
): { [key: string]: Function };
createActionResolver(actionName: string, def?: ActionResolverSchema): Function;
getDataLoaderMapKey(actionName: string, staticParams: object, args: object): string;
buildDataLoader(
ctx: Context,
actionName: string,
batchedParamKey: string,
staticParams: object,
args: object,
options?: { hashCacheKey?: boolean }
): any;
buildLoaderOptionMap(services: ServiceSchema[]): void;
createAsyncIteratorResolver(
actionName: string,
tags?: string[],
filter?: string
): { subscribe: Function; resolve: Function };
generateGraphQLSchema(services: ServiceSchema[]): Promise<GraphQLSchema>;
makeExecutableSchema(schemaDef: IExecutableSchemaDefinition): Promise<GraphQLSchema>;
createPubSub(): PubSub | Promise<PubSub>;
prepareGraphQLSchema(): Promise<void>;
createGraphqlContext(args: { req: any }): GraphQLContext;
prepareContextParams?(
mergedParams: any,
actionName: string,
context: GraphQLContext,
root: any,
args: any
): Promise<any>;
}
export interface ApolloServiceLocalVars {
apolloServer?: ApolloServer;
graphqlHandler?: Function;
graphqlSchema?: GraphQLSchema;
shouldUpdateGraphqlSchema: boolean;
dataLoaderOptions: Map<string, any>;
dataLoaderBatchParams: Map<string, any>;
pubsub?: PubSub;
wsServer?: WebSocketServer;
}
export interface ApolloServiceSettings {
graphql?: ServiceGraphQLSettings;
}
export function ApolloService(options: ApolloMixinOptions): ServiceSchema;
export function moleculerGql(
typeString: TemplateStringsArray | string,
...placeholders: any[]
): string;
}
declare module "moleculer" {
interface ActionSchema {
graphql?: GraphQLActionOptions;
}
}