private Set getModelFields()

in aws-api-appsync/src/main/java/com/amplifyframework/api/aws/SelectionSet.java [255:304]


        private Set<SelectionSet> getModelFields(Class<? extends Model> clazz, int depth, Operation operation)
                throws AmplifyException {
            if (depth < 0) {
                return new HashSet<>();
            }

            Set<SelectionSet> result = new HashSet<>();

            if (depth == 0
                    && LeafSerializationBehavior.JUST_ID.equals(requestOptions.leafSerializationBehavior())
                    && operation != QueryType.SYNC
            ) {
                result.add(new SelectionSet("id"));
                return result;
            }

            ModelSchema schema = ModelSchema.fromModelClass(clazz);
            for (Field field : FieldFinder.findModelFieldsIn(clazz)) {
                String fieldName = field.getName();
                if (schema.getAssociations().containsKey(fieldName)) {
                    if (List.class.isAssignableFrom(field.getType())) {
                        if (depth >= 1) {
                            ParameterizedType listType = (ParameterizedType) field.getGenericType();
                            Class<Model> listTypeClass = (Class<Model>) listType.getActualTypeArguments()[0];
                            Set<SelectionSet> fields = wrapPagination(getModelFields(listTypeClass,
                                                                depth - 1,
                                                                operation));
                            result.add(new SelectionSet(fieldName, fields));
                        }
                    } else if (depth >= 1) {
                        Set<SelectionSet> fields = getModelFields((Class<Model>) field.getType(), depth - 1, operation);
                        result.add(new SelectionSet(fieldName, fields));
                    }
                } else if (isCustomType(field)) {
                    result.add(new SelectionSet(fieldName, getNestedCustomTypeFields(getClassForField(field))));
                } else {
                    result.add(new SelectionSet(fieldName));
                }
                for (AuthRule authRule : schema.getAuthRules()) {
                    if (AuthStrategy.OWNER.equals(authRule.getAuthStrategy())) {
                        result.add(new SelectionSet(authRule.getOwnerFieldOrDefault()));
                        break;
                    }
                }
            }
            for (String fieldName : requestOptions.modelMetaFields()) {
                result.add(new SelectionSet(fieldName));
            }
            return result;
        }