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

[#1973] Properly handle unmapped view types in GraphQLEntityViewSupport #1974

Merged
merged 3 commits into from
Jan 7, 2025
Merged
Changes from all commits
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 @@ -235,11 +235,11 @@ public <T> EntityViewSetting<T, PaginatedCriteriaBuilder<T>> createPaginatedSett
objectRoot = elementRoot + "/" + pageElementObjectName;
}
String typeName = getElementTypeName(dataFetchingEnvironment, objectRoot);
Class<?> entityViewClass = typeNameToViewType.get(typeName).getJavaType();
ManagedViewType<?> entityViewClass = typeNameToViewType.get(typeName);
if (entityViewClass == null) {
throw new IllegalArgumentException("No entity view type is registered for the name: " + typeName);
}
return createPaginatedSetting((Class<T>) entityViewClass, dataFetchingEnvironment, elementRoot);
return createPaginatedSetting((Class<T>) entityViewClass.getJavaType(), dataFetchingEnvironment, elementRoot);
}

/**
Expand All @@ -265,11 +265,11 @@ public <T> EntityViewSetting<T, PaginatedCriteriaBuilder<T>> createPaginatedSett
objectRoot = elementRoot + "/" + pageElementObjectName;
}
String typeName = getElementTypeName(dataFetchingEnvironment, objectRoot);
Class<?> entityViewClass = typeNameToViewType.get(typeName).getJavaType();
ManagedViewType<?> entityViewClass = typeNameToViewType.get(typeName);
if (entityViewClass == null) {
throw new IllegalArgumentException("No entity view type is registered for the name: " + typeName);
}
return createPaginatedSetting((Class<T>) entityViewClass, dataFetchingEnvironment, elementRoot, extractKeysetPage(first, last, beforeCursor, afterCursor), first, last, offset);
return createPaginatedSetting((Class<T>) entityViewClass.getJavaType(), dataFetchingEnvironment, elementRoot, extractKeysetPage(first, last, beforeCursor, afterCursor), first, last, offset);
}

/**
Expand Down Expand Up @@ -372,11 +372,11 @@ public <T> EntityViewSetting<T, CriteriaBuilder<T>> createSetting(DataFetchingEn
*/
public <T> EntityViewSetting<T, CriteriaBuilder<T>> createSetting(DataFetchingEnvironment dataFetchingEnvironment, String elementRoot) {
String typeName = getElementTypeName(dataFetchingEnvironment, elementRoot);
Class<?> entityViewClass = typeNameToViewType.get(typeName).getJavaType();
ManagedViewType<?> entityViewClass = typeNameToViewType.get(typeName);
if (entityViewClass == null) {
throw new IllegalArgumentException("No entity view type is registered for the name: " + typeName);
}
return createSetting((Class<T>) entityViewClass, dataFetchingEnvironment, elementRoot);
return createSetting((Class<T>) entityViewClass.getJavaType(), dataFetchingEnvironment, elementRoot);
}

public String getElementTypeName(DataFetchingEnvironment dataFetchingEnvironment, String elementRoot) {
Expand Down Expand Up @@ -640,7 +640,14 @@ public void applyFetches(DataFetchingEnvironment dataFetchingEnvironment, Entity
}
continue;
}
String mappedFieldPart = typeNameToFieldMapping.get(typeName).get(fieldName);

Map<String, String> typeMapping = typeNameToFieldMapping.get(typeName);
if (typeMapping == null) {
throw new IllegalArgumentException(
"No type is registered for the name: " + typeName);
}

String mappedFieldPart = typeMapping.get(fieldName);
if (mappedFieldPart == null) {
// fieldName cannot be mapped to an entity view field, probably because it's a non-DB field with a default -> ignore the whole field
continue OUTER;
Expand Down Expand Up @@ -699,7 +706,11 @@ protected byte[] serializeCursor(int offset, int pageSize, Serializable[] tuple)
* @return the entity view class or <code>null</code>
*/
public Class<?> getEntityViewClass(String typeName) {
return typeNameToViewType.get(typeName).getJavaType();
ManagedViewType<?> entityViewClass = typeNameToViewType.get(typeName);
if (entityViewClass == null) {
throw new IllegalArgumentException("No entity view type is registered for the name: " + typeName);
}
return entityViewClass.getJavaType();
}

/**
Expand Down
Loading