diff --git a/packages/nodes-base/nodes/GraphQL/GraphQL.node.ts b/packages/nodes-base/nodes/GraphQL/GraphQL.node.ts index e18b2057d3..25b347f502 100644 --- a/packages/nodes-base/nodes/GraphQL/GraphQL.node.ts +++ b/packages/nodes-base/nodes/GraphQL/GraphQL.node.ts @@ -25,7 +25,37 @@ export class GraphQL implements INodeType { }, inputs: ['main'], outputs: ['main'], + credentials: [ + { + name: 'httpHeaderAuth', + required: true, + displayOptions: { + show: { + authentication: [ + 'headerAuth', + ], + }, + }, + }, + ], properties: [ + { + displayName: 'Authentication', + name: 'authentication', + type: 'options', + options: [ + { + name: 'Header Auth', + value: 'headerAuth', + }, + { + name: 'None', + value: 'none', + }, + ], + default: 'none', + description: 'The way to authenticate.', + }, { displayName: 'HTTP Request Method', name: 'requestMethod', @@ -200,6 +230,7 @@ export class GraphQL implements INodeType { async execute(this: IExecuteFunctions): Promise { const items = this.getInputData(); + const httpHeaderAuth = this.getCredentials('httpHeaderAuth'); let requestOptions: OptionsWithUri & RequestPromiseOptions; @@ -228,6 +259,11 @@ export class GraphQL implements INodeType { rejectUnauthorized: !this.getNodeParameter('allowUnauthorizedCerts', itemIndex, false) as boolean, }; + // Add credentials if any are set + if (httpHeaderAuth !== undefined) { + requestOptions.headers![httpHeaderAuth.name as string] = httpHeaderAuth.value; + } + const gqlQuery = this.getNodeParameter('query', itemIndex, '') as string; if (requestMethod === 'GET') { requestOptions.qs = {