From f27b23dde467fbd91d9b78548a1b6fe2ec1529c3 Mon Sep 17 00:00:00 2001 From: estelafs Date: Fri, 5 Jan 2024 14:42:20 -0300 Subject: [PATCH 1/2] added timeout before relaunche server on schema update --- src/server/index.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/server/index.ts b/src/server/index.ts index b7904914d..95b613757 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -186,14 +186,16 @@ class SafeServer { /** Re-launches the server with updated schema */ private async update(): Promise { - const schema = await buildSchema(); - this.httpServer.removeListener('request', this.app); - this.httpServer.close(); - logger.info('🛑 Stopping server'); - this.apolloServer.stop().then(() => { - logger.info('🔁 Reloading server'); - this.start(schema); - }); + setTimeout(async () => { + const schema = await buildSchema(); + this.httpServer.removeListener('request', this.app); + this.httpServer.close(); + logger.info('🛑 Stopping server'); + this.apolloServer.stop().then(() => { + logger.info('🔁 Reloading server'); + this.start(schema); + }); + }, 5000); } } From 9f3e1a2fd8c7fcdbbeaa62964b8fc419ec51fc34 Mon Sep 17 00:00:00 2001 From: estelafs Date: Tue, 9 Jan 2024 12:06:48 -0300 Subject: [PATCH 2/2] don't refresh schema on calculated fields permissions updates --- src/server/index.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/server/index.ts b/src/server/index.ts index 6288c8b09..fe45578b5 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -107,7 +107,13 @@ class SafeServer { const updatedDocFields = Object.keys( data.updateDescription.updatedFields ); + // Permissions update on the fields should not be considered as a change of the schema + const updatePermissions = Object.hasOwn( + data.updateDescription.updatedFields, + 'permissions' + ); if ( + !updatePermissions && updatedDocFields.some( (f) => fieldsThatRequireSchemaUpdate.includes(f) && @@ -246,16 +252,14 @@ class SafeServer { /** Re-launches the server with updated schema */ private async update(): Promise { - setTimeout(async () => { - const schema = await buildSchema(); - this.httpServer.removeListener('request', this.app); - this.httpServer.close(); - logger.info('🛑 Stopping server'); - this.apolloServer.stop().then(() => { - logger.info('🔁 Reloading server'); - this.start(schema); - }); - }, 5000); + const schema = await buildSchema(); + this.httpServer.removeListener('request', this.app); + this.httpServer.close(); + logger.info('🛑 Stopping server'); + this.apolloServer.stop().then(() => { + logger.info('🔁 Reloading server'); + this.start(schema); + }); } }