Skip to content

Commit 59cba3f

Browse files
Add options.autoUpdateSchema (#63)
Add new option to allow/disallow automatic updating of schema. Co-authored-by: Shawn McKnight <mck321@gmail.com>
1 parent 73a18da commit 59cba3f

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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;

src/service.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff 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) {

test/unit/service.spec.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)