Skip to content
This repository has been archived by the owner on Mar 6, 2020. It is now read-only.

Better string support (double quotes or escaped singles) #34

Closed
2 tasks
ErisDS opened this issue Oct 13, 2017 · 2 comments
Closed
2 tasks

Better string support (double quotes or escaped singles) #34

ErisDS opened this issue Oct 13, 2017 · 2 comments

Comments

@ErisDS
Copy link
Member

ErisDS commented Oct 13, 2017

GQL works mostly on literals - strings that don't need to be quoted because they are obviously strings.

E.g. tag:photo, we don't need to do tag:'photo', it's totally redundant!

However, if a string contains a character that has another purpose in the GQL language, we have to use quotes to make it clear the whole thing is intended as a string.

E.g. in a date string published_at:<2017-09-01 12:45:12, both the space and the colons mean that we cannot use a literal, and we need to use quotes e.g. published_at:<'2017-09-01 12:45:12'.

This works absolutely wonderfully if the filter lives in a URL encoded URL string, or in JSON, but poses a problem in javascript code:

Example from the prev/next helper in Ghost:

  apiOptions = {
            include: 'author,tags',
            order: 'published_at ' + order,
            limit: 1,
            filter: "slug:-" + slug + "+published_at:" + op + "'" + publishedAt + "'", // jscs:ignore
        }

Normally we would use single quotes around the code, but we can't because this would clash with GQL.

In other languages, you'd switch to using double quotes, but GQL doesn't support this.

If we switch to using template literals:

  apiOptions = {
            filter: `slug:-${slug}+published_at:${op}'${publishedAt}'`, // jscs:ignore
}

The single quotes end up escaped like \' inside the string, which GQL also doesn't understand!!!

TODO:

  • At least support escaped single quotes
  • Consider supporting double quotes
@kirrg001
Copy link
Contributor

The single quotes end up escaped like ' inside the string, which GQL also doesn't understand!!!

Looks like this is not true? 🤔 NQL and GQL are able to parse escaped strings. Works for me if you use template literals.

The only problem i see is this case

nql('x:2017-09-01 12:45:12').parse()

This will throw a parse error, because the date is not wrapped into quotes.

@ErisDS If there is a need to keep this issue, let me know 👍 The alternative is to close this issue and wait for user/bug reports. I have not seen a report for this problem in Ghost so far.

@kirrg001
Copy link
Contributor

Oops just saw https://github.com/NexesJS/NQL-Lang/issues/4. The issue was not referenced.


GQL was replaced by NQL. GQL is deprecated 👍

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

No branches or pull requests

2 participants