From 73420a368aacc0184dd92602f616892a3c517fc9 Mon Sep 17 00:00:00 2001 From: Taras Dubyk Date: Wed, 2 Apr 2025 13:50:31 +0300 Subject: [PATCH 1/3] escape quotes only for single-line descriptions --- forward_engineering/helpers/descriptionsHelper.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/forward_engineering/helpers/descriptionsHelper.js b/forward_engineering/helpers/descriptionsHelper.js index 2a9c65e..2d465b8 100644 --- a/forward_engineering/helpers/descriptionsHelper.js +++ b/forward_engineering/helpers/descriptionsHelper.js @@ -12,13 +12,15 @@ function getStatementDescription({ description }) { } const trimmedDescription = description.trim(); - const escapedDescription = trimmedDescription.replace(/"/g, '\\"'); - const isMultiLine = escapedDescription.includes('\n'); + const isMultiLine = trimmedDescription.includes('\n'); - // Format the description based on whether it is multi-line or single-line - const formattedDescription = isMultiLine ? `"""\n${escapedDescription}\n"""` : `"${escapedDescription}"`; + if (!isMultiLine) { + // Escape double quotes for single-line descriptions + const escapedDescription = trimmedDescription.replace(/"/g, '\\"'); + return `"${escapedDescription}"`; + } - return formattedDescription; + return `"""\n${trimmedDescription}\n"""`; } module.exports = { From b61a96c62919cef5c554cd5df63543a5a03ddda3 Mon Sep 17 00:00:00 2001 From: Taras Dubyk Date: Wed, 2 Apr 2025 13:51:06 +0300 Subject: [PATCH 2/3] remove space between field/directive name and arguments --- forward_engineering/mappers/arguments.js | 7 ++++--- forward_engineering/mappers/directives.js | 2 +- forward_engineering/mappers/fields.js | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/forward_engineering/mappers/arguments.js b/forward_engineering/mappers/arguments.js index 94632ba..fdbcb9f 100644 --- a/forward_engineering/mappers/arguments.js +++ b/forward_engineering/mappers/arguments.js @@ -70,9 +70,10 @@ const mapArgument = ({ graphqlArgument, idToNameMap = {} }) => { * @param {Object} args - arguments object. * @param {Argument[]} args.graphqlArguments - The arguments to map. * @param {IdToNameMap} [args.idToNameMap] - The ID to name map of all available types in model. - * @returns {Object} returns an object containing the arguments as a formatted string and a warning comment if any. - * @returns {string} returns.argumentsStatement - The formatted arguments string. - * @returns {string} returns.argumentsWarningComment - The warning comment if any argument is missing a type. + * @returns {{ + * argumentsStatement: string, + * argumentsWarningComment: string + * }} An object containing the arguments as a formatted string and a warning comment if any argument is missing the type. */ const getArguments = ({ graphqlArguments, idToNameMap = {} }) => { if (!Array.isArray(graphqlArguments) || graphqlArguments.length === 0) { diff --git a/forward_engineering/mappers/directives.js b/forward_engineering/mappers/directives.js index a3119c1..f2bbf71 100644 --- a/forward_engineering/mappers/directives.js +++ b/forward_engineering/mappers/directives.js @@ -53,7 +53,7 @@ function mapDirective({ name, directive, definitionsIdToNameMap }) { }); return { - statement: `directive ${directiveName}${argumentsStatement} on ${directiveLocations}`, + statement: `directive ${directiveName}${argumentsStatement.trimStart()} on ${directiveLocations}`, description: directive.description || '', isActivated: directive.isActivated, comment: argumentsWarningComment, diff --git a/forward_engineering/mappers/fields.js b/forward_engineering/mappers/fields.js index 41fd387..d7120b1 100644 --- a/forward_engineering/mappers/fields.js +++ b/forward_engineering/mappers/fields.js @@ -53,7 +53,7 @@ function mapField({ name, fieldData, required, definitionsIdToNameMap, addArgume const { argumentsStatement, argumentsWarningComment } = addArguments ? getArguments({ graphqlArguments: fieldData.arguments, idToNameMap: definitionsIdToNameMap }) : { argumentsStatement: '', argumentsWarningComment: '' }; - const fieldNameStatement = joinInlineStatements({ statements: [name, argumentsStatement] }); + const fieldNameStatement = joinInlineStatements({ statements: [name, argumentsStatement], separator: '' }); const fieldTypeStatement = `${fieldNameStatement}: ${getFieldType({ field: fieldData, required })}`; const fieldDefaultValue = addDefaultValue ? getFieldDefaultValueStatement({ field: fieldData }) : ''; const directivesStatement = getDirectivesUsageStatement({ From 9e5e483ef5f82995b815bb9642cc98a0f83ef7f1 Mon Sep 17 00:00:00 2001 From: Taras Dubyk Date: Wed, 2 Apr 2025 13:54:31 +0300 Subject: [PATCH 3/3] update expected schema --- test/forward_engineering/expectedSchema.graphql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/forward_engineering/expectedSchema.graphql b/test/forward_engineering/expectedSchema.graphql index e2aef6b..e427d87 100644 --- a/test/forward_engineering/expectedSchema.graphql +++ b/test/forward_engineering/expectedSchema.graphql @@ -8,7 +8,7 @@ schema { } "An active custom directive example" -directive @activeDirective ( +directive @activeDirective( "An example argument" arg1: String! = "TEST" ) on ARGUMENT_DEFINITION | ENUM | ENUM_VALUE | FIELD | FIELD_DEFINITION | INPUT_FIELD_DEFINITION | INPUT_OBJECT | INTERFACE | MUTATION | OBJECT | QUERY | SCALAR | SCHEMA | SUBSCRIPTION | UNION @@ -16,14 +16,14 @@ directive @activeDirective ( # directive @deactivetedDirective on UNKNOWN_LOCATION # Please specify the directive locations type TestQuery { - student ( + student( "Specify ID of user to fetch" id: ID! = "1" @activeDirective(arg1: "TEST111") ): Student } type TestMutation { - student (id: ID! = "1"): Student @activeDirective(arg1: "TEST222") + student(id: ID! = "1"): Student @activeDirective(arg1: "TEST222") } type TestSubscription {