UTF-8 Request Parser
See original GitHub issueIn 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:
- Created 4 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
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.
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.