change preparsedDocumentProvider return value to CompletableFuture<PreparsedDocumentEntry>#2612
change preparsedDocumentProvider return value to CompletableFuture<PreparsedDocumentEntry>#2612bbakerman merged 10 commits intographql-java:masterfrom
Conversation
…to CompletableFuture<PreparsedDocumentEntry>
| * @throws graphql.execution.preparsed.persisted.PersistedQueryNotFound if the query id is not know at all and you have no query text | ||
| */ | ||
| PreparsedDocumentEntry getPersistedQueryDocument(Object persistedQueryId, ExecutionInput executionInput, PersistedQueryCacheMiss onCacheMiss) throws PersistedQueryNotFound; | ||
| CompletableFuture<PreparsedDocumentEntry> getPersistedQueryDocument(Object persistedQueryId, ExecutionInput executionInput, PersistedQueryCacheMiss onCacheMiss) throws PersistedQueryNotFound; |
There was a problem hiding this comment.
This is indeed a great idea. This should indeed be an async method because its likely to go to a DB etc...for most implementations.
However as implemented this is a hard breaking change.
We can avoid this in this case.
We can
- deprecate the
PreparsedDocumentEntry getPersistedQueryDocument(method - put in a
default CompletableFuture<PreparsedDocumentEntry> getPersistedQueryDocumentAsync(method - make the default call the
getPersistedQueryDocumentand wrap it in a completed CF - make all the calls sites called
CompletableFuture<PreparsedDocumentEntry> getPersistedQueryDocumentAsync(and hence it will invoke the sync version for every one else.
bbakerman
left a comment
There was a problem hiding this comment.
We need to make this a non breaking API change because we can. We sometimes make breaking changes when we cant avoid them but in this case we can and we should avoid it.
Otherwise thank you very much for this PR
| } | ||
|
|
||
| @Override | ||
| public PreparsedDocumentEntry getDocument(ExecutionInput executionInput, Function<ExecutionInput, PreparsedDocumentEntry> parseAndValidateFunction) { |
There was a problem hiding this comment.
Same pattern here. We delegate back from an async method to this method
This is also @PublicSpi and hence people will have derived from it and hence we dont want to break them
|
@bbakerman thanks for your review i understand your comment and i fixed this PR If you have time, please review again. |
src/main/java/graphql/execution/preparsed/PreparsedDocumentProvider.java
Show resolved
Hide resolved
src/main/java/graphql/execution/preparsed/persisted/PersistedQueryCache.java
Show resolved
Hide resolved
| def getDoc = inMemCache.getPersistedQueryDocument(hash, ei, onMiss) | ||
| def doc = getDoc.document | ||
| def getDoc = inMemCache.getPersistedQueryDocumentAsync(hash, ei, onMiss) | ||
| def doc = getDoc.get().document |
There was a problem hiding this comment.
Can we have one test that goes via the old deprecated path so that we have surety that while its alive it works
|
@bbakerman thanks for review add javaDoc, |
bbakerman
left a comment
There was a problem hiding this comment.
I am happy to merge this once the explicit imports is fixed.
Sorry to be a pain.
This is a great PR and will be very useful and I am keen to get it in - but I want to maintain code health as well
src/main/java/graphql/GraphQL.java
Outdated
| import graphql.execution.instrumentation.InstrumentationState; | ||
| import graphql.execution.instrumentation.SimpleInstrumentation; | ||
| import graphql.execution.*; | ||
| import graphql.execution.instrumentation.*; |
There was a problem hiding this comment.
Sorry we require explicit imports - if you are using IDEA set them to 999 before using * for this project
| import graphql.Internal; | ||
| import graphql.ParseAndValidate; | ||
| import graphql.ParseAndValidateResult; | ||
| import graphql.*; |
|
@bbakerman Thanks for the review I'm glad it could be a merge |
bbakerman
left a comment
There was a problem hiding this comment.
Thanks you and thanks for the follow up
|
Build failing |
|
@bbakerman |
|
Hmmm not sure why this is failing the tests |
|
@bbakerman hi
I think, should add an exception handling layer |
change pre parsed Document Provider return value to
CompletableFuture<Preparsed DocumentEntry>because
we use graphql-java on Spring webflux
if we use mongodb or redis for persistent query db then
preparsedDocumentProvider.getDocument()call is blocking