gql-dart / gql

Libraries supporting GraphQL in Dart
MIT License
267 stars 121 forks source link

[BUG] Printer fails with string blocks #453

Open sh1l0n opened 5 months ago

sh1l0n commented 5 months ago

When a String is on format

"Lore ipsum
One
Two"

The query execution should valid due to "Invalid character on string literal" error appear, for fixing it the function visitStringValueNode should return the string in the right format like:

"Lore ipsum\nOne\nTwo"
knaeckeKami commented 5 months ago

According to https://spec.graphql.org/June2018/#sec-String-Value A multiline like

"Lore ipsum
One
Two"

is not allowed, for multiline strings, block strings (with triple quotes) are required.

Does this still fail for proper block strings?

sh1l0n commented 5 months ago

According to https://spec.graphql.org/June2018/#sec-String-Value A multiline like

"Lore ipsum
One
Two"

is not allowed, for multiline strings, block strings (with triple quotes) are required.

Does this still fail for proper block strings?

About the documentation thx a lot, now are integrated all the escaped characters in https://github.com/gql-dart/gql/pull/454/commits/ae3d44c58f2d146cd6252438ad0cffea288c0a6d https://github.com/gql-dart/gql/pull/454

I will show you with an example

  1. The stringValueNode parameter contains this text: "Lore ipsum\nOne\nTwo";
  2. stringValueNode.isBlock will return false since is not """
  3. When printNode is called, stringValueNode will be displayed as
    "Lore ipsum
    One
    Two"

    causing a problem when encoding the query with the gql_link RequestSerializer https://github.com/gql-dart/gql/blob/2dad214daebcc40e5b34a7315e1d4bfb85cb04d0/links/gql_link/lib/src/request_serializer.dart#L17

sh1l0n commented 5 months ago

According to https://spec.graphql.org/June2018/#sec-String-Value A multiline like

"Lore ipsum
One
Two"

is not allowed, for multiline strings, block strings (with triple quotes) are required.

Does this still fail for proper block strings?

Is is possible also that the Token is not computing the strings correctly? https://github.com/gql-dart/gql/blob/2dad214daebcc40e5b34a7315e1d4bfb85cb04d0/gql/lib/src/language/lexer.dart#L53

knaeckeKami commented 5 months ago

Is is possible also that the Token is not computing the strings correctly?

If you point me to any nontrivial piece of code and ask me "is it possible that there is a bug" I'll always say yes ;)

Do you have any specific lead to a potential issue?

knaeckeKami commented 5 months ago

According to https://spec.graphql.org/June2018/#sec-String-Value A multiline like

"Lore ipsum
One
Two"

is not allowed, for multiline strings, block strings (with triple quotes) are required. Does this still fail for proper block strings?

About the documentation thx a lot, now are integrated all the escaped characters in ae3d44c #454

I will show you with an example

  1. The stringValueNode parameter contains this text: "Lore ipsum\nOne\nTwo";
  2. stringValueNode.isBlock will return false since is not """
  3. When printNode is called, stringValueNode will be displayed as
"Lore ipsum
One
Two"

causing a problem when encoding the query with the gql_link RequestSerializer

https://github.com/gql-dart/gql/blob/2dad214daebcc40e5b34a7315e1d4bfb85cb04d0/links/gql_link/lib/src/request_serializer.dart#L17

Yes, that's true; There is an issue.