File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -91,6 +91,7 @@ declare module "moleculer-apollo-server" {
9191 } ;
9292 routeOptions ?: ServiceRouteOptions ;
9393 serverOptions ?: Config ;
94+ autoUpdateSchema ?: boolean ;
9495 }
9596
9697 export function ApolloService ( options : ApolloServiceOptions ) : ServiceSchema ;
Original file line number Diff line number Diff line change @@ -24,12 +24,15 @@ module.exports = function(mixinOptions) {
2424 serverOptions : { } ,
2525 createAction : true ,
2626 subscriptionEventName : "graphql.publish" ,
27+ autoUpdateSchema : true ,
2728 } ) ;
2829
2930 const serviceSchema = {
3031 events : {
3132 "$services.changed" ( ) {
32- this . invalidateGraphQLSchema ( ) ;
33+ if ( mixinOptions . autoUpdateSchema ) {
34+ this . invalidateGraphQLSchema ( ) ;
35+ }
3336 } ,
3437 [ mixinOptions . subscriptionEventName ] ( event ) {
3538 if ( this . pubsub ) {
Original file line number Diff line number Diff line change @@ -208,6 +208,33 @@ describe("Test Service", () => {
208208 await stop ( ) ;
209209 } ) ;
210210
211+ it ( "should not invalidate schema when autoUpdateSchema is false" , async ( ) => {
212+ const { broker, svc, stop } = await startService ( {
213+ autoUpdateSchema : false
214+ } ) ;
215+ svc . invalidateGraphQLSchema = jest . fn ( ) ;
216+
217+ await broker . broadcastLocal ( "$services.changed" ) ;
218+
219+ expect ( svc . invalidateGraphQLSchema ) . toBeCalledTimes ( 0 ) ;
220+
221+ await stop ( ) ;
222+ } ) ;
223+
224+ it ( "should not invalidate schema when autoUpdateSchema is true" , async ( ) => {
225+ const { broker, svc, stop } = await startService ( {
226+ autoUpdateSchema : true
227+ } ) ;
228+ svc . invalidateGraphQLSchema = jest . fn ( ) ;
229+
230+ await broker . broadcastLocal ( "$services.changed" ) ;
231+
232+ expect ( svc . invalidateGraphQLSchema ) . toBeCalledTimes ( 1 ) ;
233+ expect ( svc . invalidateGraphQLSchema ) . toBeCalledWith ( ) ;
234+
235+ await stop ( ) ;
236+ } ) ;
237+
211238 it ( "should subscribe to the default subscription event" , async ( ) => {
212239 const { broker, svc, stop } = await startService ( ) ;
213240
You can’t perform that action at this time.
0 commit comments