Search in sources :

Example 1 with InstrumentationFieldParameters

use of graphql.execution.instrumentation.parameters.InstrumentationFieldParameters in project graphql-java by graphql-java.

the class BatchedExecutionStrategy method resolveField.

private CompletableFuture<List<ExecutionNode>> resolveField(ExecutionContext executionContext, ExecutionStrategyParameters parameters, String fieldName, ExecutionNode node) {
    GraphQLObjectType parentType = node.getType();
    List<Field> fields = node.getFields().get(fieldName);
    GraphQLFieldDefinition fieldDef = getFieldDef(executionContext.getGraphQLSchema(), parentType, fields.get(0));
    Instrumentation instrumentation = executionContext.getInstrumentation();
    ExecutionTypeInfo typeInfo = parameters.getTypeInfo();
    InstrumentationContext<ExecutionResult> fieldCtx = instrumentation.beginField(new InstrumentationFieldParameters(executionContext, fieldDef, typeInfo));
    CompletableFuture<FetchedValues> fetchedData = fetchData(executionContext, parameters, fieldName, node, fieldDef);
    CompletableFuture<List<ExecutionNode>> result = fetchedData.thenApply((fetchedValues) -> {
        GraphqlFieldVisibility fieldVisibility = executionContext.getGraphQLSchema().getFieldVisibility();
        Map<String, Object> argumentValues = valuesResolver.getArgumentValues(fieldVisibility, fieldDef.getArguments(), fields.get(0).getArguments(), executionContext.getVariables());
        return completeValues(executionContext, fetchedValues, typeInfo, fieldName, fields, argumentValues);
    });
    fieldCtx.onDispatched(null);
    result.whenComplete((nodes, throwable) -> fieldCtx.onCompleted(null, throwable));
    return result;
}
Also used : GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) Instrumentation(graphql.execution.instrumentation.Instrumentation) ExecutionResult(graphql.ExecutionResult) InstrumentationFieldParameters(graphql.execution.instrumentation.parameters.InstrumentationFieldParameters) Field(graphql.language.Field) ExecutionTypeInfo(graphql.execution.ExecutionTypeInfo) GraphqlFieldVisibility(graphql.schema.visibility.GraphqlFieldVisibility) GraphQLObjectType(graphql.schema.GraphQLObjectType) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) GraphQLList(graphql.schema.GraphQLList)

Example 2 with InstrumentationFieldParameters

use of graphql.execution.instrumentation.parameters.InstrumentationFieldParameters in project graphql-java by graphql-java.

the class ExecutionStrategy method resolveField.

/**
 * Called to fetch a value for a field and resolve it further in terms of the graphql query.  This will call
 * #fetchField followed by #completeField and the completed {@link ExecutionResult} is returned.
 * <p>
 * An execution strategy can iterate the fields to be executed and call this method for each one
 * <p>
 * Graphql fragments mean that for any give logical field can have one or more {@link Field} values associated with it
 * in the query, hence the fieldList.  However the first entry is representative of the field for most purposes.
 *
 * @param executionContext contains the top level execution parameters
 * @param parameters       contains the parameters holding the fields to be executed and source object
 *
 * @return an {@link ExecutionResult}
 *
 * @throws NonNullableFieldWasNullException if a non null field resolves to a null value
 */
protected CompletableFuture<ExecutionResult> resolveField(ExecutionContext executionContext, ExecutionStrategyParameters parameters) {
    GraphQLFieldDefinition fieldDef = getFieldDef(executionContext, parameters, parameters.getField().get(0));
    Instrumentation instrumentation = executionContext.getInstrumentation();
    InstrumentationContext<ExecutionResult> fieldCtx = instrumentation.beginField(new InstrumentationFieldParameters(executionContext, fieldDef, fieldTypeInfo(parameters, fieldDef)));
    CompletableFuture<ExecutionResult> result = fetchField(executionContext, parameters).thenCompose((fetchedValue) -> completeField(executionContext, parameters, fetchedValue));
    fieldCtx.onDispatched(result);
    result.whenComplete(fieldCtx::onCompleted);
    return result;
}
Also used : GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) Instrumentation(graphql.execution.instrumentation.Instrumentation) ExecutionResult(graphql.ExecutionResult) InstrumentationFieldParameters(graphql.execution.instrumentation.parameters.InstrumentationFieldParameters)

Aggregations

ExecutionResult (graphql.ExecutionResult)2 Instrumentation (graphql.execution.instrumentation.Instrumentation)2 InstrumentationFieldParameters (graphql.execution.instrumentation.parameters.InstrumentationFieldParameters)2 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)2 ExecutionTypeInfo (graphql.execution.ExecutionTypeInfo)1 Field (graphql.language.Field)1 GraphQLList (graphql.schema.GraphQLList)1 GraphQLObjectType (graphql.schema.GraphQLObjectType)1 GraphqlFieldVisibility (graphql.schema.visibility.GraphqlFieldVisibility)1 ArrayList (java.util.ArrayList)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1