fix(GraphQL Node): Change default request format to json instead of graphql (#11346)

Co-authored-by: Shireen Missi <shireen@n8n.io>
Co-authored-by: Dana Lee <dana@n8n.io>
This commit is contained in:
aya 2025-01-17 02:06:45 +09:00 committed by GitHub
parent 14f4bc7690
commit c7c122f917
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -19,7 +19,7 @@ export class GraphQL implements INodeType {
// eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg // eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg
icon: 'file:graphql.png', icon: 'file:graphql.png',
group: ['input'], group: ['input'],
version: 1, version: [1, 1.1],
description: 'Makes a GraphQL request and returns the received data', description: 'Makes a GraphQL request and returns the received data',
defaults: { defaults: {
name: 'GraphQL', name: 'GraphQL',
@ -186,25 +186,57 @@ export class GraphQL implements INodeType {
displayOptions: { displayOptions: {
show: { show: {
requestMethod: ['POST'], requestMethod: ['POST'],
'@version': [1],
}, },
}, },
default: 'graphql', default: 'graphql',
description: 'The format for the query payload', description: 'The format for the query payload',
}, },
{
displayName: 'Request Format',
name: 'requestFormat',
type: 'options',
required: true,
options: [
{
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: 'GraphQL (Raw)',
value: 'graphql',
description:
'Raw GraphQL query string. Not all servers support this format. Use JSON for better compatibility.',
},
],
displayOptions: {
show: {
requestMethod: ['POST'],
'@version': [{ _cnd: { gte: 1.1 } }],
},
},
default: 'json',
description: 'The request format for the query payload',
},
{ {
displayName: 'Query', displayName: 'Query',
name: 'query', name: 'query',
type: 'json', type: 'string',
default: '', default: '',
description: 'GraphQL query', description: 'GraphQL query',
required: true, required: true,
typeOptions: {
rows: 6,
},
}, },
{ {
displayName: 'Variables', displayName: 'Variables',
name: 'variables', name: 'variables',
type: 'json', type: 'json',
default: '', default: '',
description: 'Query variables', description: 'Query variables as JSON object',
displayOptions: { displayOptions: {
show: { show: {
requestFormat: ['json'], requestFormat: ['json'],
@ -350,11 +382,7 @@ export class GraphQL implements INodeType {
'POST', 'POST',
) as IHttpRequestMethods; ) as IHttpRequestMethods;
const endpoint = this.getNodeParameter('endpoint', itemIndex, '') as string; const endpoint = this.getNodeParameter('endpoint', itemIndex, '') as string;
const requestFormat = this.getNodeParameter( const requestFormat = this.getNodeParameter('requestFormat', itemIndex, 'json') as string;
'requestFormat',
itemIndex,
'graphql',
) as string;
const responseFormat = this.getNodeParameter('responseFormat', 0) as string; const responseFormat = this.getNodeParameter('responseFormat', 0) as string;
const { parameter }: { parameter?: Array<{ name: string; value: string }> } = const { parameter }: { parameter?: Array<{ name: string; value: string }> } =
this.getNodeParameter('headerParametersUi', itemIndex, {}) as IDataObject; this.getNodeParameter('headerParametersUi', itemIndex, {}) as IDataObject;
@ -450,7 +478,7 @@ export class GraphQL implements INodeType {
...requestOptions.body, ...requestOptions.body,
query: gqlQuery, query: gqlQuery,
variables: parsedVariables, variables: parsedVariables,
operationName: this.getNodeParameter('operationName', itemIndex) as string, operationName: this.getNodeParameter('operationName', itemIndex, '') as string,
}; };
if (jsonBody.operationName === '') { if (jsonBody.operationName === '') {