mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-25 11:31:38 -08:00
fix(GraphQL Node): Change default request format to json instead of graphql
This commit is contained in:
parent
72e6343964
commit
70c188aa1b
|
@ -175,12 +175,16 @@ export class GraphQL implements INodeType {
|
|||
required: true,
|
||||
options: [
|
||||
{
|
||||
name: 'GraphQL (Raw)',
|
||||
value: 'graphql',
|
||||
name: 'JSON (Recommended)',
|
||||
value: 'json',
|
||||
description:
|
||||
'JSON object with query, variables, and operationName properties. The standard and most widely supported format for GraphQL requests.',
|
||||
},
|
||||
{
|
||||
name: 'JSON',
|
||||
value: 'json',
|
||||
name: 'GraphQL (Raw)',
|
||||
value: 'graphql',
|
||||
description:
|
||||
'Raw GraphQL query string. Not all servers support this format. Use JSON for better compatibility.',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
|
@ -188,23 +192,26 @@ export class GraphQL implements INodeType {
|
|||
requestMethod: ['POST'],
|
||||
},
|
||||
},
|
||||
default: 'graphql',
|
||||
description: 'The format for the query payload',
|
||||
default: 'json',
|
||||
description: 'The request format for the query payload',
|
||||
},
|
||||
{
|
||||
displayName: 'Query',
|
||||
name: 'query',
|
||||
type: 'json',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'GraphQL query',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
rows: 6,
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Variables',
|
||||
name: 'variables',
|
||||
type: 'json',
|
||||
default: '',
|
||||
description: 'Query variables',
|
||||
description: 'Query variables as JSON object',
|
||||
displayOptions: {
|
||||
show: {
|
||||
requestFormat: ['json'],
|
||||
|
@ -350,11 +357,7 @@ export class GraphQL implements INodeType {
|
|||
'POST',
|
||||
) as IHttpRequestMethods;
|
||||
const endpoint = this.getNodeParameter('endpoint', itemIndex, '') as string;
|
||||
const requestFormat = this.getNodeParameter(
|
||||
'requestFormat',
|
||||
itemIndex,
|
||||
'graphql',
|
||||
) as string;
|
||||
const requestFormat = this.getNodeParameter('requestFormat', itemIndex, 'json') as string;
|
||||
const responseFormat = this.getNodeParameter('responseFormat', 0) as string;
|
||||
const { parameter }: { parameter?: Array<{ name: string; value: string }> } =
|
||||
this.getNodeParameter('headerParametersUi', itemIndex, {}) as IDataObject;
|
||||
|
@ -484,7 +487,20 @@ export class GraphQL implements INodeType {
|
|||
} else {
|
||||
if (typeof response === 'string') {
|
||||
try {
|
||||
response = JSON.parse(response);
|
||||
if (typeof response === 'string') {
|
||||
response = JSON.parse(response) as IDataObject;
|
||||
}
|
||||
|
||||
// Check for errors in the response
|
||||
if (response.errors && Array.isArray(response.errors)) {
|
||||
// If the request format is 'graphql', throw an error suggesting to try JSON
|
||||
if (requestFormat === 'graphql') {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'Error in GraphQL request. Please try using the Request format "JSON" instead.',
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
|
|
Loading…
Reference in a new issue