use of com.yahoo.elide.graphql.containers.GraphQLContainer in project elide by yahoo.
the class PersistentResourceFetcher method get.
/**
* Override graphql-java's {@link DataFetcher} get method to execute
* the mutation and return some sensible output values.
* @param environment Graphql-java's execution environment
* @return a collection of {@link PersistentResource} objects
*/
@Override
public Object get(DataFetchingEnvironment environment) {
/* fetch arguments in mutation/query */
Map<String, Object> args = environment.getArguments();
/* fetch current operation */
RelationshipOp operation = (RelationshipOp) args.getOrDefault(ARGUMENT_OPERATION, FETCH);
/* build environment object, extracts required fields */
Environment context = new Environment(environment, nonEntityDictionary);
/* safe enable debugging */
if (log.isDebugEnabled()) {
logContext(log, operation, context);
}
if (operation != FETCH) {
/* Don't allow write operations in a non-mutation request. */
if (environment.getOperationDefinition().getOperation() != OperationDefinition.Operation.MUTATION) {
throw new BadRequestException("Data model writes are only allowed in mutations");
}
/* sanity check for pagination/filtering/sorting arguments w any operation other than FETCH */
filterSortPaginateSanityCheck(context);
}
GraphQLContainer container;
/* delegate request */
switch(operation) {
case FETCH:
{
return fetchObjects(context);
}
case UPSERT:
{
container = upsertObjects(context);
break;
}
case UPDATE:
{
container = updateObjects(context);
break;
}
case DELETE:
{
container = deleteObjects(context);
break;
}
case REMOVE:
{
container = removeObjects(context);
break;
}
case REPLACE:
{
container = replaceObjects(context);
break;
}
default:
throw new UnsupportedOperationException("Unknown operation: " + operation);
}
if (operation != FETCH) {
context.requestScope.runQueuedPreSecurityTriggers();
context.requestScope.runQueuedPreFlushTriggers();
}
return container;
}
Aggregations