Search in sources :

Example 1 with ExecutionResultImpl

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());
}
Also used : Field(graphql.language.Field) ExecutionResultImpl(graphql.ExecutionResultImpl) ExecutionResult(graphql.ExecutionResult) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with ExecutionResultImpl

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));
}
Also used : ExecutionResultImpl(graphql.ExecutionResultImpl) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with ExecutionResultImpl

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);
}
Also used : NonNullableFieldWasNullException(graphql.execution.NonNullableFieldWasNullException) MissingRootTypeException(graphql.execution.MissingRootTypeException) NonNullableFieldWasNullError(graphql.execution.NonNullableFieldWasNullError) ArrayList(java.util.ArrayList) SerializationError(graphql.SerializationError) InvalidSyntaxError(graphql.InvalidSyntaxError) ExecutionResultImpl(graphql.ExecutionResultImpl) GraphQLError(graphql.GraphQLError) ExceptionWhileDataFetching(graphql.ExceptionWhileDataFetching) ValidationError(graphql.validation.ValidationError) CoercingSerializeException(graphql.schema.CoercingSerializeException)

Example 4 with ExecutionResultImpl

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);
    });
}
Also used : Field(graphql.language.Field) ExecutionTypeInfo(graphql.execution.ExecutionTypeInfo) ExecutionResultImpl(graphql.ExecutionResultImpl) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) InstrumentationExecutionStrategyParameters(graphql.execution.instrumentation.parameters.InstrumentationExecutionStrategyParameters) ExecutionStrategyParameters(graphql.execution.ExecutionStrategyParameters) ExecutionPath(graphql.execution.ExecutionPath)

Example 5 with ExecutionResultImpl

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());
}
Also used : FragmentDefinition(graphql.language.FragmentDefinition) VariableDefinition(graphql.language.VariableDefinition) NodeUtil(graphql.language.NodeUtil) ExecutionResultImpl(graphql.ExecutionResultImpl) GraphQLError(graphql.GraphQLError) InstrumentationExecutionParameters(graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters) OperationDefinition(graphql.language.OperationDefinition)

Aggregations

ExecutionResultImpl (graphql.ExecutionResultImpl)17 ExecutionResult (graphql.ExecutionResult)7 LinkedHashMap (java.util.LinkedHashMap)7 Field (graphql.language.Field)6 List (java.util.List)6 GraphQLError (graphql.GraphQLError)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 CoercingSerializeException (graphql.schema.CoercingSerializeException)3 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)3 ExecutionStrategyParameters (graphql.execution.ExecutionStrategyParameters)2 NonNullableFieldWasNullException (graphql.execution.NonNullableFieldWasNullException)2 Instrumentation (graphql.execution.instrumentation.Instrumentation)2 InstrumentationExecutionStrategyParameters (graphql.execution.instrumentation.parameters.InstrumentationExecutionStrategyParameters)2 OperationDefinition (graphql.language.OperationDefinition)2 GraphQLObjectType (graphql.schema.GraphQLObjectType)2 ArrayList (java.util.ArrayList)2 CompletionException (java.util.concurrent.CompletionException)2 ExceptionWhileDataFetching (graphql.ExceptionWhileDataFetching)1 GraphQLException (graphql.GraphQLException)1 InvalidSyntaxError (graphql.InvalidSyntaxError)1