Skip to content

Commit 3930e57

Browse files
committed
fix: return the actual MultipartFile instance on the provided Upload scalar
1 parent 98f1f29 commit 3930e57

File tree

1 file changed

+14
-4
lines changed
  • graphql-kotlin-toolkit-spring-boot/src/main/kotlin/com/auritylab/graphql/kotlin/toolkit/spring/provided

1 file changed

+14
-4
lines changed

graphql-kotlin-toolkit-spring-boot/src/main/kotlin/com/auritylab/graphql/kotlin/toolkit/spring/provided/ProvidedScalars.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.auritylab.graphql.kotlin.toolkit.spring.provided
22

33
import graphql.schema.Coercing
44
import graphql.schema.GraphQLScalarType
5+
import org.springframework.web.multipart.MultipartFile
56

67
object ProvidedScalars {
78
/**
@@ -11,10 +12,19 @@ object ProvidedScalars {
1112
val upload = GraphQLScalarType.newScalar()
1213
.name("Upload")
1314
.coercing(
14-
object : Coercing<String, String> {
15-
override fun parseValue(input: Any?): String = ""
16-
override fun parseLiteral(input: Any?): String = ""
17-
override fun serialize(dataFetcherResult: Any?): String = ""
15+
object : Coercing<MultipartFile, MultipartFile?> {
16+
override fun parseValue(input: Any?): MultipartFile? {
17+
// We can only parse if we got a MultipartFile.
18+
if (input is MultipartFile) {
19+
return input
20+
}
21+
22+
// By default return null.
23+
return null
24+
}
25+
26+
override fun parseLiteral(input: Any?): MultipartFile? = null
27+
override fun serialize(dataFetcherResult: Any?): MultipartFile? = null
1828
}
1929
).build()
2030
}

0 commit comments

Comments
 (0)