11import { IExecutableSchemaDefinition } from "@graphql-tools/schema" ;
2- import { GraphQLSchema } from "graphql" ;
2+ import { GraphQLSchema , GraphQLScalarType } from "graphql" ;
33import { PubSub } from "graphql-subscriptions" ;
44import { WebSocketServer } from "ws" ;
55
66import { ServiceSchema } from "moleculer" ;
77import { ApiRouteSchema , GatewayResponse , IncomingRequest } from "moleculer-web" ;
8- import { ApolloServer as ApolloServerBase , BaseContext , ApolloServerOptions as BaseApolloServerOptions } from "@apollo/server" ;
8+ import {
9+ ApolloServer as ApolloServerBase ,
10+ BaseContext ,
11+ ApolloServerOptions as BaseApolloServerOptions
12+ } from "@apollo/server" ;
913import { ServerOptions as WsServerOptions } from "graphql-ws" ;
1014
11- declare module "moleculer-apollo-server" {
15+ interface GraphQLActionOptions {
16+ query ?: string | string [ ] ;
17+ mutation ?: string | string [ ] ;
18+ subscription ?: string | string [ ] ;
19+ type ?: string | string [ ] ;
20+ interface ?: string | string [ ] ;
21+ union ?: string | string [ ] ;
22+ enum ?: string | string [ ] ;
23+ input ?: string | string [ ] ;
24+ tags ?: string [ ] ;
25+ filter ?: string ;
26+ dataLoaderOptions ?: any ;
27+ dataLoaderBatchParam ?: string ;
28+ }
1229
30+ declare module "moleculer-apollo-server" {
1331 export { GraphQLError } from "graphql" ;
1432
15- export type ContextCreator = ( args : { req : IncomingRequest ; res : GatewayResponse } ) => BaseContext | Promise < BaseContext > ;
33+ export type ContextCreator = ( args : {
34+ req : IncomingRequest ;
35+ res : GatewayResponse ;
36+ } ) => BaseContext | Promise < BaseContext > ;
1637
1738 export interface ApolloServerOptions {
1839 path : string ;
1940 subscriptions ?: boolean | WsServerOptions ;
2041 }
2142
2243 export class ApolloServer extends ApolloServerBase {
23- createHandler ( context : ContextCreator ) : ( req : IncomingRequest , res : GatewayResponse ) => Promise < void > ;
44+ createHandler (
45+ context : ContextCreator
46+ ) : ( req : IncomingRequest , res : GatewayResponse ) => Promise < void > ;
2447 }
2548
2649 export interface ActionResolverSchema {
@@ -34,25 +57,12 @@ declare module "moleculer-apollo-server" {
3457 params ?: { [ key : string ] : any } ;
3558 }
3659
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-
5260 export interface ServiceResolverSchema {
53- [ key : string ] : {
54- [ key : string ] : ActionResolverSchema ;
55- } ;
61+ [ key : string ] :
62+ | {
63+ [ key : string ] : ActionResolverSchema ;
64+ }
65+ | GraphQLScalarType ;
5666 }
5767
5868 export interface ServiceGraphQLSettings {
@@ -67,17 +77,6 @@ declare module "moleculer-apollo-server" {
6777 resolvers ?: ServiceResolverSchema ;
6878 }
6979
70- type CorsMethods = "GET" | "POST" | "PUT" | "DELETE" | "OPTIONS" ;
71-
72- export interface ServiceRouteCorsOptions {
73- origin ?: string | string [ ] ;
74- methods ?: CorsMethods | CorsMethods [ ] ;
75- allowedHeaders ?: string [ ] ;
76- exposedHeaders ?: string [ ] ;
77- credentials ?: boolean ;
78- maxAge ?: number ;
79- }
80-
8180 export interface ApolloServiceOptions {
8281 serverOptions ?: BaseApolloServerOptions < BaseContext > & {
8382 subscriptions ?: boolean | WsServerOptions ;
@@ -102,18 +101,38 @@ declare module "moleculer-apollo-server" {
102101 invalidateGraphQLSchema ( ) : void ;
103102 getFieldName ( declaration : string ) : string ;
104103 getResolverActionName ( service : string , action : string ) : string ;
105- createServiceResolvers ( serviceName : string , resolvers : { [ key : string ] : ActionResolverSchema } ) : { [ key : string ] : Function } ;
104+ createServiceResolvers (
105+ serviceName : string ,
106+ resolvers : { [ key : string ] : ActionResolverSchema }
107+ ) : { [ key : string ] : Function } ;
106108 createActionResolver ( actionName : string , def ?: ActionResolverSchema ) : Function ;
107109 getDataLoaderMapKey ( actionName : string , staticParams : object , args : object ) : string ;
108- buildDataLoader ( ctx : any , actionName : string , batchedParamKey : string , staticParams : object , args : object , options ?: { hashCacheKey ?: boolean } ) : any ;
110+ buildDataLoader (
111+ ctx : any ,
112+ actionName : string ,
113+ batchedParamKey : string ,
114+ staticParams : object ,
115+ args : object ,
116+ options ?: { hashCacheKey ?: boolean }
117+ ) : any ;
109118 buildLoaderOptionMap ( services : ServiceSchema [ ] ) : void ;
110- createAsyncIteratorResolver ( actionName : string , tags ?: string [ ] , filter ?: string ) : { subscribe : Function ; resolve : Function } ;
119+ createAsyncIteratorResolver (
120+ actionName : string ,
121+ tags ?: string [ ] ,
122+ filter ?: string
123+ ) : { subscribe : Function ; resolve : Function } ;
111124 generateGraphQLSchema ( services : ServiceSchema [ ] ) : Promise < GraphQLSchema > ;
112125 makeExecutableSchema ( schemaDef : IExecutableSchemaDefinition ) : Promise < GraphQLSchema > ;
113126 createPubSub ( ) : PubSub | Promise < PubSub > ;
114127 prepareGraphQLSchema ( ) : Promise < void > ;
115128 createGraphqlContext ( args : { req : any } ) : BaseContext ;
116- prepareContextParams ?( mergedParams : any , actionName : string , context : BaseContext , root : any , args : any ) : Promise < any > ;
129+ prepareContextParams ?(
130+ mergedParams : any ,
131+ actionName : string ,
132+ context : BaseContext ,
133+ root : any ,
134+ args : any
135+ ) : Promise < any > ;
117136 }
118137
119138 export interface ApolloServiceLocalVars {
@@ -134,3 +153,9 @@ declare module "moleculer-apollo-server" {
134153 ...placeholders : any [ ]
135154 ) : string ;
136155}
156+
157+ declare module "moleculer" {
158+ interface ActionSchema {
159+ graphql ?: GraphQLActionOptions ;
160+ }
161+ }
0 commit comments