Search in sources :

Example 1 with ValuesResolver

use of graphql.execution.ValuesResolver in project graphql-java by graphql-java.

the class DataFetchingFieldSelectionSetImpl method traverseFields.

private void traverseFields(List<Field> fieldList, GraphQLFieldsContainer parentFieldType, String fieldPrefix) {
    FieldCollector fieldCollector = new FieldCollector();
    ValuesResolver valuesResolver = new ValuesResolver();
    FieldCollectorParameters parameters = FieldCollectorParameters.newParameters().schema(graphQLSchema).objectType(asObjectTypeOrNull(parentFieldType)).fragments(fragmentsByName).variables(variables).build();
    Map<String, List<Field>> collectedFields = fieldCollector.collectFields(parameters, fieldList);
    for (Map.Entry<String, List<Field>> entry : collectedFields.entrySet()) {
        String fieldName = mkFieldName(fieldPrefix, entry.getKey());
        List<Field> collectedFieldList = entry.getValue();
        selectionSetFields.put(fieldName, collectedFieldList);
        Field field = collectedFieldList.get(0);
        GraphQLFieldDefinition fieldDef = Introspection.getFieldDef(graphQLSchema, (GraphQLCompositeType) parentFieldType, field.getName());
        GraphQLType unwrappedType = ExecutionTypeInfo.unwrapBaseType(fieldDef.getType());
        Map<String, Object> argumentValues = valuesResolver.getArgumentValues(fieldDef.getArguments(), field.getArguments(), variables);
        selectionSetFieldArgs.put(fieldName, argumentValues);
        selectionSetFieldDefinitions.put(fieldName, fieldDef);
        flattenedFields.add(fieldName);
        if (unwrappedType instanceof GraphQLFieldsContainer) {
            traverseFields(collectedFieldList, (GraphQLFieldsContainer) unwrappedType, fieldName);
        }
    }
}
Also used : FieldCollector(graphql.execution.FieldCollector) ValuesResolver(graphql.execution.ValuesResolver) Field(graphql.language.Field) FieldCollectorParameters(graphql.execution.FieldCollectorParameters) List(java.util.List) Collections.emptyMap(java.util.Collections.emptyMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

FieldCollector (graphql.execution.FieldCollector)1 FieldCollectorParameters (graphql.execution.FieldCollectorParameters)1 ValuesResolver (graphql.execution.ValuesResolver)1 Field (graphql.language.Field)1 Collections.emptyMap (java.util.Collections.emptyMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1