question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UTF-8 Request Parser

See original GitHub issue

In order to optimize parsing a GraphQL request we want to build a request parser that is built on top of out utf-8 GraphQL Reader.

There are two kinds of GraphQL request that this new parser should be able to handle:

Single Query

{
  "query": "...",
  "operationName": "...",
  "variables": { "myVariable": "someValue", ... },
  "namedQuery" : "....",
  "extension" : { },
}

Query Batch

[
  {
    "query": "...",
    "operationName": "...",
    "variables": { "myVariable": "someValue", ... },
    "namedQuery" : "....",
    "extension" : { },
  }
]

The parser should parse the json and only fully deserialize the properties operationName and namedQuery.

If the query is named before consuming the other properties we need to check if we have a parsed representation of this query in our cache.

If the query is not named we need to hash the query byte representation and use that as query cache.

If the query is not in the cache we will try to parse the query by unescaping the ReadOnlySpan<byte> that is representing the query at this moment.

For this we need to get a temporary array (ArrayPool or stackalloc depending on size).

The resulting unescaped Span<byte> will be used to the parse the query with the Utf8GraphQLParser.

Only if the query can be successfully parsed we will deserialize the other properties that we are still holding as ReadOnlySpan<byte>. This means that if we are running into any parsing issues with the query we will not event try to deserialize the variables and other properties.

note: we need to think about using a sequence for the JSON parser.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
michaelstaibcommented, Jun 24, 2019

Hi @willwolfram18, I will finally start work on the request parser today. I have added some information about the interfaces of the new request object here.

0reactions
michaelstaibcommented, Jun 24, 2019

We need a query cache abstraction that encapsulates read-only access to the cache and query storage.

Only the middleware should add things to the cache or the query storage.

public interface IDocumentCache 
{
    bool TryGet(string queryName, out IDocument document);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

utf 8 - python requests.get() returns improperly decoded ...
When the content-type of the server is 'Content-Type:text/html' , requests.get() returns improperly encoded data. However, if we have the ...
Read more >
Parsing UTF-8 - Omar
This parser will happily accept byte sequence that looks like UTF-8 but aren't valid. In particular, everything in the range U+D800 - U+DFFF...
Read more >
UTF-8 Request Parser #834 - ChilliCream/graphql-platform
This issue will essentially move the query parsing out of the query engine when we are using ASP.net Core. The query engine request...
Read more >
bugs - Who is to blame: parsing UTF8 encoded JSON ...
I'm Riccardo, current developer of URLRead in WL and I have some experience working with encoding in WL. I would like to inform...
Read more >
How to correctly parse UTF-8 encoded HTML to Unicode ...
I'm running a Python program which fetches a UTF-8-encoded web page, and I extract some text from the HTML using BeautifulSoup.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found