Automatically parse response in GraphQL node to JSON

This commit is contained in:
Jan Oberhauser 2019-12-19 16:15:19 -06:00
parent 8acc3c5931
commit 108ffb0d86

View file

@ -221,12 +221,16 @@ export class GraphQL implements INodeType {
}); });
} else { } else {
if (typeof response === 'string') { if (typeof response === 'string') {
try {
returnItems.push({ json: JSON.parse(response) });
} catch (e) {
throw new Error('Response body is not valid JSON. Change "Response Format" to "String"'); throw new Error('Response body is not valid JSON. Change "Response Format" to "String"');
} }
} else {
returnItems.push({ json: response }); returnItems.push({ json: response });
} }
} }
}
return this.prepareOutputData(returnItems); return this.prepareOutputData(returnItems);
} }