Add header parameter support to GraphQL node

This commit is contained in:
Istvan Richter 2020-04-01 09:08:18 +02:00
parent 618ae1a82b
commit 76a161e3e1

View file

@ -1,5 +1,6 @@
import { IExecuteFunctions } from 'n8n-core'; import { IExecuteFunctions } from 'n8n-core';
import { import {
IDataObject,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
@ -155,6 +156,41 @@ export class GraphQL implements INodeType {
}, },
description: 'Name of the property to which to write the response data.', description: 'Name of the property to which to write the response data.',
}, },
// Header Parameters
{
displayName: 'Headers',
name: 'headerParametersUi',
placeholder: 'Add Header',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
description: 'The headers to send.',
default: {},
options: [
{
name: 'parameter',
displayName: 'Header',
values: [
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
description: 'Name of the header.',
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
description: 'Value to set for the header.',
},
]
},
],
},
] ]
}; };
@ -172,9 +208,17 @@ export class GraphQL implements INodeType {
const requestFormat = this.getNodeParameter('requestFormat', itemIndex, 'graphql') as string; const requestFormat = this.getNodeParameter('requestFormat', itemIndex, 'graphql') as string;
const responseFormat = this.getNodeParameter('responseFormat', 0) as string; const responseFormat = this.getNodeParameter('responseFormat', 0) as string;
const { parameter }: { parameter?: { name: string, value: string }[] } = this
.getNodeParameter('headerParametersUi', itemIndex, {}) as IDataObject;
const headerParameters = (parameter || []).reduce((result, item) => ({
...result,
[item.name]: item.value
}), {});
requestOptions = { requestOptions = {
headers: { headers: {
'content-type': `application/${requestFormat}`, 'content-type': `application/${requestFormat}`,
...headerParameters
}, },
method: requestMethod, method: requestMethod,
uri: endpoint, uri: endpoint,