Skip to content

Commit fbef1e8

Browse files
authored
Revert "fix(aws-datastore): selection set for nested custom types (#730)" (#777)
This reverts commit c0134e1.
1 parent 25840d9 commit fbef1e8

File tree

20 files changed

+8
-1386
lines changed

20 files changed

+8
-1386
lines changed

aws-api-appsync/src/main/java/com/amplifyframework/api/aws/SelectionSet.java

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@
2424
import com.amplifyframework.api.graphql.QueryType;
2525
import com.amplifyframework.core.model.Model;
2626
import com.amplifyframework.core.model.ModelSchema;
27-
import com.amplifyframework.core.model.types.JavaFieldType;
2827
import com.amplifyframework.util.Empty;
2928
import com.amplifyframework.util.FieldFinder;
3029
import com.amplifyframework.util.Wrap;
3130

3231
import java.lang.reflect.Field;
3332
import java.lang.reflect.ParameterizedType;
3433
import java.util.ArrayList;
35-
import java.util.Collection;
3634
import java.util.Collections;
3735
import java.util.HashSet;
3836
import java.util.List;
@@ -225,7 +223,7 @@ private Set<SelectionSet> getModelFields(Class<? extends Model> clazz, int depth
225223
}
226224

227225
ModelSchema schema = ModelSchema.fromModelClass(clazz);
228-
for (Field field : FieldFinder.findModelFieldsIn(clazz)) {
226+
for (Field field : FieldFinder.findFieldsIn(clazz)) {
229227
String fieldName = field.getName();
230228
if (schema.getAssociations().containsKey(fieldName)) {
231229
if (List.class.isAssignableFrom(field.getType())) {
@@ -239,8 +237,6 @@ private Set<SelectionSet> getModelFields(Class<? extends Model> clazz, int depth
239237
Set<SelectionSet> fields = getModelFields((Class<Model>) field.getType(), depth - 1);
240238
result.add(new SelectionSet(fieldName, fields));
241239
}
242-
} else if (isCustomType(field)) {
243-
result.add(new SelectionSet(fieldName, getNestedCustomTypeFields(getClassForField(field))));
244240
} else {
245241
result.add(new SelectionSet(fieldName, null));
246242
}
@@ -250,57 +246,5 @@ private Set<SelectionSet> getModelFields(Class<? extends Model> clazz, int depth
250246
}
251247
return result;
252248
}
253-
254-
/**
255-
* We handle customType fields differently as DEPTH does not apply here.
256-
* @param clazz class we wish to build selection set for
257-
* @return
258-
*/
259-
private Set<SelectionSet> getNestedCustomTypeFields(Class<?> clazz) {
260-
Set<SelectionSet> result = new HashSet<>();
261-
for (Field field : FieldFinder.findAllFieldsIn(clazz)) {
262-
String fieldName = field.getName();
263-
if (isCustomType(field)) {
264-
result.add(new SelectionSet(fieldName, getNestedCustomTypeFields(getClassForField(field))));
265-
} else {
266-
result.add(new SelectionSet(fieldName, null));
267-
}
268-
}
269-
return result;
270-
}
271-
272-
/**
273-
* Helper to determine if field is a custom type. If custom types we need to build nested selection set.
274-
* @param field field we wish to check
275-
* @return
276-
*/
277-
private static boolean isCustomType(@NonNull Field field) {
278-
Class<?> cls = getClassForField(field);
279-
if (Model.class.isAssignableFrom(cls) || Enum.class.isAssignableFrom(cls)) {
280-
return false;
281-
}
282-
try {
283-
JavaFieldType.from(cls.getSimpleName());
284-
return false;
285-
} catch (IllegalArgumentException exception) {
286-
// if we get here then field is a custom type
287-
return true;
288-
}
289-
}
290-
291-
/**
292-
* Get the class of a field. If field is a collection, it returns the Generic type
293-
* @return
294-
*/
295-
static Class<?> getClassForField(Field field) {
296-
Class<?> typeClass;
297-
if (Collection.class.isAssignableFrom(field.getType())) {
298-
ParameterizedType listType = (ParameterizedType) field.getGenericType();
299-
typeClass = (Class) listType.getActualTypeArguments()[0];
300-
} else {
301-
typeClass = field.getType();
302-
}
303-
return typeClass;
304-
}
305249
}
306250
}

aws-api-appsync/src/main/java/com/amplifyframework/core/model/types/JavaFieldType.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,6 @@ public enum JavaFieldType {
6565
*/
6666
TIME(Temporal.Time.class.getSimpleName()),
6767

68-
/**
69-
* Represents the Timestamp data type.
70-
* Is not currently used by TypeConverter as AWS_TIMESTAMP is being stored as long.
71-
*/
72-
TIMESTAMP(Temporal.Timestamp.class.getSimpleName()),
73-
7468
/**
7569
* Represents the Enum type.
7670
*/

aws-api-appsync/src/test/java/com/amplifyframework/api/aws/SelectionSetTest.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.amplifyframework.AmplifyException;
1919
import com.amplifyframework.api.graphql.QueryType;
2020
import com.amplifyframework.testmodels.commentsblog.Post;
21-
import com.amplifyframework.testmodels.parenting.Parent;
2221
import com.amplifyframework.testutils.Resources;
2322

2423
import org.junit.Test;
@@ -42,18 +41,4 @@ public void selectionSetSerializesToExpectedValue() throws AmplifyException {
4241
.build();
4342
assertEquals(Resources.readAsString("selection-set-post.txt"), selectionSet.toString() + "\n");
4443
}
45-
46-
/**
47-
* Test that custom type selection set serialization works as expected.
48-
* @throws AmplifyException if a ModelSchema can't be derived from Post.class
49-
*/
50-
@Test
51-
public void nestedCustomTypeSelectionSetSerializesToExpectedValue() throws AmplifyException {
52-
SelectionSet selectionSet = SelectionSet.builder()
53-
.modelClass(Parent.class)
54-
.operation(QueryType.GET)
55-
.requestOptions(new DefaultGraphQLRequestOptions())
56-
.build();
57-
assertEquals(Resources.readAsString("selection-set-parent.txt"), selectionSet.toString() + "\n");
58-
}
5944
}

aws-api-appsync/src/test/resources/selection-set-parent.txt

Lines changed: 0 additions & 29 deletions
This file was deleted.

aws-datastore/src/androidTest/java/com/amplifyframework/datastore/storage/sqlite/SQLiteStorageCustomTypeTest.java

Lines changed: 0 additions & 124 deletions
This file was deleted.

aws-datastore/src/main/java/com/amplifyframework/datastore/storage/sqlite/SQLiteModelFieldTypeConverter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ public static Object convertRawValueToTarget(
9191
case LONG:
9292
case FLOAT:
9393
case STRING:
94-
case TIMESTAMP:
9594
// these types require no special treatment
9695
return value;
9796
case BOOLEAN:
@@ -159,7 +158,6 @@ public Object convertValueFromSource(
159158
case FLOAT:
160159
return cursor.getFloat(columnIndex);
161160
case LONG:
162-
case TIMESTAMP:
163161
return cursor.getLong(columnIndex);
164162
case DATE:
165163
return new Temporal.Date(valueAsString);

0 commit comments

Comments
 (0)