use of graphql.ExecutionResultImpl in project admin-console-beta by connexta.
the class ExecutionStrategyImpl method execute.
@Override
public ExecutionResult execute(ExecutionContext executionContext, GraphQLObjectType parentType, Object source, Map<String, List<Field>> fields) {
Map<String, Object> results = new LinkedHashMap<String, Object>();
for (String fieldName : fields.keySet()) {
List<Field> fieldList = fields.get(fieldName);
ExecutionResult resolvedResult = resolveField(executionContext, parentType, source, fieldList);
results.put(fieldName, resolvedResult != null ? resolvedResult.getData() : null);
}
return new ExecutionResultImpl(results, executionContext.getErrors());
}
use of graphql.ExecutionResultImpl in project graphql-java by graphql-java.
the class TracingInstrumentation method instrumentExecutionResult.
@Override
public CompletableFuture<ExecutionResult> instrumentExecutionResult(ExecutionResult executionResult, InstrumentationExecutionParameters parameters) {
Map<Object, Object> currentExt = executionResult.getExtensions();
TracingSupport tracingSupport = parameters.getInstrumentationState();
Map<Object, Object> tracingMap = new LinkedHashMap<>();
tracingMap.putAll(currentExt == null ? Collections.emptyMap() : currentExt);
tracingMap.put("tracing", tracingSupport.snapshotTracingData());
return CompletableFuture.completedFuture(new ExecutionResultImpl(executionResult.getData(), executionResult.getErrors(), tracingMap));
}
use of graphql.ExecutionResultImpl in project graphql-java by graphql-java.
the class ExecutionResultJSONTesting method createER.
private ExecutionResult createER() {
List<GraphQLError> errors = new ArrayList<>();
errors.add(new ValidationError(ValidationErrorType.UnknownType, mkLocations(), "Test ValidationError"));
errors.add(new MissingRootTypeException("Mutations are not supported.", null));
errors.add(new InvalidSyntaxError(mkLocations(), "Not good syntax m'kay"));
errors.add(new NonNullableFieldWasNullError(new NonNullableFieldWasNullException(mkTypeInfo(), mkPath())));
errors.add(new SerializationError(mkPath(), new CoercingSerializeException("Bad coercing")));
errors.add(new ExceptionWhileDataFetching(mkPath(), new RuntimeException("Bang"), mkLocation(666, 999)));
return new ExecutionResultImpl(null, errors);
}
use of graphql.ExecutionResultImpl in project graphql-java by graphql-java.
the class BatchedExecutionStrategy method executeImpl.
private void executeImpl(ExecutionContext executionContext, ExecutionStrategyParameters parameters, ExecutionNode root, ExecutionNode curNode, Queue<ExecutionNode> queueOfNodes, Iterator<String> curFieldNames, CompletableFuture<ExecutionResult> overallResult) {
if (!curFieldNames.hasNext() && queueOfNodes.isEmpty()) {
overallResult.complete(new ExecutionResultImpl(root.getParentResults().get(0).toObject(), executionContext.getErrors()));
return;
}
if (!curFieldNames.hasNext()) {
curNode = queueOfNodes.poll();
curFieldNames = curNode.getFields().keySet().iterator();
}
String fieldName = curFieldNames.next();
List<Field> currentField = curNode.getFields().get(fieldName);
//
// once an object is resolved from a interface / union to a node with an object type, the
// parent type info has effectively changed (it has got more specific), even though the path etc...
// has not changed
ExecutionTypeInfo currentParentTypeInfo = parameters.getTypeInfo();
ExecutionTypeInfo newParentTypeInfo = newTypeInfo().type(curNode.getType()).fieldDefinition(currentParentTypeInfo.getFieldDefinition()).path(currentParentTypeInfo.getPath()).parentInfo(currentParentTypeInfo.getParentTypeInfo()).build();
ExecutionPath fieldPath = curNode.getTypeInfo().getPath().segment(fieldName);
GraphQLFieldDefinition fieldDefinition = getFieldDef(executionContext.getGraphQLSchema(), curNode.getType(), currentField.get(0));
ExecutionTypeInfo typeInfo = newTypeInfo().type(fieldDefinition.getType()).fieldDefinition(fieldDefinition).path(fieldPath).parentInfo(newParentTypeInfo).build();
ExecutionStrategyParameters newParameters = parameters.transform(builder -> builder.path(fieldPath).field(currentField).typeInfo(typeInfo));
ExecutionNode finalCurNode = curNode;
Iterator<String> finalCurFieldNames = curFieldNames;
resolveField(executionContext, newParameters, fieldName, curNode).whenComplete((childNodes, exception) -> {
if (exception != null) {
handleNonNullException(executionContext, overallResult, exception);
return;
}
queueOfNodes.addAll(childNodes);
executeImpl(executionContext, newParameters, root, finalCurNode, queueOfNodes, finalCurFieldNames, overallResult);
});
}
use of graphql.ExecutionResultImpl in project graphql-java by graphql-java.
the class Execution method execute.
public CompletableFuture<ExecutionResult> execute(Document document, GraphQLSchema graphQLSchema, ExecutionId executionId, ExecutionInput executionInput, InstrumentationState instrumentationState) {
NodeUtil.GetOperationResult getOperationResult = NodeUtil.getOperation(document, executionInput.getOperationName());
Map<String, FragmentDefinition> fragmentsByName = getOperationResult.fragmentsByName;
OperationDefinition operationDefinition = getOperationResult.operationDefinition;
ValuesResolver valuesResolver = new ValuesResolver();
Map<String, Object> inputVariables = executionInput.getVariables();
List<VariableDefinition> variableDefinitions = operationDefinition.getVariableDefinitions();
Map<String, Object> coercedVariables;
try {
coercedVariables = valuesResolver.coerceArgumentValues(graphQLSchema, variableDefinitions, inputVariables);
} catch (RuntimeException rte) {
if (rte instanceof GraphQLError) {
return completedFuture(new ExecutionResultImpl((GraphQLError) rte));
}
throw rte;
}
ExecutionContext executionContext = newExecutionContextBuilder().instrumentation(instrumentation).instrumentationState(instrumentationState).executionId(executionId).graphQLSchema(graphQLSchema).queryStrategy(queryStrategy).mutationStrategy(mutationStrategy).subscriptionStrategy(subscriptionStrategy).context(executionInput.getContext()).root(executionInput.getRoot()).fragmentsByName(fragmentsByName).variables(coercedVariables).document(document).operationDefinition(operationDefinition).build();
InstrumentationExecutionParameters parameters = new InstrumentationExecutionParameters(executionInput, graphQLSchema, instrumentationState);
executionContext = instrumentation.instrumentExecutionContext(executionContext, parameters);
return executeOperation(executionContext, parameters, executionInput.getRoot(), executionContext.getOperationDefinition());
}
Aggregations