Skip to content

Commit 4e6bb95

Browse files
authored
Create index.d.ts (#61)
Create Typescript ambient declaration file
1 parent ddbe42a commit 4e6bb95

1 file changed

Lines changed: 102 additions & 0 deletions

File tree

index.d.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
declare module "moleculer-apollo-server" {
2+
import { ServiceSchema, Context } from "moleculer";
3+
import { Config } from "apollo-server-core";
4+
import { OptionsUrlencoded } from "body-parser";
5+
import { SchemaDirectiveVisitor, IResolvers } from "graphql-tools";
6+
7+
export {
8+
GraphQLUpload,
9+
GraphQLExtension,
10+
gql,
11+
ApolloError,
12+
toApolloError,
13+
SyntaxError,
14+
ValidationError,
15+
AuthenticationError,
16+
ForbiddenError,
17+
UserInputError,
18+
defaultPlaygroundOptions,
19+
} from "apollo-server-core";
20+
21+
export * from "graphql-tools";
22+
23+
export interface ApolloServerOptions {
24+
path: string;
25+
disableHealthCheck: boolean;
26+
onHealthCheck: () => {};
27+
}
28+
29+
export class ApolloServer {
30+
createGraphQLServerOptions(req: any, res: any): Promise<any>;
31+
createHandler(options: ApolloServerOptions): void;
32+
supportsUploads(): boolean;
33+
supportsSubscriptions(): boolean;
34+
}
35+
36+
export interface ActionResolverSchema {
37+
action: string;
38+
rootParams?: {
39+
[key: string]: string;
40+
};
41+
dataLoader?: boolean;
42+
nullIfError?: boolean;
43+
params?: { [key: string]: any };
44+
}
45+
46+
export interface ServiceResolverSchema {
47+
[key: string]: {
48+
[key: string]: ActionResolverSchema;
49+
};
50+
}
51+
52+
export interface ServiceRouteCorsOptions {
53+
origin?: string | string[];
54+
methods?: "GET" | "POST" | "PUT" | "DELETE" | "OPTIONS"[];
55+
allowedHeaders?: string[];
56+
exposedHeaders?: string[];
57+
credentials?: boolean;
58+
maxAge?: number;
59+
}
60+
61+
export interface ServiceRouteOptions {
62+
path?: string;
63+
use?: any[];
64+
etag?: boolean;
65+
whitelist?: string[];
66+
authorization?: boolean;
67+
camelCaseNames?: boolean;
68+
aliases?: {
69+
[key: string]: any; // Should discuss more on this. string | AliasSchema, ...
70+
};
71+
bodyParsers?: {
72+
json: boolean;
73+
urlencoded: OptionsUrlencoded;
74+
};
75+
cors?: boolean | ServiceRouteCorsOptions;
76+
mappingPolicy?: "all" | "restrict";
77+
authentication?: boolean;
78+
callOptions?: {
79+
timeout: number;
80+
fallbackResponse?: any;
81+
};
82+
onBeforeCall?: (ctx: Context, route: any, req: any, res: any) => Promise<any>;
83+
onAfterCall?: (ctx: Context, route: any, req: any, res: any) => Promise<any>;
84+
}
85+
86+
export interface ApolloServiceOptions {
87+
typeDefs?: string | string[];
88+
resolvers?: ServiceResolverSchema | IResolvers | Array<IResolvers>;
89+
schemaDirectives?: {
90+
[name: string]: typeof SchemaDirectiveVisitor;
91+
};
92+
routeOptions?: ServiceRouteOptions;
93+
serverOptions?: Config;
94+
}
95+
96+
export function ApolloService(options: ApolloServiceOptions): ServiceSchema;
97+
98+
export function moleculerGql<T>(
99+
typeString: TemplateStringsArray | string,
100+
...placeholders: T[]
101+
): string;
102+
}

0 commit comments

Comments
 (0)