Add header authentication to GraphQL node (#1805)

This commit is contained in:
Jacob Spizziri 2021-05-19 20:04:43 -05:00 committed by GitHub
parent 7ccc0f40a2
commit d3aa637ff4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -25,7 +25,37 @@ export class GraphQL implements INodeType {
}, },
inputs: ['main'], inputs: ['main'],
outputs: ['main'], outputs: ['main'],
credentials: [
{
name: 'httpHeaderAuth',
required: true,
displayOptions: {
show: {
authentication: [
'headerAuth',
],
},
},
},
],
properties: [ 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', displayName: 'HTTP Request Method',
name: 'requestMethod', name: 'requestMethod',
@ -200,6 +230,7 @@ export class GraphQL implements INodeType {
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> { async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData(); const items = this.getInputData();
const httpHeaderAuth = this.getCredentials('httpHeaderAuth');
let requestOptions: OptionsWithUri & RequestPromiseOptions; let requestOptions: OptionsWithUri & RequestPromiseOptions;
@ -228,6 +259,11 @@ export class GraphQL implements INodeType {
rejectUnauthorized: !this.getNodeParameter('allowUnauthorizedCerts', itemIndex, false) as boolean, 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; const gqlQuery = this.getNodeParameter('query', itemIndex, '') as string;
if (requestMethod === 'GET') { if (requestMethod === 'GET') {
requestOptions.qs = { requestOptions.qs = {