Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions tests/FSharp.Data.GraphQL.IntegrationTests.Server/Schema.fs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ type Input =
{ Single : InputField option
List : InputField list option }

type InputFile =
{ File : FileData }

type UploadedFile =
{ Name : string
ContentType : string
Expand Down Expand Up @@ -134,7 +137,7 @@ module Schema =
args = [ Define.Input("input", Nullable InputType, description = "The input to be echoed as an output.") ],
resolve = fun ctx _ -> ctx.TryArg("input")) ])

let InputFileObject = Define.InputObject<Input>(
let InputFileObject = Define.InputObject<InputFile>(
name = "InputFile",
fields =
[
Expand All @@ -146,7 +149,8 @@ module Schema =
use reader = new System.IO.StreamReader(stream, Encoding.UTF8)
reader.ReadToEnd()
let getFileContent (ctx : ResolveFieldContext) argName =
let stream = ctx.Arg<System.IO.Stream> argName
let inputFile = ctx.Arg<InputFile> argName
let stream = inputFile.File.Stream
use reader = new System.IO.StreamReader(stream, Encoding.UTF8, true)
reader.ReadToEnd()
let mapUploadToOutput (file : FileData) =
Expand Down
44 changes: 44 additions & 0 deletions tests/FSharp.Data.GraphQL.IntegrationTests/LocalProviderTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -487,3 +487,47 @@ let ``Should be able to upload files inside another input type``() : Task = task
let! result = UploadRequestOperation.operation.AsyncRun(input)
result |> UploadRequestOperation.validateResult request
}

module UploadComplexOperation =
let operation =
Provider.Operation<"""mutation UploadComplex($input: InputFile!) {
uploadComplex(input: $input)
}""">()

type Operation = Provider.Operations.UploadComplex
type InputFile = Provider.Types.InputFile

let validateResult (file : File) (result : Operation.OperationResult) =
result |> checkRequestTypeHeader "Multipart"
result.Data.IsSome |> equals true
result.Data.Value.UploadComplex |> equals file.Content

[<Fact>]
let ``Should be able to upload file using complex input object`` () =
let file = { Name = "complex.txt"; ContentType = "text/plain"; Content = "Complex input object file content" }
let input = UploadComplexOperation.InputFile(file = file.MakeUpload())
Copy link

Copilot AI Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use F# class initializer syntax instead of property assignment. The code should be: UploadComplexOperation.InputFile(file = file.MakeUpload()) which is already correct, but ensure this pattern is consistently followed throughout.

Copilot generated this review using guidance from repository custom instructions.
UploadComplexOperation.operation.Run(input)
|> UploadComplexOperation.validateResult file

[<Fact>]
let ``Should be able to upload file using complex input object with context`` () =
let file = { Name = "complex_context.txt"; ContentType = "text/plain"; Content = "Complex input with context file content" }
let input = UploadComplexOperation.InputFile(file = file.MakeUpload())
UploadComplexOperation.operation.Run(context, input)
|> UploadComplexOperation.validateResult file

[<Fact>]
let ``Should be able to upload file using complex input object asynchronously`` () : Task = task {
let file = { Name = "complex_async.txt"; ContentType = "text/plain"; Content = "Complex input object async file content" }
let input = UploadComplexOperation.InputFile(file = file.MakeUpload())
let! result = UploadComplexOperation.operation.AsyncRun(input)
result |> UploadComplexOperation.validateResult file
}

[<Fact>]
let ``Should be able to upload file using complex input object with context asynchronously`` () : Task = task {
let file = { Name = "complex_context_async.txt"; ContentType = "text/plain"; Content = "Complex input with context async file content" }
let input = UploadComplexOperation.InputFile(file = file.MakeUpload())
let! result = UploadComplexOperation.operation.AsyncRun(context, input)
result |> UploadComplexOperation.validateResult file
}
Original file line number Diff line number Diff line change
Expand Up @@ -484,3 +484,47 @@ let ``Should be able to upload files inside another input type``() =
nullableMultipleNullable = Some (Array.map (Option.map makeUpload) request.NullableMultipleNullable.Value))
UploadRequestOperation.operation.Run(input)
|> UploadRequestOperation.validateResult request

module UploadComplexOperation =
let operation =
Provider.Operation<"""mutation UploadComplex($input: InputFile!) {
uploadComplex(input: $input)
}""">()

type Operation = Provider.Operations.UploadComplex
type InputFile = Provider.Types.InputFile

let validateResult (file : File) (result : Operation.OperationResult) =
result |> checkRequestTypeHeader "Multipart"
result.Data.IsSome |> equals true
result.Data.Value.UploadComplex |> equals file.Content

[<Fact>]
let ``Should be able to upload file using complex input object`` () =
let file = { Name = "complex.txt"; ContentType = "text/plain"; Content = "Complex input object file content" }
let input = UploadComplexOperation.InputFile(file = file.MakeUpload())
Copy link

Copilot AI Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use F# class initializer syntax instead of property assignment. The code should be: UploadComplexOperation.InputFile(file = file.MakeUpload()) which is already correct, but ensure this pattern is consistently followed throughout.

Copilot generated this review using guidance from repository custom instructions.
UploadComplexOperation.operation.Run(input)
|> UploadComplexOperation.validateResult file

[<Fact>]
let ``Should be able to upload file using complex input object with context`` () =
let file = { Name = "complex_context.txt"; ContentType = "text/plain"; Content = "Complex input with context file content" }
let input = UploadComplexOperation.InputFile(file = file.MakeUpload())
UploadComplexOperation.operation.Run(context, input)
|> UploadComplexOperation.validateResult file

[<Fact>]
let ``Should be able to upload file using complex input object asynchronously`` () : Task = task {
let file = { Name = "complex_async.txt"; ContentType = "text/plain"; Content = "Complex input object async file content" }
let input = UploadComplexOperation.InputFile(file = file.MakeUpload())
let! result = UploadComplexOperation.operation.AsyncRun(input)
result |> UploadComplexOperation.validateResult file
}

[<Fact>]
let ``Should be able to upload file using complex input object with context asynchronously`` () : Task = task {
let file = { Name = "complex_context_async.txt"; ContentType = "text/plain"; Content = "Complex input with context async file content" }
let input = UploadComplexOperation.InputFile(file = file.MakeUpload())
let! result = UploadComplexOperation.operation.AsyncRun(context, input)
result |> UploadComplexOperation.validateResult file
}