aws-mobile-appsync-events-starter-react icon indicating copy to clipboard operation
aws-mobile-appsync-events-starter-react copied to clipboard

events created with newline in the description are lost

Open ceich opened this issue 7 years ago • 5 comments

The new event UI has a textarea for the description, which invites use of newlines. The Save button seems to work: the app goes from NewEvent back to Home and the new event appears briefly, but it then disappears.

I see a complaint in the console about an unescaped control character (decimal 10 is newline):

Uncaught (in promise) Error: GraphQL error: Unable to parse the JSON document: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value
 at [Source: (String)"{
    "version": "2017-02-28",
    "operation": "PutItem",
    "key": {
        "id": { "S": "5f7a4c6d-eee0-474a-b4ca-2b52e953a8bf"}
    },
    "attributeValues": {
        "name": { "S": "one" },
        "where": { "S": "two" },
        "when": { "S": "2018-02-23T00:15:00Z" },
        "description": { "S": "three
four" }
    }
}"; line: 11, column: 38]
 at [Source: (String)"{
    "version": "2017-02-28",
    "operation": "PutItem",
    "key": {
        "id": { "S": "5f7a4c6d-eee0-474a-b4ca-2b52e953a8bf"}
    },
    "attributeValues": {
        "name": { "S": "one" },
        "where": { "S": "two" },
        "when": { "S": "2018-02-23T00:15:00Z" },
        "description": { "S": "three
four" }
    }
}"; line: 11, column: 38]

ceich avatar Feb 23 '18 00:02 ceich

When I edit an event in DynamoDB console to have a newline in the description, it properly shows as \n in the console, but the app displays it as a space.

ceich avatar Feb 23 '18 00:02 ceich

A simple fix would be to escape() before creating and unescape() before displaying, but the job of satisfying DynamoDB's need for valid JSON seems to belong to the GraphQL layer or the Resolver.

ceich avatar Feb 23 '18 00:02 ceich

Ah, I see what you mean. This is a limitation of the request mapping template currently as the result of the evaluated template is expected to be a JSON object that will be used to configure the call to DynamoDB. You can currently pass mutli-line strings through to dynamodb by referencing an argument on the context.

For example if you had this:

{
    "version": "2017-02-28",
    "operation": "PutItem",
    "key": {
        "id": { "S": "5f7a4c6d-eee0-474a-b4ca-2b52e953a8bf"}
    },
    "attributeValues": {
        "name": { "S": "one" },
        "where": { "S": "two" },
        "when": { "S": "2018-02-23T00:15:00Z" },
        "description": { "S": "$ctx.args.description" }
    }
}

You can pass a description with newlines as you might expect. I'll take a note of this and look into the possibility of escaping the evaluated template. Thanks for the feedback!

mikeparisstuff avatar Feb 23 '18 22:02 mikeparisstuff

@mikeparisstuff this solution does not work for me. I'm using RDS and it only fails when the description has a new line

Zerquix18 avatar Dec 20 '18 22:12 Zerquix18

So what fixed the issue in my case was to escape the value with:

$util.escapeJavaScript()

eg:

"$util.escapeJavaScript($ctx.args.long_description)"

Zerquix18 avatar Dec 20 '18 22:12 Zerquix18