From 4a47ddc8b2ed50aab8658e921e5431f04cec9ef8 Mon Sep 17 00:00:00 2001 From: Alexis Tyler Date: Mon, 19 Apr 2021 14:41:14 +0930 Subject: [PATCH] fix: emit owner event if we update servers from mothership --- app/graphql/schema/utils.ts | 7 +++++++ app/utils.ts | 5 ++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/graphql/schema/utils.ts b/app/graphql/schema/utils.ts index 106efcd47..c60170bc6 100644 --- a/app/graphql/schema/utils.ts +++ b/app/graphql/schema/utils.ts @@ -49,6 +49,7 @@ type makeNullUndefinedAndOptional = { type Server = makeNullUndefinedAndOptional; export const getServers = async (): Promise => { + // Check if we have the servers already cached, if so return them const cachedServers = userCache.get('mine')?.servers; if (cachedServers) { return cachedServers; @@ -75,6 +76,12 @@ export const getServers = async (): Promise => { servers }); + // Get first server's owner object + const owner = servers[0].owner; + + // Publish owner event + await pubsub.publish('owner', owner); + // Return servers from mothership return servers; } diff --git a/app/utils.ts b/app/utils.ts index 805577170..8dee509e5 100644 --- a/app/utils.ts +++ b/app/utils.ts @@ -21,12 +21,11 @@ export const getServers = async (apiKey: string) => fetch(MOTHERSHIP_GRAPHQL_LIN .then(async response => { const { data, errors } = await response.json(); if (errors) { - return new Error(errors[0].message); + throw new Error(errors[0].message); } return data.servers as Promise; }) - .catch(error => { + .catch((error: Error) => { Sentry.captureException(error); - return error; });