Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try catch on drupal graphql schemas fetch #378

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/schema/external/drupal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand All @@ -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;
}
};
11 changes: 6 additions & 5 deletions src/schemaLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down