use of com.yahoo.elide.graphql.parser.SubscriptionEntityProjectionMaker in project elide by yahoo.
the class SubscriptionDataFetcherTest method runSubscription.
/**
* Run a subscription.
* @param request The subscription query.
* @return A discrete list of results returned from the subscription.
*/
protected List<ExecutionResult> runSubscription(String request) {
InMemoryDataStore inMemoryDataStore = new InMemoryDataStore(dataStore);
DataStoreTransaction tx = inMemoryDataStore.beginTransaction();
GraphQLProjectionInfo projectionInfo = new SubscriptionEntityProjectionMaker(settings, new HashMap<>(), NO_VERSION).make(request);
GraphQLRequestScope requestScope = new GraphQLRequestScope(baseUrl, tx, null, NO_VERSION, settings, projectionInfo, UUID.randomUUID(), null);
ExecutionInput executionInput = ExecutionInput.newExecutionInput().query(request).localContext(requestScope).build();
ExecutionResult executionResult = api.execute(executionInput);
if (!(executionResult.getData() instanceof Publisher)) {
return List.of(executionResult);
}
Publisher<ExecutionResult> resultPublisher = executionResult.getData();
requestScope.getTransaction().commit(requestScope);
if (resultPublisher == null) {
return List.of(executionResult);
}
List<ExecutionResult> results = new ArrayList<>();
AtomicReference<Subscription> subscriptionRef = new AtomicReference<>();
AtomicReference<Throwable> errorRef = new AtomicReference<>();
resultPublisher.subscribe(new Subscriber<ExecutionResult>() {
@Override
public void onSubscribe(Subscription subscription) {
subscriptionRef.set(subscription);
subscription.request(1);
}
@Override
public void onNext(ExecutionResult executionResult) {
results.add(executionResult);
subscriptionRef.get().request(1);
}
@Override
public void onError(Throwable t) {
errorRef.set(t);
}
@Override
public void onComplete() {
// NOOP
}
});
return results;
}
use of com.yahoo.elide.graphql.parser.SubscriptionEntityProjectionMaker in project elide by yahoo.
the class RequestHandler method executeRequest.
public synchronized ExecutionResult executeRequest(Subscribe subscribeRequest) {
if (transaction != null) {
throw new IllegalStateException("Already handling an active request.");
}
transaction = topicStore.beginReadTransaction();
elide.getTransactionRegistry().addRunningTransaction(requestID, transaction);
ElideSettings settings = elide.getElideSettings();
GraphQLProjectionInfo projectionInfo = new SubscriptionEntityProjectionMaker(settings, subscribeRequest.getPayload().getVariables(), connectionInfo.getGetApiVersion()).make(subscribeRequest.getPayload().getQuery());
GraphQLRequestScope requestScope = new GraphQLRequestScope(connectionInfo.getBaseUrl(), transaction, connectionInfo.getUser(), connectionInfo.getGetApiVersion(), settings, projectionInfo, requestID, connectionInfo.getParameters());
ExecutionInput executionInput = ExecutionInput.newExecutionInput().query(subscribeRequest.getPayload().getQuery()).operationName(subscribeRequest.getPayload().getOperationName()).variables(subscribeRequest.getPayload().getVariables()).localContext(requestScope).build();
log.info("Processing GraphQL query:\n{}", subscribeRequest.getPayload().getQuery());
return api.execute(executionInput);
}
Aggregations