@@ -19,10 +19,15 @@ let QueryType =
1919 )
2020
2121type Input = {
22- File : Stream
23- File2 : Stream option
22+ File : FileData
23+ File2 : FileData option
2424}
2525
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+
2631let InputObject = Define.InputObject< Input>(
2732 name = " Input" ,
2833 fields =
@@ -37,21 +42,18 @@ let MutationType =
3742 fields =
3843 [ Define.Field ( " uploadFile" , StringType, " " , [ Define.Input ( " input" , FileType) ],
3944 ( 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
4347 ));
4448 Define.Field ( " uploadFileComplex" , StringType, " " , [ Define.Input ( " input" , InputObject) ],
4549 ( fun ctx () ->
4650 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
5053 | Some file2 ->
51- let reader2 = new StreamReader( file2, Encoding.UTF8, true )
52- reader2.ReadToEnd()
54+ getFullInfo file2
5355 | None -> " "
54- fileContent + file2Content
56+ fileString + file2String
5557 ))
5658 ]
5759 )
@@ -80,7 +82,7 @@ let mutationComplexObjectWithTwoFiles = """mutation uploadFile () {
8082
8183[<Fact>]
8284let ``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 ]
8486 let result = execute mutationWithConstant
8587 ensureDirect result <| fun data errors ->
8688 empty errors
@@ -89,7 +91,7 @@ let ``File type: Must upload file as input scalar using inline string as a file
8991
9092[<Fact>]
9193let ``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 ]
9395 let jsonVariable = " \" fileKey\" " |> JsonDocument.Parse |> _. RootElement
9496 let variables = ImmutableDictionary< string, JsonElement>. Empty.Add ( " file" , jsonVariable)
9597 let result = executeWithVariables ( mutationWithVariable, variables)
@@ -100,7 +102,7 @@ let ``File type: Must upload a file as input scalar using a variable`` () =
100102
101103[<Fact>]
102104let ``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 ]
104106 let result = execute mutationComplexObject
105107 ensureDirect result <| fun data errors ->
106108 empty errors
@@ -109,7 +111,7 @@ let ``File type: Must upload a file as input object field using inline string a
109111
110112[<Fact>]
111113let ``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
113115 let expected = NameValueLookup.ofList [
114116 " uploadFileComplex" , expectedContent
115117 ]
0 commit comments