-
-
Notifications
You must be signed in to change notification settings - Fork 916
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
Automatic Persisted Queries #3134
Conversation
Is this targeting v5.3.0 or v6? Assuming we are targeting v5.3.0 then we cannot make breaking changes to existing classes and interfaces. |
I was trying to make breaking changes as little as possible. It seems like only |
I think the biggest issue is that |
I do see that For example -- would this compile anymore?? class test : IDocumentCache
{
System.Threading.Tasks.ValueTask<GraphQLParser.AST.GraphQLDocument?> IDocumentCache.GetAsync(string key)
{
//do some stuff
}
} I can't remember -- wouldn't it have to change to this? class test : IDocumentCache
{
System.Threading.Tasks.ValueTask<GraphQLParser.AST.GraphQLDocument?> ICache<GraphQLParser.AST.GraphQLDocument>.GetAsync(string key)
{
//do some stuff
}
} |
src/GraphQL.MemoryCache/AutomaticPersistedQueries/AutomaticPersistedQueriesExecution.cs
Outdated
Show resolved
Hide resolved
src/GraphQL.MemoryCache/AutomaticPersistedQueries/AutomaticPersistedQueriesExecution.cs
Outdated
Show resolved
Hide resolved
src/GraphQL.MemoryCache/AutomaticPersistedQueries/AutomaticPersistedQueriesExecution.cs
Outdated
Show resolved
Hide resolved
src/GraphQL.MemoryCache/AutomaticPersistedQueries/AutomaticPersistedQueriesExecution.cs
Outdated
Show resolved
Hide resolved
src/GraphQL.MemoryCache/AutomaticPersistedQueries/AutomaticPersistedQueriesExecution.cs
Outdated
Show resolved
Hide resolved
src/GraphQL.MemoryCache/AutomaticPersistedQueries/AutomaticPersistedQueriesExecution.cs
Outdated
Show resolved
Hide resolved
src/GraphQL.MemoryCache/AutomaticPersistedQueries/AutomaticPersistedQueriesExecution.cs
Outdated
Show resolved
Hide resolved
src/GraphQL.MemoryCache/AutomaticPersistedQueries/PersistedQueryUnsupportedVersionError.cs
Outdated
Show resolved
Hide resolved
Regarding biggest issue. For me this implementation is overcomplicated and contains a lot of things that have no value. I'm completely against |
@sungam3r Don't you think that a REDIS implementation could be significant to users? You do not think we should at least support some type of extension supporting such a scenario? I suggest that even if we eliminate the interfaces you mentioned (okay with me), implement the APQ functionality as an abstract class, with the memory implementation as a derived class on top of it. In that manner, anyone can implement their own caching implementation and there are less abstractions that need to be maintained without completely blocking derived implementations. Something like this: (quick draft) public abstract class APQBase : IConfigureExecution
{
public virtual Task<ExecutionResult> ExecuteAsync(ExecutionOptions options, ExecutionDelegate next)
{
//implementation here
}
// add some methods to generate errors, which can be overridden if logging is desired
public virtual ValueTask<ExecutionResult> HandleNotInCacheErrorAsync(ExecutionOptions options)
=> new(new ExecutionResult { ExecutionErrors = new() { new NotInCacheError() } }); //or whatever
// similar for invalid version and similar errors
public virtual string HashQuery(string query) { } // default SHA hash code here, which can be overridden (??)
public abstract ValueTask<string?> GetQueryAsync(string hash)
{
}
public abstract Task SetQueryAsync(string hash, string query)
{
}
} Without a REDIS cache, APQ usefulness is somewhat limited to a single-server design, as a request through a load balancer to one server may have a cache miss, and the subsequent request containing the full query may hit a different server, which could already have a populated cache entry. Of course we can optimize for an in-memory cache, but it seems that we should also support a custom cache implementation. Some users may even want to stack a memory cache with a distributed cache. |
No if this causes a significant complication of the main scenario - keeping hash-query dictionary into memory.
Of course, I argee with provided example. APQ may and should be abstracted itself as a whole concept. It seems that abstracting on top of
I understand but eventually (sooner or later) every app node's hash-query cache will be filled with all needed data. |
I'm fine either way. In case v5.3.0 it should at least be mentioned in release notes. |
I agree |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
src/GraphQL.MemoryCache/AutomaticPersistedQueries/AutomaticPersistedQueriesExecutionBase.cs
Outdated
Show resolved
Hide resolved
src/GraphQL.MemoryCache/AutomaticPersistedQueries/AutomaticPersistedQueriesExecutionBase.cs
Outdated
Show resolved
Hide resolved
src/GraphQL.MemoryCache/AutomaticPersistedQueries/AutomaticPersistedQueriesExecutionBase.cs
Outdated
Show resolved
Hide resolved
src/GraphQL.MemoryCache/AutomaticPersistedQueries/AutomaticPersistedQueriesExecutionBase.cs
Outdated
Show resolved
Hide resolved
src/GraphQL.MemoryCache/AutomaticPersistedQueries/AutomaticPersistedQueriesExecutionBase.cs
Outdated
Show resolved
Hide resolved
…sistedQueriesExecutionBase.cs
src/GraphQL.MemoryCache/AutomaticPersistedQueries/AutomaticPersistedQueriesExecutionBase.cs
Outdated
Show resolved
Hide resolved
src/GraphQL.MemoryCache/AutomaticPersistedQueries/AutomaticPersistedQueriesExecutionBase.cs
Outdated
Show resolved
Hide resolved
src/GraphQL.MemoryCache/AutomaticPersistedQueries/AutomaticPersistedQueriesCacheOptions.cs
Outdated
Show resolved
Hide resolved
I'm fine with this PR. Only 1 thing - make methods from AutomaticPersistedQueriesExecutionBase protected |
…sistedQueriesCacheOptions.cs Co-authored-by: Ivan Maximov <sungam3r@yandex.ru>
Codecov Report
@@ Coverage Diff @@
## master #3134 +/- ##
==========================================
+ Coverage 84.31% 84.43% +0.11%
==========================================
Files 363 371 +8
Lines 15949 16087 +138
Branches 2581 2599 +18
==========================================
+ Hits 13448 13583 +135
+ Misses 1883 1882 -1
- Partials 618 622 +4
Continue to review full report at Codecov.
|
Implementation of Automatic Persisted Queries (APQ) based on
IConfigureExecution
middleware and in-memory cache. It is a possible solution of the issue graphql-dotnet/server#132. The feature has been implemented in accordance with APQ protocol, Apollo logic and general architecture:Typical incoming request looks the following way: