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;
}
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;
}
Aggregations