use of graphql.schema.GraphQLFieldDefinition in project admin-console-beta by connexta.
the class ExecutionStrategyImpl method resolveField.
@Override
protected ExecutionResult resolveField(ExecutionContext executionContext, GraphQLObjectType parentType, Object source, List<Field> fields) {
GraphQLFieldDefinition fieldDef = getFieldDef(executionContext.getGraphQLSchema(), parentType, fields.get(0));
Map<String, Object> argumentValues = valuesResolver.getArgumentValues(fieldDef.getArguments(), fields.get(0).getArguments(), executionContext.getVariables());
DataFetchingEnvironment environment = new DataFetchingEnvironment(source, argumentValues, executionContext.getRoot(), fields, fieldDef.getType(), parentType, executionContext.getGraphQLSchema());
Object resolvedValue = null;
try {
resolvedValue = fieldDef.getDataFetcher().get(environment);
if (resolvedValue instanceof FunctionReport) {
FunctionReport<DataType> report = ((FunctionReport) resolvedValue);
resolvedValue = report.isResultPresent() ? report.result().getValue() : null;
List<Message> msgs = report.messages();
msgs.stream().map(GraphQLErrorMessageWrapper::new).forEach(executionContext::addError);
}
} catch (Exception e) {
LOGGER.info("Exception while fetching data", e);
executionContext.addError(new ExceptionWhileDataFetching(e));
}
return completeValue(executionContext, fieldDef.getType(), fields, resolvedValue);
}
use of graphql.schema.GraphQLFieldDefinition in project admin-console-beta by connexta.
the class GraphQLTransformOutput method fieldToGraphQLFieldDefinition.
public GraphQLFieldDefinition fieldToGraphQLFieldDefinition(Field field) {
List<GraphQLArgument> graphQLArgs = new ArrayList<>();
DataType returnType;
if (field instanceof FunctionField) {
FunctionField function = (FunctionField) field;
if (function.getArguments() != null) {
function.getArguments().forEach(f -> graphQLArgs.add(fieldToGraphQLArgument((DataType) f)));
}
returnType = function.getReturnType();
} else {
returnType = (DataType) field;
}
return GraphQLFieldDefinition.newFieldDefinition().name(field.fieldName()).description(field.description()).type(fieldToGraphQLOutputType(returnType)).argument(graphQLArgs).dataFetcher(field instanceof FunctionField ? (env -> functionDataFetcher(env, (FunctionField) field)) : (env -> dataTypeDataFetcher(env, (DataType) field))).build();
}
Aggregations