use of com.yahoo.elide.graphql.Environment 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);
}
use of com.yahoo.elide.graphql.Environment in project elide by yahoo.
the class PageInfoContainer method processFetch.
@Override
public Object processFetch(Environment context) {
String fieldName = context.field.getName();
ConnectionContainer connectionContainer = getConnectionContainer();
Optional<Pagination> pagination = connectionContainer.getPagination();
List<String> ids = connectionContainer.getPersistentResources().stream().map(PersistentResource::getId).sorted().collect(Collectors.toList());
return pagination.map(pageValue -> {
switch(KeyWord.byName(fieldName)) {
case PAGE_INFO_HAS_NEXT_PAGE:
{
int numResults = ids.size();
int nextOffset = numResults + pageValue.getOffset();
return nextOffset < pageValue.getPageTotals();
}
case PAGE_INFO_START_CURSOR:
return pageValue.getOffset();
case PAGE_INFO_END_CURSOR:
return pageValue.getOffset() + ids.size();
case PAGE_INFO_TOTAL_RECORDS:
return pageValue.getPageTotals();
default:
break;
}
throw new BadRequestException("Invalid request. Looking for field: " + fieldName + " in an pageInfo object.");
}).orElseThrow(() -> new BadRequestException("Could not generate pagination information for type: " + connectionContainer.getTypeName()));
}
Aggregations