Skip to content

Commit 8fa5927

Browse files
icebobclaude
andcommitted
Improve TypeScript definitions for Moleculer 0.15 compatibility
- Import Context and Service types from moleculer - Add GraphQLContext interface for the context object created per request - Use Context type instead of any for buildDataLoader ctx parameter - Use GraphQLContext as return type for createGraphqlContext and prepareContextParams Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fe1820f commit 8fa5927

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

index.d.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { GraphQLSchema, GraphQLScalarType } from "graphql";
33
import { PubSub } from "graphql-subscriptions";
44
import { WebSocketServer } from "ws";
55

6-
import { ServiceSchema } from "moleculer";
6+
import { Context, Service, ServiceSchema } from "moleculer";
77
import { ApiRouteSchema, GatewayResponse, IncomingRequest } from "moleculer-web";
88
import {
99
ApolloServer as ApolloServerBase,
@@ -94,6 +94,13 @@ declare module "moleculer-apollo-server" {
9494
autoUpdateSchema?: boolean;
9595
}
9696

97+
export interface GraphQLContext extends BaseContext {
98+
ctx: Context;
99+
service: Service;
100+
params: any;
101+
dataLoaders: Map<string, any>;
102+
}
103+
97104
export interface ApolloServiceMethods {
98105
invalidateGraphQLSchema(): void;
99106
getFieldName(declaration: string): string;
@@ -105,7 +112,7 @@ declare module "moleculer-apollo-server" {
105112
createActionResolver(actionName: string, def?: ActionResolverSchema): Function;
106113
getDataLoaderMapKey(actionName: string, staticParams: object, args: object): string;
107114
buildDataLoader(
108-
ctx: any,
115+
ctx: Context,
109116
actionName: string,
110117
batchedParamKey: string,
111118
staticParams: object,
@@ -122,11 +129,11 @@ declare module "moleculer-apollo-server" {
122129
makeExecutableSchema(schemaDef: IExecutableSchemaDefinition): Promise<GraphQLSchema>;
123130
createPubSub(): PubSub | Promise<PubSub>;
124131
prepareGraphQLSchema(): Promise<void>;
125-
createGraphqlContext(args: { req: any }): BaseContext;
132+
createGraphqlContext(args: { req: any }): GraphQLContext;
126133
prepareContextParams?(
127134
mergedParams: any,
128135
actionName: string,
129-
context: BaseContext,
136+
context: GraphQLContext,
130137
root: any,
131138
args: any
132139
): Promise<any>;

0 commit comments

Comments
 (0)