From bcd84c6185f76cc0b3dfc596ea3625d2bb28f4ec Mon Sep 17 00:00:00 2001 From: maxhov <14804474+maxhov@users.noreply.github.com> Date: Thu, 19 Dec 2024 15:33:42 +0100 Subject: [PATCH 1/3] Properly handle unmapped view types. --- .../graphql/GraphQLEntityViewSupport.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/integration/graphql/src/main/java/com/blazebit/persistence/integration/graphql/GraphQLEntityViewSupport.java b/integration/graphql/src/main/java/com/blazebit/persistence/integration/graphql/GraphQLEntityViewSupport.java index f760109ce5..5b26a4e3c3 100644 --- a/integration/graphql/src/main/java/com/blazebit/persistence/integration/graphql/GraphQLEntityViewSupport.java +++ b/integration/graphql/src/main/java/com/blazebit/persistence/integration/graphql/GraphQLEntityViewSupport.java @@ -235,11 +235,11 @@ public EntityViewSetting> 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) entityViewClass, dataFetchingEnvironment, elementRoot); + return createPaginatedSetting((Class) entityViewClass.getJavaType(), dataFetchingEnvironment, elementRoot); } /** @@ -265,11 +265,11 @@ public EntityViewSetting> 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) entityViewClass, dataFetchingEnvironment, elementRoot, extractKeysetPage(first, last, beforeCursor, afterCursor), first, last, offset); + return createPaginatedSetting((Class) entityViewClass.getJavaType(), dataFetchingEnvironment, elementRoot, extractKeysetPage(first, last, beforeCursor, afterCursor), first, last, offset); } /** @@ -372,11 +372,11 @@ public EntityViewSetting> createSetting(DataFetchingEn */ public EntityViewSetting> 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) entityViewClass, dataFetchingEnvironment, elementRoot); + return createSetting((Class) entityViewClass.getJavaType(), dataFetchingEnvironment, elementRoot); } public String getElementTypeName(DataFetchingEnvironment dataFetchingEnvironment, String elementRoot) { @@ -699,7 +699,11 @@ protected byte[] serializeCursor(int offset, int pageSize, Serializable[] tuple) * @return the entity view class or null */ 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(); } /** From b66ace0f227ba4848a7680518126d6428c7ce0cb Mon Sep 17 00:00:00 2001 From: maxhov <14804474+maxhov@users.noreply.github.com> Date: Thu, 19 Dec 2024 15:49:26 +0100 Subject: [PATCH 2/3] Properly handle unmapped view types. --- .../integration/graphql/GraphQLEntityViewSupport.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/integration/graphql/src/main/java/com/blazebit/persistence/integration/graphql/GraphQLEntityViewSupport.java b/integration/graphql/src/main/java/com/blazebit/persistence/integration/graphql/GraphQLEntityViewSupport.java index 5b26a4e3c3..f3b60356a4 100644 --- a/integration/graphql/src/main/java/com/blazebit/persistence/integration/graphql/GraphQLEntityViewSupport.java +++ b/integration/graphql/src/main/java/com/blazebit/persistence/integration/graphql/GraphQLEntityViewSupport.java @@ -640,7 +640,14 @@ public void applyFetches(DataFetchingEnvironment dataFetchingEnvironment, Entity } continue; } - String mappedFieldPart = typeNameToFieldMapping.get(typeName).get(fieldName); + + Map 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; From 508300dabe23e718d71bb83dc82b0839f9e11264 Mon Sep 17 00:00:00 2001 From: maxhov <14804474+maxhov@users.noreply.github.com> Date: Mon, 30 Dec 2024 09:15:59 +0100 Subject: [PATCH 3/3] Fix formatting issue --- .../integration/graphql/GraphQLEntityViewSupport.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/graphql/src/main/java/com/blazebit/persistence/integration/graphql/GraphQLEntityViewSupport.java b/integration/graphql/src/main/java/com/blazebit/persistence/integration/graphql/GraphQLEntityViewSupport.java index f3b60356a4..4eb0edb88e 100644 --- a/integration/graphql/src/main/java/com/blazebit/persistence/integration/graphql/GraphQLEntityViewSupport.java +++ b/integration/graphql/src/main/java/com/blazebit/persistence/integration/graphql/GraphQLEntityViewSupport.java @@ -647,7 +647,7 @@ public void applyFetches(DataFetchingEnvironment dataFetchingEnvironment, Entity "No type is registered for the name: " + typeName); } - String mappedFieldPart = typeMapping.get(fieldName); + 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;