Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQL printer produces invalid documentation strings #2569

Closed
pcarrier opened this issue May 21, 2020 · 4 comments · Fixed by #2745
Closed

GraphQL printer produces invalid documentation strings #2569

pcarrier opened this issue May 21, 2020 · 4 comments · Fixed by #2745
Assignees
Labels

Comments

@pcarrier
Copy link
Contributor

pcarrier commented May 21, 2020

With graphql-js 15.0.0:

import graphql from 'graphql';
console.log(graphql.printSchema(graphql.buildASTSchema(graphql.parse(`"Ex\\\\ample" scalar Foo`))));
node .\index.mjs
"""Ex\ample"""
scalar Foo

which is an invalid escape according to the spec.

@thenamankumar
Copy link
Contributor

@pcarrier this is not an invalid result. The js string literals are auto escaped.

`"Ex\\\\ample" scalar Foo`.split('') === [ "\"", "E", "x", "\\", "\\", "a", "m", "p", "l", "e", "\"", " ", "s", "c", "a", "l", "a", "r", " ", "F", "o", "o" ]
// true

So the string provided to the parser actually has only 2 \ and it returns the correct result according to that. If you try using String.raw and wrap your gql string with it then this problem can be solved.

@IvanGoncharov
Copy link
Member

@pcarrier Please also note that block strings are treated slash just as slash:
http://spec.graphql.org/draft/#sel-IAFdPVREBCABCCBvoT
So in GraphQL """Ex\ample""" and "Ex\\ample" are equal.

@IvanGoncharov
Copy link
Member

@hereisnaman Please ensure that we have such a similar test case in our tests.

@pcarrier
Copy link
Contributor Author

Thanks for the explanation, block strings are indeed simpler yet smarter than I had originally understood.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants