2022-07-04 02:12:08 -07:00
|
|
|
/* eslint-disable n8n-nodes-base/node-filename-against-convention */
|
2023-01-27 03:22:44 -08:00
|
|
|
import type {
|
2023-03-09 09:13:15 -08:00
|
|
|
IExecuteFunctions,
|
2020-04-01 00:08:18 -07:00
|
|
|
IDataObject,
|
2019-10-30 04:05:52 -07:00
|
|
|
INodeExecutionData,
|
|
|
|
INodeType,
|
|
|
|
INodeTypeDescription,
|
2023-02-27 19:39:43 -08:00
|
|
|
JsonObject,
|
2023-06-29 06:27:02 -07:00
|
|
|
IRequestOptionsSimplified,
|
2019-10-30 04:05:52 -07:00
|
|
|
} from 'n8n-workflow';
|
2023-06-29 06:27:02 -07:00
|
|
|
import { NodeApiError, NodeOperationError, jsonParse } from 'n8n-workflow';
|
2019-10-30 04:05:52 -07:00
|
|
|
|
2023-01-27 03:22:44 -08:00
|
|
|
import type { OptionsWithUri } from 'request';
|
|
|
|
import type { RequestPromiseOptions } from 'request-promise-native';
|
2019-10-30 04:05:52 -07:00
|
|
|
|
|
|
|
export class GraphQL implements INodeType {
|
|
|
|
description: INodeTypeDescription = {
|
|
|
|
displayName: 'GraphQL',
|
|
|
|
name: 'graphql',
|
2022-06-20 07:54:01 -07:00
|
|
|
// eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg
|
2019-10-31 03:45:50 -07:00
|
|
|
icon: 'file:graphql.png',
|
2019-10-30 04:05:52 -07:00
|
|
|
group: ['input'],
|
|
|
|
version: 1,
|
|
|
|
description: 'Makes a GraphQL request and returns the received data',
|
|
|
|
defaults: {
|
|
|
|
name: 'GraphQL',
|
|
|
|
},
|
|
|
|
inputs: ['main'],
|
|
|
|
outputs: ['main'],
|
2021-05-19 18:04:43 -07:00
|
|
|
credentials: [
|
2022-01-15 11:05:15 -08:00
|
|
|
{
|
|
|
|
name: 'httpBasicAuth',
|
|
|
|
required: true,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
authentication: ['basicAuth'],
|
2022-01-15 11:05:15 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-06-29 06:27:02 -07:00
|
|
|
{
|
|
|
|
name: 'httpCustomAuth',
|
|
|
|
required: true,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
authentication: ['customAuth'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-15 11:05:15 -08:00
|
|
|
{
|
|
|
|
name: 'httpDigestAuth',
|
|
|
|
required: true,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
authentication: ['digestAuth'],
|
2022-01-15 11:05:15 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-05-19 18:04:43 -07:00
|
|
|
{
|
|
|
|
name: 'httpHeaderAuth',
|
|
|
|
required: true,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
authentication: ['headerAuth'],
|
2021-05-19 18:04:43 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-15 11:05:15 -08:00
|
|
|
{
|
|
|
|
name: 'httpQueryAuth',
|
|
|
|
required: true,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
authentication: ['queryAuth'],
|
2022-01-15 11:05:15 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'oAuth1Api',
|
|
|
|
required: true,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
authentication: ['oAuth1'],
|
2022-01-15 11:05:15 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'oAuth2Api',
|
|
|
|
required: true,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
authentication: ['oAuth2'],
|
2022-01-15 11:05:15 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-05-19 18:04:43 -07:00
|
|
|
],
|
2019-10-30 04:05:52 -07:00
|
|
|
properties: [
|
2021-05-19 18:04:43 -07:00
|
|
|
{
|
|
|
|
displayName: 'Authentication',
|
|
|
|
name: 'authentication',
|
|
|
|
type: 'options',
|
|
|
|
options: [
|
2022-01-15 11:05:15 -08:00
|
|
|
{
|
|
|
|
name: 'Basic Auth',
|
|
|
|
value: 'basicAuth',
|
|
|
|
},
|
2023-06-29 06:27:02 -07:00
|
|
|
{
|
|
|
|
name: 'Custom Auth',
|
|
|
|
value: 'customAuth',
|
|
|
|
},
|
2022-01-15 11:05:15 -08:00
|
|
|
{
|
|
|
|
name: 'Digest Auth',
|
|
|
|
value: 'digestAuth',
|
|
|
|
},
|
2021-05-19 18:04:43 -07:00
|
|
|
{
|
|
|
|
name: 'Header Auth',
|
|
|
|
value: 'headerAuth',
|
|
|
|
},
|
2022-01-15 11:05:15 -08:00
|
|
|
{
|
2022-06-03 10:23:49 -07:00
|
|
|
name: 'None',
|
|
|
|
value: 'none',
|
2022-01-15 11:05:15 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'OAuth1',
|
|
|
|
value: 'oAuth1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'OAuth2',
|
|
|
|
value: 'oAuth2',
|
|
|
|
},
|
2021-05-19 18:04:43 -07:00
|
|
|
{
|
2022-06-03 10:23:49 -07:00
|
|
|
name: 'Query Auth',
|
|
|
|
value: 'queryAuth',
|
2021-05-19 18:04:43 -07:00
|
|
|
},
|
|
|
|
],
|
|
|
|
default: 'none',
|
2022-05-06 14:01:25 -07:00
|
|
|
description: 'The way to authenticate',
|
2021-05-19 18:04:43 -07:00
|
|
|
},
|
2019-10-30 04:05:52 -07:00
|
|
|
{
|
|
|
|
displayName: 'HTTP Request Method',
|
|
|
|
name: 'requestMethod',
|
|
|
|
type: 'options',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'GET',
|
2019-10-31 03:45:50 -07:00
|
|
|
value: 'GET',
|
2019-10-30 04:05:52 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'POST',
|
2019-10-31 03:45:50 -07:00
|
|
|
value: 'POST',
|
2019-10-30 04:05:52 -07:00
|
|
|
},
|
|
|
|
],
|
|
|
|
default: 'POST',
|
2022-05-06 14:01:25 -07:00
|
|
|
description: 'The underlying HTTP request method to use',
|
2019-10-30 04:05:52 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Endpoint',
|
|
|
|
name: 'endpoint',
|
|
|
|
type: 'string',
|
|
|
|
default: '',
|
|
|
|
placeholder: 'http://example.com/graphql',
|
2022-05-06 14:01:25 -07:00
|
|
|
description: 'The GraphQL endpoint',
|
2019-10-30 04:05:52 -07:00
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Ignore SSL Issues',
|
|
|
|
name: 'allowUnauthorizedCerts',
|
|
|
|
type: 'boolean',
|
|
|
|
default: false,
|
2022-05-06 14:01:25 -07:00
|
|
|
// eslint-disable-next-line n8n-nodes-base/node-param-description-wrong-for-ignore-ssl-issues
|
2022-08-17 08:50:24 -07:00
|
|
|
description:
|
|
|
|
'Whether to download the response even if SSL certificate validation is not possible',
|
2019-10-30 04:05:52 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Request Format',
|
|
|
|
name: 'requestFormat',
|
|
|
|
type: 'options',
|
|
|
|
required: true,
|
|
|
|
options: [
|
|
|
|
{
|
2022-06-03 10:23:49 -07:00
|
|
|
name: 'GraphQL (Raw)',
|
2019-10-31 03:45:50 -07:00
|
|
|
value: 'graphql',
|
2019-10-30 04:05:52 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'JSON',
|
2019-10-31 03:45:50 -07:00
|
|
|
value: 'json',
|
2019-10-30 04:05:52 -07:00
|
|
|
},
|
|
|
|
],
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
requestMethod: ['POST'],
|
2019-10-30 04:05:52 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
default: 'graphql',
|
|
|
|
description: 'The format for the query payload',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Query',
|
|
|
|
name: 'query',
|
|
|
|
type: 'json',
|
|
|
|
default: '',
|
|
|
|
description: 'GraphQL query',
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Variables',
|
|
|
|
name: 'variables',
|
|
|
|
type: 'json',
|
2019-10-30 06:02:14 -07:00
|
|
|
default: '',
|
2019-10-30 04:05:52 -07:00
|
|
|
description: 'Query variables',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
requestFormat: ['json'],
|
|
|
|
requestMethod: ['POST'],
|
2019-10-30 04:05:52 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Operation Name',
|
|
|
|
name: 'operationName',
|
|
|
|
type: 'string',
|
|
|
|
default: '',
|
|
|
|
description: 'Name of operation to execute',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
requestFormat: ['json'],
|
|
|
|
requestMethod: ['POST'],
|
2019-10-30 04:05:52 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Response Format',
|
|
|
|
name: 'responseFormat',
|
|
|
|
type: 'options',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'JSON',
|
2019-10-31 03:45:50 -07:00
|
|
|
value: 'json',
|
2019-10-30 04:05:52 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'String',
|
2019-10-31 03:45:50 -07:00
|
|
|
value: 'string',
|
2019-10-30 04:05:52 -07:00
|
|
|
},
|
|
|
|
],
|
|
|
|
default: 'json',
|
2022-05-06 14:01:25 -07:00
|
|
|
description: 'The format in which the data gets returned from the URL',
|
2019-10-30 04:05:52 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Response Data Property Name',
|
|
|
|
name: 'dataPropertyName',
|
|
|
|
type: 'string',
|
2019-10-31 09:26:05 -07:00
|
|
|
default: 'data',
|
2019-10-30 04:05:52 -07:00
|
|
|
required: true,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
responseFormat: ['string'],
|
2019-10-30 04:05:52 -07:00
|
|
|
},
|
|
|
|
},
|
2022-05-06 14:01:25 -07:00
|
|
|
description: 'Name of the property to which to write the response data',
|
2019-10-30 04:05:52 -07:00
|
|
|
},
|
2020-04-01 00:08:18 -07:00
|
|
|
|
|
|
|
// Header Parameters
|
|
|
|
{
|
|
|
|
displayName: 'Headers',
|
|
|
|
name: 'headerParametersUi',
|
|
|
|
placeholder: 'Add Header',
|
|
|
|
type: 'fixedCollection',
|
|
|
|
typeOptions: {
|
|
|
|
multipleValues: true,
|
|
|
|
},
|
2022-05-06 14:01:25 -07:00
|
|
|
description: 'The headers to send',
|
2020-04-01 00:08:18 -07:00
|
|
|
default: {},
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'parameter',
|
|
|
|
displayName: 'Header',
|
|
|
|
values: [
|
|
|
|
{
|
|
|
|
displayName: 'Name',
|
|
|
|
name: 'name',
|
|
|
|
type: 'string',
|
|
|
|
default: '',
|
2022-05-06 14:01:25 -07:00
|
|
|
description: 'Name of the header',
|
2020-04-01 00:08:18 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Value',
|
|
|
|
name: 'value',
|
|
|
|
type: 'string',
|
|
|
|
default: '',
|
2022-05-06 14:01:25 -07:00
|
|
|
description: 'Value to set for the header',
|
2020-04-01 00:08:18 -07:00
|
|
|
},
|
2020-10-22 06:46:03 -07:00
|
|
|
],
|
2020-04-01 00:08:18 -07:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2020-10-22 06:46:03 -07:00
|
|
|
],
|
2019-10-30 04:05:52 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
|
|
const items = this.getInputData();
|
2022-04-14 23:00:47 -07:00
|
|
|
let httpBasicAuth;
|
|
|
|
let httpDigestAuth;
|
2023-06-29 06:27:02 -07:00
|
|
|
let httpCustomAuth;
|
2022-04-14 23:00:47 -07:00
|
|
|
let httpHeaderAuth;
|
|
|
|
let httpQueryAuth;
|
|
|
|
let oAuth1Api;
|
|
|
|
let oAuth2Api;
|
|
|
|
|
|
|
|
try {
|
|
|
|
httpBasicAuth = await this.getCredentials('httpBasicAuth');
|
2022-08-17 08:50:24 -07:00
|
|
|
} catch (error) {
|
2022-04-14 23:00:47 -07:00
|
|
|
// Do nothing
|
|
|
|
}
|
2023-06-29 06:27:02 -07:00
|
|
|
try {
|
|
|
|
httpCustomAuth = await this.getCredentials('httpCustomAuth');
|
|
|
|
} catch (error) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
2022-04-14 23:00:47 -07:00
|
|
|
try {
|
|
|
|
httpDigestAuth = await this.getCredentials('httpDigestAuth');
|
2022-08-17 08:50:24 -07:00
|
|
|
} catch (error) {
|
2022-04-14 23:00:47 -07:00
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
httpHeaderAuth = await this.getCredentials('httpHeaderAuth');
|
2022-08-17 08:50:24 -07:00
|
|
|
} catch (error) {
|
2022-04-14 23:00:47 -07:00
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
httpQueryAuth = await this.getCredentials('httpQueryAuth');
|
2022-08-17 08:50:24 -07:00
|
|
|
} catch (error) {
|
2022-04-14 23:00:47 -07:00
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
oAuth1Api = await this.getCredentials('oAuth1Api');
|
2022-08-17 08:50:24 -07:00
|
|
|
} catch (error) {
|
2022-04-14 23:00:47 -07:00
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
oAuth2Api = await this.getCredentials('oAuth2Api');
|
2022-08-17 08:50:24 -07:00
|
|
|
} catch (error) {
|
2022-04-14 23:00:47 -07:00
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
|
2019-10-30 04:05:52 -07:00
|
|
|
let requestOptions: OptionsWithUri & RequestPromiseOptions;
|
|
|
|
|
|
|
|
const returnItems: INodeExecutionData[] = [];
|
|
|
|
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
|
|
|
const requestMethod = this.getNodeParameter('requestMethod', itemIndex, 'POST') as string;
|
|
|
|
const endpoint = this.getNodeParameter('endpoint', itemIndex, '') as string;
|
2022-08-17 08:50:24 -07:00
|
|
|
const requestFormat = this.getNodeParameter(
|
|
|
|
'requestFormat',
|
|
|
|
itemIndex,
|
|
|
|
'graphql',
|
|
|
|
) as string;
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseFormat = this.getNodeParameter('responseFormat', 0) as string;
|
2022-08-17 08:50:24 -07:00
|
|
|
const { parameter }: { parameter?: Array<{ name: string; value: string }> } =
|
|
|
|
this.getNodeParameter('headerParametersUi', itemIndex, {}) as IDataObject;
|
2023-01-19 04:37:19 -08:00
|
|
|
const headerParameters = (parameter || []).reduce(
|
2022-08-17 08:50:24 -07:00
|
|
|
(result, item) => ({
|
|
|
|
...result,
|
|
|
|
[item.name]: item.value,
|
|
|
|
}),
|
|
|
|
{},
|
|
|
|
);
|
2020-04-01 00:08:18 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestOptions = {
|
|
|
|
headers: {
|
|
|
|
'content-type': `application/${requestFormat}`,
|
|
|
|
...headerParameters,
|
|
|
|
},
|
|
|
|
method: requestMethod,
|
|
|
|
uri: endpoint,
|
|
|
|
simple: false,
|
2022-12-02 12:54:28 -08:00
|
|
|
rejectUnauthorized: !this.getNodeParameter('allowUnauthorizedCerts', itemIndex, false),
|
2021-07-19 23:58:54 -07:00
|
|
|
};
|
2019-10-30 04:05:52 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
// Add credentials if any are set
|
2022-01-15 11:05:15 -08:00
|
|
|
if (httpBasicAuth !== undefined) {
|
|
|
|
requestOptions.auth = {
|
|
|
|
user: httpBasicAuth.user as string,
|
|
|
|
pass: httpBasicAuth.password as string,
|
|
|
|
};
|
|
|
|
}
|
2023-06-29 06:27:02 -07:00
|
|
|
if (httpCustomAuth !== undefined) {
|
|
|
|
const customAuth = jsonParse<IRequestOptionsSimplified>(
|
|
|
|
(httpCustomAuth.json as string) || '{}',
|
|
|
|
{ errorMessage: 'Invalid Custom Auth JSON' },
|
|
|
|
);
|
|
|
|
if (customAuth.headers) {
|
|
|
|
requestOptions.headers = { ...requestOptions.headers, ...customAuth.headers };
|
|
|
|
}
|
|
|
|
if (customAuth.body) {
|
|
|
|
requestOptions.body = { ...requestOptions.body, ...customAuth.body };
|
|
|
|
}
|
|
|
|
if (customAuth.qs) {
|
|
|
|
requestOptions.qs = { ...requestOptions.qs, ...customAuth.qs };
|
|
|
|
}
|
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
if (httpHeaderAuth !== undefined) {
|
|
|
|
requestOptions.headers![httpHeaderAuth.name as string] = httpHeaderAuth.value;
|
|
|
|
}
|
2022-01-15 11:05:15 -08:00
|
|
|
if (httpQueryAuth !== undefined) {
|
|
|
|
if (!requestOptions.qs) {
|
|
|
|
requestOptions.qs = {};
|
|
|
|
}
|
2022-12-02 12:54:28 -08:00
|
|
|
requestOptions.qs[httpQueryAuth.name as string] = httpQueryAuth.value;
|
2022-01-15 11:05:15 -08:00
|
|
|
}
|
|
|
|
if (httpDigestAuth !== undefined) {
|
|
|
|
requestOptions.auth = {
|
|
|
|
user: httpDigestAuth.user as string,
|
|
|
|
pass: httpDigestAuth.password as string,
|
|
|
|
sendImmediately: false,
|
|
|
|
};
|
|
|
|
}
|
2021-05-19 18:04:43 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const gqlQuery = this.getNodeParameter('query', itemIndex, '') as string;
|
|
|
|
if (requestMethod === 'GET') {
|
2022-01-15 11:05:15 -08:00
|
|
|
if (!requestOptions.qs) {
|
|
|
|
requestOptions.qs = {};
|
|
|
|
}
|
|
|
|
requestOptions.qs.query = gqlQuery;
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
|
|
|
if (requestFormat === 'json') {
|
|
|
|
requestOptions.body = {
|
2023-06-29 06:27:02 -07:00
|
|
|
...requestOptions.body,
|
2021-07-19 23:58:54 -07:00
|
|
|
query: gqlQuery,
|
|
|
|
variables: this.getNodeParameter('variables', itemIndex, {}) as object,
|
|
|
|
operationName: this.getNodeParameter('operationName', itemIndex) as string,
|
|
|
|
};
|
|
|
|
if (typeof requestOptions.body.variables === 'string') {
|
|
|
|
try {
|
2023-02-27 19:39:43 -08:00
|
|
|
requestOptions.body.variables = JSON.parse(
|
|
|
|
(requestOptions.body.variables as string) || '{}',
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
} catch (error) {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
this.getNode(),
|
|
|
|
'Using variables failed:\n' +
|
2023-01-13 09:11:56 -08:00
|
|
|
(requestOptions.body.variables as string) +
|
2022-08-17 08:50:24 -07:00
|
|
|
'\n\nWith error message:\n' +
|
2023-01-13 09:11:56 -08:00
|
|
|
(error as string),
|
2022-08-17 08:50:24 -07:00
|
|
|
{ itemIndex },
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2019-10-30 06:02:14 -07:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
if (requestOptions.body.operationName === '') {
|
|
|
|
requestOptions.body.operationName = null;
|
|
|
|
}
|
|
|
|
requestOptions.json = true;
|
|
|
|
} else {
|
|
|
|
requestOptions.body = gqlQuery;
|
2019-10-30 04:05:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-15 11:05:15 -08:00
|
|
|
let response;
|
|
|
|
// Now that the options are all set make the actual http request
|
|
|
|
if (oAuth1Api !== undefined) {
|
|
|
|
response = await this.helpers.requestOAuth1.call(this, 'oAuth1Api', requestOptions);
|
|
|
|
} else if (oAuth2Api !== undefined) {
|
2022-08-17 08:50:24 -07:00
|
|
|
response = await this.helpers.requestOAuth2.call(this, 'oAuth2Api', requestOptions, {
|
|
|
|
tokenType: 'Bearer',
|
|
|
|
});
|
2022-01-15 11:05:15 -08:00
|
|
|
} else {
|
|
|
|
response = await this.helpers.request(requestOptions);
|
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
if (responseFormat === 'string') {
|
2023-01-06 06:09:32 -08:00
|
|
|
const dataPropertyName = this.getNodeParameter('dataPropertyName', 0);
|
2022-09-03 04:20:25 -07:00
|
|
|
returnItems.push({
|
2021-07-19 23:58:54 -07:00
|
|
|
json: {
|
|
|
|
[dataPropertyName]: response,
|
|
|
|
},
|
|
|
|
});
|
2019-12-19 14:15:19 -08:00
|
|
|
} else {
|
2021-07-19 23:58:54 -07:00
|
|
|
if (typeof response === 'string') {
|
|
|
|
try {
|
2022-04-01 05:38:26 -07:00
|
|
|
response = JSON.parse(response);
|
2021-07-19 23:58:54 -07:00
|
|
|
} catch (error) {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
this.getNode(),
|
|
|
|
'Response body is not valid JSON. Change "Response Format" to "String"',
|
|
|
|
{ itemIndex },
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
}
|
2022-04-01 05:38:26 -07:00
|
|
|
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
2023-02-27 19:39:43 -08:00
|
|
|
this.helpers.returnJsonArray(response as IDataObject),
|
2022-08-30 08:55:33 -07:00
|
|
|
{ itemData: { item: itemIndex } },
|
|
|
|
);
|
|
|
|
returnItems.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2023-08-18 02:22:12 -07:00
|
|
|
|
|
|
|
// parse error string messages
|
|
|
|
if (typeof response === 'string' && response.startsWith('{"errors":')) {
|
|
|
|
try {
|
|
|
|
const errorResponse = JSON.parse(response) as IDataObject;
|
|
|
|
if (Array.isArray(errorResponse.errors)) {
|
|
|
|
response = errorResponse;
|
|
|
|
}
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
// throw from response object.errors[]
|
|
|
|
if (typeof response === 'object' && response.errors) {
|
|
|
|
const message =
|
|
|
|
response.errors?.map((error: IDataObject) => error.message).join(', ') ||
|
|
|
|
'Unexpected error';
|
|
|
|
throw new NodeApiError(this.getNode(), response.errors as JsonObject, { message });
|
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
2022-08-30 08:55:33 -07:00
|
|
|
const errorData = this.helpers.returnJsonArray({
|
|
|
|
$error: error,
|
|
|
|
json: this.getInputData(itemIndex),
|
|
|
|
itemIndex,
|
|
|
|
});
|
|
|
|
const exectionErrorWithMetaData = this.helpers.constructExecutionMetaData(errorData, {
|
|
|
|
itemData: { item: itemIndex },
|
|
|
|
});
|
|
|
|
returnItems.push(...exectionErrorWithMetaData);
|
2021-07-19 23:58:54 -07:00
|
|
|
continue;
|
2019-10-30 04:05:52 -07:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
throw error;
|
2019-10-30 04:05:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-05 03:59:02 -07:00
|
|
|
return [returnItems];
|
2019-10-30 04:05:52 -07:00
|
|
|
}
|
|
|
|
}
|