Skip to content

Commit

Permalink
replace LinkedHashMap with Map in NadelDirectives
Browse files Browse the repository at this point in the history
  • Loading branch information
sbarker2 committed Dec 15, 2023
1 parent 7537711 commit 27557a6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package graphql.nadel.dsl


data class WhenConditionDefinition(
val result: WhenConditionResultDefinition
)
Expand Down
47 changes: 21 additions & 26 deletions lib/src/main/java/graphql/nadel/schema/NadelDirectives.kt
Original file line number Diff line number Diff line change
Expand Up @@ -210,29 +210,6 @@ object NadelDirectives {
) on ENUM_VALUE
""".trimIndent(),
)


private fun buildConditionalHydrationObject(whenConditionArgument: GraphQLAppliedDirectiveArgument): WhenConditionDefinition? {

val result = whenConditionArgument.getValue<LinkedHashMap<String, LinkedHashMap<String, Any>>>()?.get("result")
if (result == null){
return null
}
val sourceField = result["sourceField"]!! as String
val predicate: LinkedHashMap<String, Any> = result["predicate"]!! as LinkedHashMap<String, Any>

return WhenConditionDefinition(
result = WhenConditionResultDefinition(
sourceField = sourceField,
predicate = WhenConditionPredicateDefinition(
equals = predicate.get("equals"),
startsWith = predicate.get("startsWith") as String?,
matches = (predicate.get("matches")as String?)?.toRegex()
)
)
)

}
fun createUnderlyingServiceHydration(
fieldDefinition: GraphQLFieldDefinition,
overallSchema: GraphQLSchema,
Expand All @@ -247,9 +224,6 @@ object NadelDirectives {

val conditionalHydration = buildConditionalHydrationObject(directive.getArgument("when"))?.result

// directive.getArgument("when")
// .getValue<LinkedHashMap<String, LinkedHashMap<String, Any>>>()?.get("result")

buildHydrationParameters(directive, arguments, identifiedBy, conditionalHydration)
}

Expand Down Expand Up @@ -475,6 +449,27 @@ object NadelDirectives {
) as T
}

private fun buildConditionalHydrationObject(whenConditionArgument: GraphQLAppliedDirectiveArgument): WhenConditionDefinition? {

val result = whenConditionArgument.getValue<Map<String, Map<String, Any>>>()?.get("result")
if (result == null){
return null
}
val sourceField = result["sourceField"]!! as String
val predicate: Map<String, Any> = result["predicate"]!! as Map<String, Any>

return WhenConditionDefinition(
result = WhenConditionResultDefinition(
sourceField = sourceField,
predicate = WhenConditionPredicateDefinition(
equals = predicate.get("equals"),
startsWith = predicate.get("startsWith") as String?,
matches = (predicate.get("matches")as String?)?.toRegex()
)
)
)
}

private inline fun <reified T : SDLDefinition<*>> parseDefinition(sdl: String): T {
return Parser.parse(sdl).definitions.singleOfType()
}
Expand Down

0 comments on commit 27557a6

Please sign in to comment.