@@ -19,10 +19,15 @@ let QueryType =
19
19
)
20
20
21
21
type Input = {
22
- File : Stream
23
- File2 : Stream option
22
+ File : FileData
23
+ File2 : FileData option
24
24
}
25
25
26
+ let private getFullInfo fileData =
27
+ use reader = new StreamReader( fileData.Stream, Encoding.UTF8, true )
28
+ let fileContent = reader.ReadToEnd()
29
+ fileContent + fileData.ContentType
30
+
26
31
let InputObject = Define.InputObject< Input>(
27
32
name = " Input" ,
28
33
fields =
@@ -37,21 +42,18 @@ let MutationType =
37
42
fields =
38
43
[ Define.Field ( " uploadFile" , StringType, " " , [ Define.Input ( " input" , FileType) ],
39
44
( fun ctx () ->
40
- let stream = ctx.Arg< Stream> " input"
41
- use reader = new StreamReader( stream, Encoding.UTF8, true )
42
- reader.ReadToEnd()
45
+ let fileData = ctx.Arg< FileData> " input"
46
+ getFullInfo fileData
43
47
));
44
48
Define.Field ( " uploadFileComplex" , StringType, " " , [ Define.Input ( " input" , InputObject) ],
45
49
( fun ctx () ->
46
50
let input = ctx.Arg< Input> " input"
47
- let reader = new StreamReader( input.File, Encoding.UTF8, true )
48
- let fileContent = reader.ReadToEnd()
49
- let file2Content = match input.File2 with
51
+ let fileString = getFullInfo input.File
52
+ let file2String = match input.File2 with
50
53
| Some file2 ->
51
- let reader2 = new StreamReader( file2, Encoding.UTF8, true )
52
- reader2.ReadToEnd()
54
+ getFullInfo file2
53
55
| None -> " "
54
- fileContent + file2Content
56
+ fileString + file2String
55
57
))
56
58
]
57
59
)
@@ -80,7 +82,7 @@ let mutationComplexObjectWithTwoFiles = """mutation uploadFile () {
80
82
81
83
[<Fact>]
82
84
let ``File type : Must upload file as input scalar using inline string as a file name`` () =
83
- let expected = NameValueLookup.ofList [ " uploadFile" , MockInputContext.mockFileText ]
85
+ let expected = NameValueLookup.ofList [ " uploadFile" , MockInputContext.mockFileTextAndContentType ]
84
86
let result = execute mutationWithConstant
85
87
ensureDirect result <| fun data errors ->
86
88
empty errors
@@ -89,7 +91,7 @@ let ``File type: Must upload file as input scalar using inline string as a file
89
91
90
92
[<Fact>]
91
93
let ``File type : Must upload a file as input scalar using a variable`` () =
92
- let expected = NameValueLookup.ofList [ " uploadFile" , MockInputContext.mockFileText ]
94
+ let expected = NameValueLookup.ofList [ " uploadFile" , MockInputContext.mockFileTextAndContentType ]
93
95
let jsonVariable = " \" fileKey\" " |> JsonDocument.Parse |> _. RootElement
94
96
let variables = ImmutableDictionary< string, JsonElement>. Empty.Add ( " file" , jsonVariable)
95
97
let result = executeWithVariables ( mutationWithVariable, variables)
@@ -100,7 +102,7 @@ let ``File type: Must upload a file as input scalar using a variable`` () =
100
102
101
103
[<Fact>]
102
104
let ``File type : Must upload a file as input object field using inline string a file name`` () =
103
- let expected = NameValueLookup.ofList [ " uploadFileComplex" , MockInputContext.mockFileText ]
105
+ let expected = NameValueLookup.ofList [ " uploadFileComplex" , MockInputContext.mockFileTextAndContentType ]
104
106
let result = execute mutationComplexObject
105
107
ensureDirect result <| fun data errors ->
106
108
empty errors
@@ -109,7 +111,7 @@ let ``File type: Must upload a file as input object field using inline string a
109
111
110
112
[<Fact>]
111
113
let ``File type : Must upload two files as input object field using inline string a file name`` () =
112
- let expectedContent = MockInputContext.mockFileText + MockInputContext.mockFileText2
114
+ let expectedContent = MockInputContext.mockFileTextAndContentType + MockInputContext.mockFileText2AndContentType
113
115
let expected = NameValueLookup.ofList [
114
116
" uploadFileComplex" , expectedContent
115
117
]
0 commit comments