use of graphql.execution.FieldCollector 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);
}
}
}
Aggregations