From 6eaff4dda0dd8ec0ede816902e8529f3c1234b31 Mon Sep 17 00:00:00 2001 From: pjohans Date: Mon, 10 Jun 2024 15:23:54 +0200 Subject: [PATCH] try catch on drupal graphql schemas fetch --- src/schema/external/drupal.js | 21 +++++++++++++++------ src/schemaLoader.js | 11 ++++++----- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/schema/external/drupal.js b/src/schema/external/drupal.js index 3bcf2b94..ce9e74ab 100644 --- a/src/schema/external/drupal.js +++ b/src/schema/external/drupal.js @@ -2,11 +2,13 @@ import request from "superagent"; import { introspectSchema, wrapSchema, RenameTypes } from "@graphql-tools/wrap"; import { print } from "graphql"; import config from "../../config"; +import { log } from "dbc-node-logger"; const executor = async ({ document, variables }) => { const query = print(document); const url = config.datasources.backend.url; const fetchResult = await request.post(url).send({ query, variables }); + return await fetchResult.body; }; @@ -17,11 +19,18 @@ const typeNameMap = { }; export default async () => { - const executableSchema = wrapSchema({ - schema: await introspectSchema(executor), - executor, - transforms: [new RenameTypes((name) => typeNameMap[name] || name)], - }); + try { + const executableSchema = wrapSchema({ + schema: await introspectSchema(executor), + executor, + transforms: [new RenameTypes((name) => typeNameMap[name] || name)], + }); - return executableSchema; + return executableSchema; + } catch (e) { + log.error("Error fetching graphql schema from drupal backend", { + response: e.message, + }); + return false; + } }; diff --git a/src/schemaLoader.js b/src/schemaLoader.js index edbe6281..23136ca4 100644 --- a/src/schemaLoader.js +++ b/src/schemaLoader.js @@ -112,11 +112,12 @@ export async function getExecutableSchema({ } // Merge external and internal schemas - const mergedSchema = loadExternal - ? mergeSchemas({ - schemas: [externalSchema, internalSchema], - }) - : internalSchema; + const mergedSchema = + loadExternal && externalSchema + ? mergeSchemas({ + schemas: [externalSchema, internalSchema], + }) + : internalSchema; // Filter schema according to permissions of Smaug client // If no valid accessToken is given (no smaug client), we allow to introspect