Search in sources :

Example 1 with GraphQLFieldDefinition

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);
}
Also used : Message(org.codice.ddf.admin.api.report.Message) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) FunctionReport(org.codice.ddf.admin.api.report.FunctionReport) DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) DataType(org.codice.ddf.admin.api.DataType) ExceptionWhileDataFetching(graphql.ExceptionWhileDataFetching)

Example 2 with GraphQLFieldDefinition

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();
}
Also used : FunctionField(org.codice.ddf.admin.api.fields.FunctionField) DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) Arrays(java.util.Arrays) GraphQLScalarType(graphql.schema.GraphQLScalarType) LoggerFactory(org.slf4j.LoggerFactory) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) HashMap(java.util.HashMap) GraphQLUnionType(graphql.schema.GraphQLUnionType) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Scalars(graphql.Scalars) Lists(com.google.common.collect.Lists) FIELD_TYPE_NAME_KEY(org.codice.ddf.admin.api.fields.UnionField.FIELD_TYPE_NAME_KEY) EnumField(org.codice.ddf.admin.api.fields.EnumField) FunctionReport(org.codice.ddf.admin.api.report.FunctionReport) Map(java.util.Map) FunctionField(org.codice.ddf.admin.api.fields.FunctionField) TypeResolver(graphql.schema.TypeResolver) GraphQLTransformCommons.capitalize(org.codice.ddf.admin.graphql.common.GraphQLTransformCommons.capitalize) UnionField(org.codice.ddf.admin.api.fields.UnionField) DataType(org.codice.ddf.admin.api.DataType) GraphQLObjectType(graphql.schema.GraphQLObjectType) Field(org.codice.ddf.admin.api.Field) Logger(org.slf4j.Logger) ObjectField(org.codice.ddf.admin.api.fields.ObjectField) GraphQLNonNull(graphql.schema.GraphQLNonNull) Set(java.util.Set) GraphQLInputType(graphql.schema.GraphQLInputType) GraphQLOutputType(graphql.schema.GraphQLOutputType) Collectors(java.util.stream.Collectors) GraphQLArgument(graphql.schema.GraphQLArgument) List(java.util.List) GraphQLList(graphql.schema.GraphQLList) GraphQLTypeReference(graphql.schema.GraphQLTypeReference) ListField(org.codice.ddf.admin.api.fields.ListField) Optional(java.util.Optional) FieldProvider(org.codice.ddf.admin.api.FieldProvider) ArrayList(java.util.ArrayList) DataType(org.codice.ddf.admin.api.DataType) GraphQLArgument(graphql.schema.GraphQLArgument)

Aggregations

DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)2 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)2 DataType (org.codice.ddf.admin.api.DataType)2 FunctionReport (org.codice.ddf.admin.api.report.FunctionReport)2 Lists (com.google.common.collect.Lists)1 ExceptionWhileDataFetching (graphql.ExceptionWhileDataFetching)1 Scalars (graphql.Scalars)1 GraphQLArgument (graphql.schema.GraphQLArgument)1 GraphQLInputType (graphql.schema.GraphQLInputType)1 GraphQLList (graphql.schema.GraphQLList)1 GraphQLNonNull (graphql.schema.GraphQLNonNull)1 GraphQLObjectType (graphql.schema.GraphQLObjectType)1 GraphQLOutputType (graphql.schema.GraphQLOutputType)1 GraphQLScalarType (graphql.schema.GraphQLScalarType)1 GraphQLTypeReference (graphql.schema.GraphQLTypeReference)1 GraphQLUnionType (graphql.schema.GraphQLUnionType)1 TypeResolver (graphql.schema.TypeResolver)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1