diff --git a/packages/npm/@amazeelabs/gatsby-source-silverback/README.md b/packages/npm/@amazeelabs/gatsby-source-silverback/README.md index 827f31812..2743545e7 100644 --- a/packages/npm/@amazeelabs/gatsby-source-silverback/README.md +++ b/packages/npm/@amazeelabs/gatsby-source-silverback/README.md @@ -54,6 +54,8 @@ The following configuration options are supported: GraphQL query. Defaults to 100. - `type_prefix` **(optional)**: A prefix to be added to all generated GraphQL types. Defaults to `Drupal`. +- `request_timeout` **(optional)**: The timeout for the GraphQL requests in + milliseconds. Defaults to 60_000. The optional credential parameters can be used to enable different workflows. On production, they can be omitted to make sure Drupal handles these requests diff --git a/packages/npm/@amazeelabs/gatsby-source-silverback/src/gatsby-node.ts b/packages/npm/@amazeelabs/gatsby-source-silverback/src/gatsby-node.ts index 2f12e1588..da897d677 100644 --- a/packages/npm/@amazeelabs/gatsby-source-silverback/src/gatsby-node.ts +++ b/packages/npm/@amazeelabs/gatsby-source-silverback/src/gatsby-node.ts @@ -49,6 +49,7 @@ export const pluginOptionsSchema: GatsbyNode['pluginOptionsSchema'] = ({ schema_configuration: Joi.string().optional(), directives: Joi.object().pattern(Joi.string(), Joi.function()).optional(), sources: Joi.object().pattern(Joi.string(), Joi.function()).optional(), + request_timeout: Joi.number().optional().min(1), }); const getForwardedHeaders = (url: URL) => ({ diff --git a/packages/npm/@amazeelabs/gatsby-source-silverback/src/helpers/create-query-executor.ts b/packages/npm/@amazeelabs/gatsby-source-silverback/src/helpers/create-query-executor.ts index 92bffdecf..8ae54ea9b 100644 --- a/packages/npm/@amazeelabs/gatsby-source-silverback/src/helpers/create-query-executor.ts +++ b/packages/npm/@amazeelabs/gatsby-source-silverback/src/helpers/create-query-executor.ts @@ -20,19 +20,23 @@ export const createQueryExecutor = ( throw "No Drupal Url defined. Can't instantiate query executor."; } const url = `${new URL(options.drupal_url).origin}${options.graphql_path}`; - const executor = createNetworkQueryExecutor(url, { - headers: { - ...options?.headers, - ...(options?.auth_user && options?.auth_pass - ? { - Authorization: `Basic ${Buffer.from( - `${options.auth_user}:${options.auth_pass}`, - ).toString('base64')}`, - } - : {}), - ...(options?.auth_key ? { 'api-key': options.auth_key } : {}), + const executor = createNetworkQueryExecutor( + url, + { + headers: { + ...options?.headers, + ...(options?.auth_user && options?.auth_pass + ? { + Authorization: `Basic ${Buffer.from( + `${options.auth_user}:${options.auth_pass}`, + ).toString('base64')}`, + } + : {}), + ...(options?.auth_key ? { 'api-key': options.auth_key } : {}), + }, }, - }); + options.request_timeout, + ); return wrapQueryExecutorWithQueue(executor, { concurrency: options.query_concurrency || 10, }); @@ -44,12 +48,12 @@ export const createQueryExecutor = ( export function createNetworkQueryExecutor( uri: string, fetchOptions: RequestInit = {}, + timeout = 60_000, ): IQueryExecutor { return async function execute(args) { const { query, variables, operationName } = args; let response; - const timeout = 60_000; const signal = timeoutSignal(timeout); signal.onabort = () => console.error( diff --git a/packages/npm/@amazeelabs/gatsby-source-silverback/src/utils.ts b/packages/npm/@amazeelabs/gatsby-source-silverback/src/utils.ts index 1abe7e6bc..7c9572730 100644 --- a/packages/npm/@amazeelabs/gatsby-source-silverback/src/utils.ts +++ b/packages/npm/@amazeelabs/gatsby-source-silverback/src/utils.ts @@ -23,6 +23,8 @@ export type Options = { directives?: Record; // A list of functions that will be available as data source. sources?: Record; + // Request timeout for GraphQL queries in milliseconds. Defaults to 60_000. + request_timeout?: number; }; export const validOptions = (options: {