Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aws-api-appsync): update getModelFields for flutter support #1611

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public SelectionSet build() throws AmplifyException {
Objects.requireNonNull(this.operation);
SelectionSet node = new SelectionSet(null,
SerializedModel.class == modelClass
? getModelFields(modelSchema, requestOptions.maxDepth())
? getModelFields(modelSchema, requestOptions.maxDepth(), operation)
: getModelFields(modelClass, requestOptions.maxDepth(), operation));
if (QueryType.LIST.equals(operation) || QueryType.SYNC.equals(operation)) {
node = wrapPagination(node);
Expand Down Expand Up @@ -243,7 +243,7 @@ private Set<SelectionSet> wrapPagination(Set<SelectionSet> nodes) {

/**
* Gets a selection set for the given class.
* TODO: this is mostly duplicative of {@link #getModelFields(ModelSchema, int)}.
* TODO: this is mostly duplicative of {@link #getModelFields(ModelSchema, int, Operation)}.
* Long-term, we want to remove this current method and rely only on the ModelSchema-based
* version.
* @param clazz Class from which to build selection set
Expand Down Expand Up @@ -357,12 +357,16 @@ static Class<?> getClassForField(Field field) {

// TODO: this method is tech debt. We added it to support usage of the library from Flutter.
// This version of the method needs to be unified with getModelFields(Class<? extends Model> clazz, int depth).
private Set<SelectionSet> getModelFields(ModelSchema modelSchema, int depth) {
private Set<SelectionSet> getModelFields(ModelSchema modelSchema, int depth, Operation operation) {
if (depth < 0) {
return new HashSet<>();
}
Set<SelectionSet> result = new HashSet<>();
if (depth == 0 && LeafSerializationBehavior.JUST_ID.equals(requestOptions.leafSerializationBehavior())) {
if (
depth == 0
&& LeafSerializationBehavior.JUST_ID.equals(requestOptions.leafSerializationBehavior())
&& operation != QueryType.SYNC
) {
result.add(new SelectionSet("id"));
return result;
}
Expand All @@ -379,9 +383,9 @@ private Set<SelectionSet> getModelFields(ModelSchema modelSchema, int depth) {
modelSchemas.getModelSchemaForModelClass(associatedModelName);
Set<SelectionSet> fields;
if (entry.getValue().isArray()) { // If modelField is an Array
fields = wrapPagination(getModelFields(associateModelSchema, depth - 1));
fields = wrapPagination(getModelFields(associateModelSchema, depth - 1, operation));
} else {
fields = getModelFields(associateModelSchema, depth - 1);
fields = getModelFields(associateModelSchema, depth - 1, operation);
}
result.add(new SelectionSet(fieldName, fields));
}
Expand Down