Search in sources :

Example 1 with SubscriptionNodeContainer

use of com.yahoo.elide.graphql.subscriptions.containers.SubscriptionNodeContainer in project elide by yahoo.

the class SubscriptionDataFetcher method get.

@Override
public Object get(DataFetchingEnvironment environment) throws Exception {
    OperationDefinition.Operation op = environment.getOperationDefinition().getOperation();
    if (op != OperationDefinition.Operation.SUBSCRIPTION) {
        throw new InvalidEntityBodyException(String.format("%s not supported for subscription models.", op));
    }
    /* build environment object, extracts required fields */
    Environment context = new Environment(environment, nonEntityDictionary);
    /* safe enable debugging */
    if (log.isDebugEnabled()) {
        logContext(log, RelationshipOp.FETCH, context);
    }
    if (context.isRoot()) {
        String entityName = context.field.getName();
        String aliasName = context.field.getAlias();
        EntityProjection projection = context.requestScope.getProjectionInfo().getProjection(aliasName, entityName);
        Flowable<PersistentResource> recordPublisher = PersistentResource.loadRecords(projection, new ArrayList<>(), context.requestScope).toFlowable(BackpressureStrategy.BUFFER).onBackpressureBuffer(bufferSize, true, false);
        return recordPublisher.map(SubscriptionNodeContainer::new);
    }
    // as the PersistentResourceFetcher.
    return context.container.processFetch(context);
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) PersistentResource(com.yahoo.elide.core.PersistentResource) InvalidEntityBodyException(com.yahoo.elide.core.exceptions.InvalidEntityBodyException) DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) Environment(com.yahoo.elide.graphql.Environment) SubscriptionNodeContainer(com.yahoo.elide.graphql.subscriptions.containers.SubscriptionNodeContainer) OperationDefinition(graphql.language.OperationDefinition)

Aggregations

PersistentResource (com.yahoo.elide.core.PersistentResource)1 InvalidEntityBodyException (com.yahoo.elide.core.exceptions.InvalidEntityBodyException)1 EntityProjection (com.yahoo.elide.core.request.EntityProjection)1 Environment (com.yahoo.elide.graphql.Environment)1 SubscriptionNodeContainer (com.yahoo.elide.graphql.subscriptions.containers.SubscriptionNodeContainer)1 OperationDefinition (graphql.language.OperationDefinition)1 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)1