graphql-go-tools icon indicating copy to clipboard operation
graphql-go-tools copied to clipboard

String literal input value is trimming whitespace

Open mattjohnsonpint opened this issue 1 year ago • 3 comments

If I have an operation with a string literal input value that has leading or trailing whitespace, such as:

query {
    test(s: "  abcd  ")
}

... the string gets trimmed to just "abcd" when the operation is parsed.

If instead I pass as a variable, then the string is not trimmed.

According to the GraphQL Spec:

... White space and other otherwise-ignored characters are significant within a string value. ...

Thus I would expect to never have the string input trimmed of whitespace.

I believe this is happening because lexer.readSingleLineString is designed to seek out whitespace and exclude it from the string. IMHO it should not.

https://github.com/wundergraph/graphql-go-tools/blob/6526186b7e823632f2c4f541497b7dd421a8bade/v2/pkg/lexer/lexer.go#L387-L431

Thanks.

mattjohnsonpint avatar Oct 25 '24 18:10 mattjohnsonpint

From a first glance it looks like you're right.

jensneuse avatar Oct 25 '24 18:10 jensneuse

@devsergiy please take a look.

StarpTech avatar Nov 05 '24 10:11 StarpTech

Faced the same issue in my project. An interesting observation: if you substitute values not directly, but through query variables, then spaces in strings are not cut off

mmaxim2710 avatar Nov 08 '24 08:11 mmaxim2710