mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(GraphQL Node): Fix request format JSON error (#8646)
This commit is contained in:
parent
c4e259bcfc
commit
bd4b50cf08
|
@ -424,9 +424,8 @@ export class GraphQL implements INodeType {
|
||||||
requestOptions.qs.query = gqlQuery;
|
requestOptions.qs.query = gqlQuery;
|
||||||
} else {
|
} else {
|
||||||
if (requestFormat === 'json') {
|
if (requestFormat === 'json') {
|
||||||
const jsonBody = requestOptions.body as IDataObject;
|
const jsonBody = {
|
||||||
requestOptions.body = {
|
...requestOptions.body,
|
||||||
...jsonBody,
|
|
||||||
query: gqlQuery,
|
query: gqlQuery,
|
||||||
variables: this.getNodeParameter('variables', itemIndex, {}) as object,
|
variables: this.getNodeParameter('variables', itemIndex, {}) as object,
|
||||||
operationName: this.getNodeParameter('operationName', itemIndex) as string,
|
operationName: this.getNodeParameter('operationName', itemIndex) as string,
|
||||||
|
@ -449,6 +448,7 @@ export class GraphQL implements INodeType {
|
||||||
jsonBody.operationName = null;
|
jsonBody.operationName = null;
|
||||||
}
|
}
|
||||||
requestOptions.json = true;
|
requestOptions.json = true;
|
||||||
|
requestOptions.body = jsonBody;
|
||||||
} else {
|
} else {
|
||||||
requestOptions.body = gqlQuery;
|
requestOptions.body = gqlQuery;
|
||||||
}
|
}
|
||||||
|
|
54
packages/nodes-base/nodes/GraphQL/test/GraphQL.node.test.ts
Normal file
54
packages/nodes-base/nodes/GraphQL/test/GraphQL.node.test.ts
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
import type { WorkflowTestData } from '@test/nodes/types';
|
||||||
|
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
|
||||||
|
import * as Helpers from '@test/nodes/Helpers';
|
||||||
|
|
||||||
|
describe('GraphQL Node', () => {
|
||||||
|
const mockResponse = {
|
||||||
|
data: {
|
||||||
|
nodes: {},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const tests: WorkflowTestData[] = [
|
||||||
|
{
|
||||||
|
description: 'should run Request Format JSON',
|
||||||
|
input: {
|
||||||
|
workflowData: Helpers.readJsonFileSync('nodes/GraphQL/test/workflow.json'),
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
nodeExecutionOrder: ['Start'],
|
||||||
|
nodeData: {
|
||||||
|
'Fetch Request Format JSON': [
|
||||||
|
[
|
||||||
|
{
|
||||||
|
json: mockResponse,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
nock: {
|
||||||
|
baseUrl: 'https://api.n8n.io',
|
||||||
|
mocks: [
|
||||||
|
{
|
||||||
|
method: 'post',
|
||||||
|
path: '/graphql',
|
||||||
|
statusCode: 200,
|
||||||
|
responseBody: mockResponse,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const nodeTypes = Helpers.setup(tests);
|
||||||
|
|
||||||
|
test.each(tests)('$description', async (testData) => {
|
||||||
|
const { result } = await executeWorkflow(testData, nodeTypes);
|
||||||
|
const resultNodeData = Helpers.getResultNodeData(result, testData);
|
||||||
|
resultNodeData.forEach(({ nodeName, resultData }) =>
|
||||||
|
expect(resultData).toEqual(testData.output.nodeData[nodeName]),
|
||||||
|
);
|
||||||
|
expect(result.finished).toEqual(true);
|
||||||
|
});
|
||||||
|
});
|
42
packages/nodes-base/nodes/GraphQL/test/workflow.json
Normal file
42
packages/nodes-base/nodes/GraphQL/test/workflow.json
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
{
|
||||||
|
"meta": {
|
||||||
|
"templateCredsSetupCompleted": true,
|
||||||
|
"instanceId": "104a4d08d8897b8bdeb38aaca515021075e0bd8544c983c2bb8c86e6a8e6081c"
|
||||||
|
},
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"parameters": {},
|
||||||
|
"id": "fb826323-2e48-4f11-bb0e-e12de32e22ee",
|
||||||
|
"name": "When clicking \"Test workflow\"",
|
||||||
|
"type": "n8n-nodes-base.manualTrigger",
|
||||||
|
"typeVersion": 1,
|
||||||
|
"position": [180, 160]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parameters": {
|
||||||
|
"endpoint": "https://api.n8n.io/graphql",
|
||||||
|
"requestFormat": "json",
|
||||||
|
"query": "query {\n nodes(pagination: { limit: 1 }) {\n data {\n id\n attributes {\n name\n displayName\n description\n group\n codex\n createdAt\n }\n }\n }\n}"
|
||||||
|
},
|
||||||
|
"name": "Fetch Request Format JSON",
|
||||||
|
"type": "n8n-nodes-base.graphql",
|
||||||
|
"typeVersion": 1,
|
||||||
|
"position": [420, 160],
|
||||||
|
"id": "7f8ceaf4-b82f-48d5-be0b-9fe3bfb35ee4"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"connections": {
|
||||||
|
"When clicking \"Test workflow\"": {
|
||||||
|
"main": [
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"node": "Fetch Request Format JSON",
|
||||||
|
"type": "main",
|
||||||
|
"index": 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pinData": {}
|
||||||
|
}
|
|
@ -2125,6 +2125,15 @@ export interface WorkflowTestData {
|
||||||
[key: string]: any[][];
|
[key: string]: any[][];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
nock: {
|
||||||
|
baseUrl: string;
|
||||||
|
mocks: Array<{
|
||||||
|
method: string;
|
||||||
|
path: string;
|
||||||
|
statusCode: number;
|
||||||
|
responseBody: any;
|
||||||
|
}>;
|
||||||
|
};
|
||||||
trigger?: {
|
trigger?: {
|
||||||
mode: WorkflowExecuteMode;
|
mode: WorkflowExecuteMode;
|
||||||
input: INodeExecutionData;
|
input: INodeExecutionData;
|
||||||
|
|
Loading…
Reference in a new issue