From 5f5eff4c6fd67758bd169f34093c3b7bed414fac Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Sun, 17 May 2026 19:49:59 +0200 Subject: [PATCH 1/9] Migrate integration tests to in-process hosts via `WebApplicationFactory` and remove external server orchestration from build (#564) Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Andrii Chebukin --- FSharp.Data.GraphQL.Integration.slnx | 5 + Packages.props | 1 + build/Program.fs | 72 +- .../star-wars-fabulous-client/StarWars.slnx | 6 + .../StarWars/Common.fs | 5 +- .../StarWars/StarWars.fsproj | 20 +- ...Sharp.Data.GraphQL.IntegrationTests.fsproj | 17 +- .../IntrospectionUpdateTests.fs | 90 + .../LocalProviderTests.fs | 69 +- ...ProviderWithOptionalParametersOnlyTests.fs | 69 +- .../OperationErrorTests.fs | 9 +- .../SwapiLocalProviderTests.fs | 5 +- .../SwapiRemoteProviderTests.fs | 69 +- .../TestHosts.fs | 43 + .../integration-introspection.json | 1929 +++++++++++++++++ .../introspection.json | 2 +- 16 files changed, 2240 insertions(+), 171 deletions(-) create mode 100644 tests/FSharp.Data.GraphQL.IntegrationTests/IntrospectionUpdateTests.fs create mode 100644 tests/FSharp.Data.GraphQL.IntegrationTests/TestHosts.fs create mode 100644 tests/FSharp.Data.GraphQL.IntegrationTests/integration-introspection.json diff --git a/FSharp.Data.GraphQL.Integration.slnx b/FSharp.Data.GraphQL.Integration.slnx index ebd077769..b8e081034 100644 --- a/FSharp.Data.GraphQL.Integration.slnx +++ b/FSharp.Data.GraphQL.Integration.slnx @@ -4,6 +4,9 @@ + + + @@ -12,7 +15,9 @@ + + diff --git a/Packages.props b/Packages.props index 7d3b9582b..323f603f2 100644 --- a/Packages.props +++ b/Packages.props @@ -76,6 +76,7 @@ + diff --git a/build/Program.fs b/build/Program.fs index 22bbb133c..f23d68415 100644 --- a/build/Program.fs +++ b/build/Program.fs @@ -2,8 +2,6 @@ module Program open System open System.IO -open System.Net.Http -open System.Text.Json open Fake.Core open Fake.Core.TargetOperators @@ -123,26 +121,6 @@ let runTests (project : string) (args : string) = |> _.WithCommon(DotNetCli.setVersion)) project -let starWarsServerStream = StreamRef.Empty - -let [] StartStarWarsServerTarget = "StartStarWarsServer" -Target.create StartStarWarsServerTarget <| fun _ -> - Target.activateFinal "StopStarWarsServer" - - let project = - "samples" - "star-wars-api" - "star-wars-api.fsproj" - - startGraphQLServer project 8086 starWarsServerStream - -let [] StopStarWarsServerTarget = "StopStarWarsServer" -Target.createFinal StopStarWarsServerTarget <| fun _ -> - try - starWarsServerStream.Value.Write ([| 0uy |], 0, 1) - with e -> - printfn "%s" e.Message - let integrationTestServerProjectPath = "tests" "FSharp.Data.GraphQL.IntegrationTests.Server" @@ -179,58 +157,35 @@ Target.createFinal StopIntegrationServerTarget <| fun _ -> with e -> printfn "%s" e.Message -let [] UpdateIntrospectionFileTarget = "UpdateIntrospectionFile" -Target.create UpdateIntrospectionFileTarget <| fun _ -> - let client = new HttpClient () - (task { - let! result = client.GetAsync ("http://localhost:8086") - let! contentStream = result.Content.ReadAsStreamAsync () - let! jsonDocument = JsonDocument.ParseAsync contentStream - let file = - new FileStream ("tests/FSharp.Data.GraphQL.IntegrationTests/introspection.json", FileMode.Create, FileAccess.Write, FileShare.None) - let encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping - let jsonWriterOptions = JsonWriterOptions (Indented = true, Encoder = encoder) - let writer = new Utf8JsonWriter (file, jsonWriterOptions) - jsonDocument.WriteTo writer - do! writer.FlushAsync () - do! writer.DisposeAsync () - do! file.DisposeAsync () - result.Dispose () - }) - .Wait () - client.Dispose () - -let unitTestsProjectPath = - "tests" - "FSharp.Data.GraphQL.Tests" - "FSharp.Data.GraphQL.Tests.fsproj" - let integrationTestsProjectPath = "tests" "FSharp.Data.GraphQL.IntegrationTests" "FSharp.Data.GraphQL.IntegrationTests.fsproj" -let [] BuildIntegrationTestsTarget = "BuildIntegrationTests" -Target.create BuildIntegrationTestsTarget <| fun _ -> +let [] UpdateIntrospectionFileTarget = "UpdateIntrospectionFile" +Target.create UpdateIntrospectionFileTarget <| fun _ -> integrationTestsProjectPath - |> DotNet.build (fun options -> { + |> DotNet.test (fun options -> { options with + Framework = Some DotNetMoniker Configuration = configuration + Common = { DotNetCli.setVersion options.Common with CustomParams = Some "--filter FullyQualifiedName~IntrospectionUpdateTests" } MSBuildParams = { options.MSBuildParams with DisableInternalBinLog = true + Verbosity = Some Normal } - Common = DotNetCli.setVersion options.Common }) +let unitTestsProjectPath = + "tests" + "FSharp.Data.GraphQL.Tests" + "FSharp.Data.GraphQL.Tests.fsproj" + let [] RunUnitTestsTarget = "RunUnitTests" Target.create RunUnitTestsTarget <| fun _ -> runTests unitTestsProjectPath "" -let [] RunIntegrationTestsTarget = "RunIntegrationTests" -Target.create RunIntegrationTestsTarget <| fun _ -> - runTests integrationTestsProjectPath "" //"--filter Execution=Sync" - let prepareDocGen () = Shell.rm "docs/release-notes.md" Shell.cp "RELEASE_NOTES.md" "docs/RELEASE_NOTES.md" @@ -406,12 +361,7 @@ Target.create "PackAndPush" ignore ==> RestoreTarget ==> BuildTarget ==> RunUnitTestsTarget -==> StartStarWarsServerTarget -==> BuildIntegrationTestServerTarget -==> StartIntegrationServerTarget ==> UpdateIntrospectionFileTarget -==> BuildIntegrationTestsTarget -==> RunIntegrationTestsTarget ==> "All" =?> (GenerateDocsTarget, Environment.environVar "GITHUB_ACTIONS" = "True") |> ignore diff --git a/samples/star-wars-fabulous-client/StarWars.slnx b/samples/star-wars-fabulous-client/StarWars.slnx index 51d68264a..52cff01ec 100644 --- a/samples/star-wars-fabulous-client/StarWars.slnx +++ b/samples/star-wars-fabulous-client/StarWars.slnx @@ -14,6 +14,12 @@ + + + + + + diff --git a/samples/star-wars-fabulous-client/StarWars/Common.fs b/samples/star-wars-fabulous-client/StarWars/Common.fs index 3974e6c92..1de5ae4e9 100644 --- a/samples/star-wars-fabulous-client/StarWars/Common.fs +++ b/samples/star-wars-fabulous-client/StarWars/Common.fs @@ -5,7 +5,10 @@ open FSharp.Data.GraphQL module Commands = - type GraphQLApi = GraphQLProvider<"http://localhost:8086"> + [] + let IntrospectionPath = "../../../tests/FSharp.Data.GraphQL.IntegrationTests/introspection.json" + + type GraphQLApi = GraphQLProvider let GetCharactersData = GraphQLApi.Operation<"queries/FetchCharacters.graphql">() type Character = GraphQLApi.Operations.FetchCharacters.Types.CharactersFields.Character diff --git a/samples/star-wars-fabulous-client/StarWars/StarWars.fsproj b/samples/star-wars-fabulous-client/StarWars/StarWars.fsproj index d972d6d59..4769849ad 100644 --- a/samples/star-wars-fabulous-client/StarWars/StarWars.fsproj +++ b/samples/star-wars-fabulous-client/StarWars/StarWars.fsproj @@ -4,7 +4,7 @@ false - + @@ -18,16 +18,16 @@ - - - - - - - - + + + + + + + + - \ No newline at end of file + diff --git a/tests/FSharp.Data.GraphQL.IntegrationTests/FSharp.Data.GraphQL.IntegrationTests.fsproj b/tests/FSharp.Data.GraphQL.IntegrationTests/FSharp.Data.GraphQL.IntegrationTests.fsproj index f133dee2a..5d7e2d004 100644 --- a/tests/FSharp.Data.GraphQL.IntegrationTests/FSharp.Data.GraphQL.IntegrationTests.fsproj +++ b/tests/FSharp.Data.GraphQL.IntegrationTests/FSharp.Data.GraphQL.IntegrationTests.fsproj @@ -7,6 +7,7 @@ + @@ -15,6 +16,7 @@ + @@ -22,7 +24,9 @@ + + @@ -30,16 +34,19 @@ + + + + + - ..\..\src\FSharp.Data.GraphQL.Client\bin\Debug\netstandard2.0\FSharp.Data.GraphQL.Client.dll - ..\..\src\FSharp.Data.GraphQL.Client\bin\Release\netstandard2.0\FSharp.Data.GraphQL.Client.dll + ..\..\src\FSharp.Data.GraphQL.Client\bin\$(Configuration)\netstandard2.0\FSharp.Data.GraphQL.Client.dll ..\..\bin\FSharp.Data.GraphQL.Client\netstandard2.0\FSharp.Data.GraphQL.Client.dll - ..\..\src\FSharp.Data.GraphQL.Client\bin\Debug\netstandard2.0\FSharp.Data.GraphQL.Shared.dll - ..\..\src\FSharp.Data.GraphQL.Client\bin\Release\netstandard2.0\FSharp.Data.GraphQL.Shared.dll - ..\..\bin\FSharp.Data.GraphQL.Client\netstandard2.0\FSharp.Data.GraphQL.Shared.dll + ..\..\src\FSharp.Data.GraphQL.Shared\bin\$(Configuration)\net10.0\FSharp.Data.GraphQL.Shared.dll + ..\..\bin\FSharp.Data.GraphQL.Shared\net10.0\FSharp.Data.GraphQL.Shared.dll diff --git a/tests/FSharp.Data.GraphQL.IntegrationTests/IntrospectionUpdateTests.fs b/tests/FSharp.Data.GraphQL.IntegrationTests/IntrospectionUpdateTests.fs new file mode 100644 index 000000000..80a23c5ce --- /dev/null +++ b/tests/FSharp.Data.GraphQL.IntegrationTests/IntrospectionUpdateTests.fs @@ -0,0 +1,90 @@ +module FSharp.Data.GraphQL.IntegrationTests.IntrospectionUpdateTests + +open System +open System.IO +open System.Net.Http.Json +open System.Text.Json +open System.Threading +open Xunit + +let introspectionFilePath = + Path.Combine (__SOURCE_DIRECTORY__, "integration-introspection.json") + |> Path.GetFullPath + +let normalizeJsonDocument options (document : JsonDocument) = + use buffer = new MemoryStream () + use writer = new Utf8JsonWriter (buffer, options) + document.WriteTo writer + writer.Flush () + buffer.Seek (0L, SeekOrigin.Begin) |> ignore + JsonDocument.Parse buffer + +let parseAndNormalizeJsonAsync ct options stream = + task { + let! document = JsonDocument.ParseAsync (stream, cancellationToken = ct) + return normalizeJsonDocument options document + } + +let areSchemasEqual (document1 : JsonDocument) (document2 : JsonDocument) = + let schema1 = document1.RootElement.GetProperty("data").GetProperty("__schema") + let schema2 = document2.RootElement.GetProperty("data").GetProperty("__schema") + schema1.GetRawText() = schema2.GetRawText() + +let readDestinationDocumentAsync ct (stream : FileStream) = + task { + try + let! document = JsonDocument.ParseAsync (stream, cancellationToken = ct) + return ValueSome document + with :? JsonException -> + return ValueNone + } + +let updateIntrospectionFileAsync ct sourceStream = + task { + use destinationStream = + new FileStream (introspectionFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read) + + let options = JsonWriterOptions(Indented = true) + let! sourceDocument = parseAndNormalizeJsonAsync ct options sourceStream + destinationStream.Seek (0L, SeekOrigin.Begin) |> ignore + let! destinationDocument = readDestinationDocumentAsync ct destinationStream + + let shouldUpdate = + match destinationDocument with + | ValueNone -> true + | ValueSome document -> not (areSchemasEqual document sourceDocument) + + if shouldUpdate then + destinationStream.Seek (0L, SeekOrigin.Begin) |> ignore + destinationStream.SetLength 0 + use writer = new Utf8JsonWriter (destinationStream, options) + sourceDocument.WriteTo writer + writer.Flush () + + return shouldUpdate + } + +[] +let ``Get GraphQL introspection response returns schema`` () = + task { + use httpClient = TestHosts.createIntegrationHttpClient () + let! response = httpClient.GetFromJsonAsync("/", CancellationToken.None) + let schema = response.GetProperty("data").GetProperty("__schema") + Assert.NotEqual(Unchecked.defaultof, schema) + let hasErrors, _ = response.TryGetProperty "errors" + Assert.False hasErrors + } + +[] +let ``Update integration introspection file when schema changes`` () = + task { + use httpClient = TestHosts.createIntegrationHttpClient () + let! sourceStream = httpClient.GetStreamAsync("/") + let! wasUpdated = updateIntrospectionFileAsync CancellationToken.None sourceStream + Assert.True(File.Exists introspectionFilePath) + if wasUpdated then + let! sourceStreamSecondRun = httpClient.GetStreamAsync("/") + use sourceStreamForVerification = sourceStreamSecondRun + let! wasUpdatedSecondRun = updateIntrospectionFileAsync CancellationToken.None sourceStreamForVerification + Assert.False wasUpdatedSecondRun + } diff --git a/tests/FSharp.Data.GraphQL.IntegrationTests/LocalProviderTests.fs b/tests/FSharp.Data.GraphQL.IntegrationTests/LocalProviderTests.fs index 897364cb1..24944207e 100644 --- a/tests/FSharp.Data.GraphQL.IntegrationTests/LocalProviderTests.fs +++ b/tests/FSharp.Data.GraphQL.IntegrationTests/LocalProviderTests.fs @@ -5,13 +5,14 @@ open System.Threading.Tasks open FSharp.Data.GraphQL open Helpers -let [] ServerUrl = "http://localhost:8085" +let [] IntrospectionPath = "integration-introspection.json" let [] EmptyGuidAsString = "00000000-0000-0000-0000-000000000000" -type Provider = GraphQLProvider +type Provider = GraphQLProvider // type FileProvider = GraphQLProvider -let context = Provider.GetContext(ServerUrl) +let connection = TestHosts.createIntegrationConnection () +let context = Provider.GetContext(serverUrl = TestHosts.integrationServerUrl, connectionFactory = fun () -> connection) type Input = Provider.Types.Input type InputField = Provider.Types.InputField @@ -59,7 +60,7 @@ module SimpleOperation = [] let ``Should be able to execute a query without sending input field``() = - SimpleOperation.operation.Run() + SimpleOperation.operation.Run(context) |> SimpleOperation.validateResult None [] @@ -69,7 +70,7 @@ let ``Should be able to execute a query using context, without sending input fie [] let ``Should be able to execute a query without sending input field asynchronously``() : Task = task { - let! result = SimpleOperation.operation.AsyncRun() + let! result = SimpleOperation.operation.AsyncRun(context) result |> SimpleOperation.validateResult None } @@ -82,7 +83,7 @@ let ``Should be able to execute a query using context, without sending input fie [] let ``Should be able to execute a query sending an empty input field``() = let input = Input() - SimpleOperation.operation.Run(input) + SimpleOperation.operation.Run(context, input) |> SimpleOperation.validateResult (Some input) [] @@ -94,7 +95,7 @@ let ``Should be able to execute a query using context, sending an empty input fi [] let ``Should be able to execute a query without sending an empty input field asynchronously``() : Task = task { let input = Input() - let! result = SimpleOperation.operation.AsyncRun(input) + let! result = SimpleOperation.operation.AsyncRun(context, input) result |> SimpleOperation.validateResult (Some input) } @@ -109,7 +110,7 @@ let ``Should be able to execute a query using context, sending an empty input fi let ``Should be able to execute a query sending an input field with single field``() = let single = InputField("A", 2, System.Uri("http://localhost:1234"), EmptyGuidAsString) let input = Input(single) - SimpleOperation.operation.Run(input) + SimpleOperation.operation.Run(context, input) |> SimpleOperation.validateResult (Some input) [] @@ -123,7 +124,7 @@ let ``Should be able to execute a query using context, sending an input field wi let ``Should be able to execute a query without sending an input field with single field asynchronously``() : Task = task { let single = InputField("A", 2, System.Uri("http://localhost:1234"), EmptyGuidAsString) let input = Input(single) - let! result = SimpleOperation.operation.AsyncRun(input) + let! result = SimpleOperation.operation.AsyncRun(context, input) result |> SimpleOperation.validateResult (Some input) } @@ -139,7 +140,7 @@ let ``Should be able to execute a query using context, sending an input field wi let ``Should be able to execute a query sending an input field with list field``() = let list = [|InputField("A", 2, System.Uri("http://localhost:4321"), EmptyGuidAsString)|] let input = Input(list) - SimpleOperation.operation.Run(input) + SimpleOperation.operation.Run(context, input) |> SimpleOperation.validateResult (Some input) [] @@ -153,7 +154,7 @@ let ``Should be able to execute a query using context, sending an input field wi let ``Should be able to execute a query without sending an input field with list field asynchronously``() : Task = task { let list = [|InputField("A", 2, System.Uri("http://localhost:4321"), EmptyGuidAsString)|] let input = Input(list) - let! result = SimpleOperation.operation.AsyncRun(input) + let! result = SimpleOperation.operation.AsyncRun(context, input) result |> SimpleOperation.validateResult (Some input) } @@ -170,7 +171,7 @@ let ``Should be able to execute a query sending an input field with single and l let single = InputField("A", 2, System.Uri("http://localhost:1234"), EmptyGuidAsString) let list = [|InputField("A", 2, System.Uri("http://localhost:4321"), EmptyGuidAsString)|] let input = Input(single, list) - SimpleOperation.operation.Run(input) + SimpleOperation.operation.Run(context, input) |> SimpleOperation.validateResult (Some input) [] @@ -186,7 +187,7 @@ let ``Should be able to execute a query without sending an input field with sing let single = InputField("A", 2, System.Uri("http://localhost:1234"), EmptyGuidAsString) let list = [|InputField("A", 2, System.Uri("http://localhost:4321"), EmptyGuidAsString)|] let input = Input(single, list) - let! result = SimpleOperation.operation.AsyncRun(input) + let! result = SimpleOperation.operation.AsyncRun(context, input) result |> SimpleOperation.validateResult (Some input) } @@ -221,13 +222,13 @@ module SingleRequiredUploadOperation = [] let ``Should be able to execute a single required upload``() = let file = { Name = "file.txt"; ContentType = "text/plain"; Content = "Sample text file contents" } - SingleRequiredUploadOperation.operation.Run(file.MakeUpload()) + SingleRequiredUploadOperation.operation.Run(context, file.MakeUpload()) |> SingleRequiredUploadOperation.validateResult file [] let ``Should be able to execute a single required upload asynchronously``() : Task = task { let file = { Name = "file.txt"; ContentType = "text/plain"; Content = "Sample text file contents" } - let! result = SingleRequiredUploadOperation.operation.AsyncRun(file.MakeUpload()) + let! result = SingleRequiredUploadOperation.operation.AsyncRun(context, file.MakeUpload()) result |> SingleRequiredUploadOperation.validateResult file } @@ -256,24 +257,24 @@ module SingleOptionalUploadOperation = [] let ``Should be able to execute a single optional upload by passing a file``() = let file = { Name = "file.txt"; ContentType = "text/plain"; Content = "Sample text file contents" } - SingleOptionalUploadOperation.operation.Run(file.MakeUpload()) + SingleOptionalUploadOperation.operation.Run(context, file.MakeUpload()) |> SingleOptionalUploadOperation.validateResult (Some file) [] let ``Should be able to execute a single optional upload by passing a file, asynchronously``() : Task = task { let file = { Name = "file.txt"; ContentType = "text/plain"; Content = "Sample text file contents" } - let! result = SingleOptionalUploadOperation.operation.AsyncRun(file.MakeUpload()) + let! result = SingleOptionalUploadOperation.operation.AsyncRun(context, file.MakeUpload()) result |> SingleOptionalUploadOperation.validateResult (Some file) } [] let ``Should be able to execute a single optional upload by not passing a file``() = - SingleOptionalUploadOperation.operation.Run() + SingleOptionalUploadOperation.operation.Run(context) |> SingleOptionalUploadOperation.validateResult None [] let ``Should be able to execute a single optional upload by not passing a file asynchronously``() : Task = task { - let! result = SingleOptionalUploadOperation.operation.AsyncRun() + let! result = SingleOptionalUploadOperation.operation.AsyncRun(context) result |> SingleOptionalUploadOperation.validateResult None } @@ -302,7 +303,7 @@ let ``Should be able to execute a multiple required upload``() = let files = [| { Name = "file1.txt"; ContentType = "text/plain"; Content = "Sample text file contents 1" } { Name = "file2.txt"; ContentType = "text/plain"; Content = "Sample text file contents 2" } |] - RequiredMultipleUploadOperation.operation.Run(files |> Array.map (fun f -> f.MakeUpload())) + RequiredMultipleUploadOperation.operation.Run(context, files |> Array.map (fun f -> f.MakeUpload())) |> RequiredMultipleUploadOperation.validateResult files [] @@ -310,7 +311,7 @@ let ``Should be able to execute a multiple required upload asynchronously``() : let files = [| { Name = "file1.txt"; ContentType = "text/plain"; Content = "Sample text file contents 1" } { Name = "file2.txt"; ContentType = "text/plain"; Content = "Sample text file contents 2" } |] - let! result = RequiredMultipleUploadOperation.operation.AsyncRun(files |> Array.map (fun f -> f.MakeUpload())) + let! result = RequiredMultipleUploadOperation.operation.AsyncRun(context, files |> Array.map (fun f -> f.MakeUpload())) result |> RequiredMultipleUploadOperation.validateResult files } @@ -339,7 +340,7 @@ let ``Should be able to execute a multiple upload``() = let files = [| { Name = "file1.txt"; ContentType = "text/plain"; Content = "Sample text file contents 1" } { Name = "file2.txt"; ContentType = "text/plain"; Content = "Sample text file contents 2" } |] - OptionalMultipleUploadOperation.operation.Run(files |> Array.map (fun f -> f.MakeUpload())) + OptionalMultipleUploadOperation.operation.Run(context, files |> Array.map (fun f -> f.MakeUpload())) |> OptionalMultipleUploadOperation.validateResult (Some files) [] @@ -347,18 +348,18 @@ let ``Should be able to execute a multiple upload asynchronously``() : Task = ta let files = [| { Name = "file1.txt"; ContentType = "text/plain"; Content = "Sample text file contents 1" } { Name = "file2.txt"; ContentType = "text/plain"; Content = "Sample text file contents 2" } |] - let! result = OptionalMultipleUploadOperation.operation.AsyncRun(files |> Array.map (fun f -> f.MakeUpload())) + let! result = OptionalMultipleUploadOperation.operation.AsyncRun(context, files |> Array.map (fun f -> f.MakeUpload())) result |> OptionalMultipleUploadOperation.validateResult (Some files) } [] let ``Should be able to execute a multiple upload by sending no uploads``() = - OptionalMultipleUploadOperation.operation.Run() + OptionalMultipleUploadOperation.operation.Run(context) |> OptionalMultipleUploadOperation.validateResult None [] let ``Should be able to execute a multiple upload asynchronously by sending no uploads``() : Task = task { - let! result = OptionalMultipleUploadOperation.operation.AsyncRun() + let! result = OptionalMultipleUploadOperation.operation.AsyncRun(context) result |> OptionalMultipleUploadOperation.validateResult None } @@ -387,7 +388,7 @@ let ``Should be able to execute a multiple optional upload``() = let files = [| Some { Name = "file1.txt"; ContentType = "text/plain"; Content = "Sample text file contents 1" } Some { Name = "file2.txt"; ContentType = "text/plain"; Content = "Sample text file contents 2" } |] - OptionalMultipleOptionalUploadOperation.operation.Run(files |> Array.map (Option.map (fun f -> f.MakeUpload()))) + OptionalMultipleOptionalUploadOperation.operation.Run(context, files |> Array.map (Option.map (fun f -> f.MakeUpload()))) |> OptionalMultipleOptionalUploadOperation.validateResult (Some files) [] @@ -395,18 +396,18 @@ let ``Should be able to execute a multiple optional upload asynchronously``() : let files = [| Some { Name = "file1.txt"; ContentType = "text/plain"; Content = "Sample text file contents 1" } Some { Name = "file2.txt"; ContentType = "text/plain"; Content = "Sample text file contents 2" } |] - let! result = OptionalMultipleOptionalUploadOperation.operation.AsyncRun(files |> Array.map (Option.map (fun f -> f.MakeUpload()))) + let! result = OptionalMultipleOptionalUploadOperation.operation.AsyncRun(context, files |> Array.map (Option.map (fun f -> f.MakeUpload()))) result |> (OptionalMultipleOptionalUploadOperation.validateResult (Some files)) } [] let ``Should be able to execute a multiple optional upload by sending no uploads``() = - OptionalMultipleOptionalUploadOperation.operation.Run() + OptionalMultipleOptionalUploadOperation.operation.Run(context) |> OptionalMultipleOptionalUploadOperation.validateResult None [] let ``Should be able to execute a multiple optional upload asynchronously by sending no uploads``() : Task = task { - let! result = OptionalMultipleOptionalUploadOperation.operation.AsyncRun() + let! result = OptionalMultipleOptionalUploadOperation.operation.AsyncRun(context) result |> OptionalMultipleOptionalUploadOperation.validateResult None } @@ -417,7 +418,7 @@ let ``Should be able to execute a multiple optional upload by sending some uploa None Some { Name = "file2.txt"; ContentType = "text/plain"; Content = "Sample text file contents 2" } None |] - OptionalMultipleOptionalUploadOperation.operation.Run(files |> Array.map (Option.map (fun f -> f.MakeUpload()))) + OptionalMultipleOptionalUploadOperation.operation.Run(context, files |> Array.map (Option.map (fun f -> f.MakeUpload()))) |> OptionalMultipleOptionalUploadOperation.validateResult (Some files) [] @@ -427,7 +428,7 @@ let ``Should be able to execute a multiple optional upload asynchronously by sen None Some { Name = "file2.txt"; ContentType = "text/plain"; Content = "Sample text file contents 2" } None |] - let! result = OptionalMultipleOptionalUploadOperation.operation.AsyncRun(files |> Array.map (Option.map (fun f -> f.MakeUpload()))) + let! result = OptionalMultipleOptionalUploadOperation.operation.AsyncRun(context, files |> Array.map (Option.map (fun f -> f.MakeUpload()))) result |> OptionalMultipleOptionalUploadOperation.validateResult (Some files) } @@ -484,7 +485,7 @@ let ``Should be able to upload files inside another input type``() : Task = task multiple = Array.map makeUpload request.Multiple, nullableMultiple = Array.map makeUpload request.NullableMultiple.Value, nullableMultipleNullable = Array.map (Option.map makeUpload) request.NullableMultipleNullable.Value) - let! result = UploadRequestOperation.operation.AsyncRun(input) + let! result = UploadRequestOperation.operation.AsyncRun(context, input) result |> UploadRequestOperation.validateResult request } @@ -506,7 +507,7 @@ module UploadComplexOperation = 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()) - UploadComplexOperation.operation.Run(input) + UploadComplexOperation.operation.Run(context, input) |> UploadComplexOperation.validateResult file [] @@ -520,7 +521,7 @@ let ``Should be able to upload file using complex input object with context`` () 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) + let! result = UploadComplexOperation.operation.AsyncRun(context, input) result |> UploadComplexOperation.validateResult file } diff --git a/tests/FSharp.Data.GraphQL.IntegrationTests/LocalProviderWithOptionalParametersOnlyTests.fs b/tests/FSharp.Data.GraphQL.IntegrationTests/LocalProviderWithOptionalParametersOnlyTests.fs index 74cc97a48..5422c356a 100644 --- a/tests/FSharp.Data.GraphQL.IntegrationTests/LocalProviderWithOptionalParametersOnlyTests.fs +++ b/tests/FSharp.Data.GraphQL.IntegrationTests/LocalProviderWithOptionalParametersOnlyTests.fs @@ -5,12 +5,13 @@ open System.Threading.Tasks open FSharp.Data.GraphQL open Helpers -let [] ServerUrl = "http://localhost:8085" +let [] IntrospectionPath = "integration-introspection.json" let [] EmptyGuidAsString = "00000000-0000-0000-0000-000000000000" -type Provider = GraphQLProvider +type Provider = GraphQLProvider -let context = Provider.GetContext(ServerUrl) +let connection = TestHosts.createIntegrationConnection () +let context = Provider.GetContext(serverUrl = TestHosts.integrationServerUrl, connectionFactory = fun () -> connection) type Input = Provider.Types.Input type InputField = Provider.Types.InputField @@ -58,7 +59,7 @@ module SimpleOperation = [] let ``Should be able to execute a query without sending input field``() = - SimpleOperation.operation.Run() + SimpleOperation.operation.Run(context) |> SimpleOperation.validateResult None [] @@ -68,7 +69,7 @@ let ``Should be able to execute a query using context, without sending input fie [] let ``Should be able to execute a query without sending input field asynchronously``() = - SimpleOperation.operation.AsyncRun() + SimpleOperation.operation.AsyncRun(context) |> Async.RunSynchronously |> SimpleOperation.validateResult None @@ -81,7 +82,7 @@ let ``Should be able to execute a query using context, without sending input fie [] let ``Should be able to execute a query sending an empty input field``() = let input = Input() - SimpleOperation.operation.Run(Some input) + SimpleOperation.operation.Run(context, Some input) |> SimpleOperation.validateResult (Some input) [] @@ -93,7 +94,7 @@ let ``Should be able to execute a query using context, sending an empty input fi [] let ``Should be able to execute a query without sending an empty input field asynchronously``() : Task = task { let input = Input() - let! result = SimpleOperation.operation.AsyncRun(Some input) + let! result = SimpleOperation.operation.AsyncRun(context, Some input) result |> SimpleOperation.validateResult (Some input) } @@ -108,7 +109,7 @@ let ``Should be able to execute a query using context, sending an empty input fi let ``Should be able to execute a query sending an input field with single field``() = let single = InputField("A", 2, System.Uri("http://localhost:1234"), EmptyGuidAsString) let input = Input(Some single) - SimpleOperation.operation.Run(Some input) + SimpleOperation.operation.Run(context, Some input) |> SimpleOperation.validateResult (Some input) [] @@ -122,7 +123,7 @@ let ``Should be able to execute a query using context, sending an input field wi let ``Should be able to execute a query without sending an input field with single field asynchronously``() : Task = task { let single = InputField("A", 2, System.Uri("http://localhost:1234"), EmptyGuidAsString) let input = Input(Some single) - let! result = SimpleOperation.operation.AsyncRun(Some input) + let! result = SimpleOperation.operation.AsyncRun(context, Some input) result |> SimpleOperation.validateResult (Some input) } @@ -138,7 +139,7 @@ let ``Should be able to execute a query using context, sending an input field wi let ``Should be able to execute a query sending an input field with list field``() = let list = [|InputField("A", 2, System.Uri("http://localhost:4321"), EmptyGuidAsString)|] let input = Input(list = Some list) - SimpleOperation.operation.Run(Some input) + SimpleOperation.operation.Run(context, Some input) |> SimpleOperation.validateResult (Some input) [] @@ -152,7 +153,7 @@ let ``Should be able to execute a query using context, sending an input field wi let ``Should be able to execute a query without sending an input field with list field asynchronously``() : Task = task { let list = [|InputField("A", 2, System.Uri("http://localhost:4321"), EmptyGuidAsString)|] let input = Input(list = Some list) - let! result = SimpleOperation.operation.AsyncRun(Some input) + let! result = SimpleOperation.operation.AsyncRun(context, Some input) result |> SimpleOperation.validateResult (Some input) } @@ -169,7 +170,7 @@ let ``Should be able to execute a query sending an input field with single and l let single = InputField("A", 2, System.Uri("http://localhost:1234"), EmptyGuidAsString) let list = [|InputField("A", 2, System.Uri("http://localhost:4321"), EmptyGuidAsString)|] let input = Input(Some single, Some list) - SimpleOperation.operation.Run(Some input) + SimpleOperation.operation.Run(context, Some input) |> SimpleOperation.validateResult (Some input) [] @@ -185,7 +186,7 @@ let ``Should be able to execute a query without sending an input field with sing let single = InputField("A", 2, System.Uri("http://localhost:1234"), EmptyGuidAsString) let list = [|InputField("A", 2, System.Uri("http://localhost:4321"), EmptyGuidAsString)|] let input = Input(Some single, Some list) - let! result = SimpleOperation.operation.AsyncRun(Some input) + let! result = SimpleOperation.operation.AsyncRun(context, Some input) result |> SimpleOperation.validateResult (Some input) } @@ -220,13 +221,13 @@ module SingleRequiredUploadOperation = [] let ``Should be able to execute a single required upload``() = let file = { Name = "file.txt"; ContentType = "text/plain"; Content = "Sample text file contents" } - SingleRequiredUploadOperation.operation.Run(file.MakeUpload(file.Name)) + SingleRequiredUploadOperation.operation.Run(context, file.MakeUpload(file.Name)) |> SingleRequiredUploadOperation.validateResult file [] let ``Should be able to execute a single required upload asynchronously``() : Task = task { let file = { Name = "file.txt"; ContentType = "text/plain"; Content = "Sample text file contents" } - let! result = SingleRequiredUploadOperation.operation.AsyncRun(file.MakeUpload()) + let! result = SingleRequiredUploadOperation.operation.AsyncRun(context, file.MakeUpload()) result |> SingleRequiredUploadOperation.validateResult file } @@ -254,24 +255,24 @@ module SingleOptionalUploadOperation = [] let ``Should be able to execute a single optional upload by passing a file``() = let file = { Name = "file.txt"; ContentType = "text/plain"; Content = "Sample text file contents" } - SingleOptionalUploadOperation.operation.Run(file.MakeUpload() |> Some) + SingleOptionalUploadOperation.operation.Run(context, file.MakeUpload() |> Some) |> SingleOptionalUploadOperation.validateResult (Some file) [] let ``Should be able to execute a single optional upload by passing a file, asynchronously``() : Task = task { let file = { Name = "file.txt"; ContentType = "text/plain"; Content = "Sample text file contents" } - let! result = SingleOptionalUploadOperation.operation.AsyncRun(file.MakeUpload("test") |> Some) + let! result = SingleOptionalUploadOperation.operation.AsyncRun(context, file.MakeUpload("test") |> Some) result |> SingleOptionalUploadOperation.validateResult (Some file) } [] let ``Should be able to execute a single optional upload by not passing a file``() = - SingleOptionalUploadOperation.operation.Run() + SingleOptionalUploadOperation.operation.Run(context) |> SingleOptionalUploadOperation.validateResult None [] let ``Should be able to execute a single optional upload by not passing a file asynchronously``() : Task = task { - let! result = SingleOptionalUploadOperation.operation.AsyncRun() + let! result = SingleOptionalUploadOperation.operation.AsyncRun(context) result |> SingleOptionalUploadOperation.validateResult None } @@ -300,7 +301,7 @@ let ``Should be able to execute a multiple required upload``() = let files = [| { Name = "file1.txt"; ContentType = "text/plain"; Content = "Sample text file contents 1" } { Name = "file2.txt"; ContentType = "text/plain"; Content = "Sample text file contents 2" } |] - RequiredMultipleUploadOperation.operation.Run(files |> Array.map (fun f -> f.MakeUpload())) + RequiredMultipleUploadOperation.operation.Run(context, files |> Array.map (fun f -> f.MakeUpload())) |> RequiredMultipleUploadOperation.validateResult files [] @@ -308,7 +309,7 @@ let ``Should be able to execute a multiple required upload asynchronously``() : let files = [| { Name = "file1.txt"; ContentType = "text/plain"; Content = "Sample text file contents 1" } { Name = "file2.txt"; ContentType = "text/plain"; Content = "Sample text file contents 2" } |] - let! result = RequiredMultipleUploadOperation.operation.AsyncRun(files |> Array.map (fun f -> f.MakeUpload())) + let! result = RequiredMultipleUploadOperation.operation.AsyncRun(context, files |> Array.map (fun f -> f.MakeUpload())) result |> RequiredMultipleUploadOperation.validateResult files } @@ -337,7 +338,7 @@ let ``Should be able to execute a multiple upload``() = let files = [| { Name = "file1.txt"; ContentType = "text/plain"; Content = "Sample text file contents 1" } { Name = "file2.txt"; ContentType = "text/plain"; Content = "Sample text file contents 2" } |] - OptionalMultipleUploadOperation.operation.Run(files |> Array.map (fun f -> f.MakeUpload()) |> Some) + OptionalMultipleUploadOperation.operation.Run(context, files |> Array.map (fun f -> f.MakeUpload()) |> Some) |> OptionalMultipleUploadOperation.validateResult (Some files) [] @@ -345,18 +346,18 @@ let ``Should be able to execute a multiple upload asynchronously``() : Task = ta let files = [| { Name = "file1.txt"; ContentType = "text/plain"; Content = "Sample text file contents 1" } { Name = "file2.txt"; ContentType = "text/plain"; Content = "Sample text file contents 2" } |] - let! result = OptionalMultipleUploadOperation.operation.AsyncRun((files |> Array.map _.MakeUpload()) |> Some) + let! result = OptionalMultipleUploadOperation.operation.AsyncRun(context, (files |> Array.map _.MakeUpload()) |> Some) result |> OptionalMultipleUploadOperation.validateResult (Some files) } [] let ``Should be able to execute a multiple upload by sending no uploads``() = - OptionalMultipleUploadOperation.operation.Run() + OptionalMultipleUploadOperation.operation.Run(context) |> OptionalMultipleUploadOperation.validateResult None [] let ``Should be able to execute a multiple upload asynchronously by sending no uploads``() : Task = task { - let! result = OptionalMultipleUploadOperation.operation.AsyncRun() + let! result = OptionalMultipleUploadOperation.operation.AsyncRun(context) result |> OptionalMultipleUploadOperation.validateResult None } @@ -385,7 +386,7 @@ let ``Should be able to execute a multiple optional upload``() = let files = [| Some { Name = "file1.txt"; ContentType = "text/plain"; Content = "Sample text file contents 1" } Some { Name = "file2.txt"; ContentType = "text/plain"; Content = "Sample text file contents 2" } |] - OptionalMultipleOptionalUploadOperation.operation.Run((files |> Array.map (Option.map _.MakeUpload())) |> Some) + OptionalMultipleOptionalUploadOperation.operation.Run(context, (files |> Array.map (Option.map _.MakeUpload())) |> Some) |> OptionalMultipleOptionalUploadOperation.validateResult (Some files) [] @@ -393,18 +394,18 @@ let ``Should be able to execute a multiple optional upload asynchronously``() : let files = [| Some { Name = "file1.txt"; ContentType = "text/plain"; Content = "Sample text file contents 1" } Some { Name = "file2.txt"; ContentType = "text/plain"; Content = "Sample text file contents 2" } |] - let! result = OptionalMultipleOptionalUploadOperation.operation.AsyncRun((files |> Array.map (Option.map _.MakeUpload())) |> Some) + let! result = OptionalMultipleOptionalUploadOperation.operation.AsyncRun(context, (files |> Array.map (Option.map _.MakeUpload())) |> Some) result |> OptionalMultipleOptionalUploadOperation.validateResult (Some files) } [] let ``Should be able to execute a multiple optional upload by sending no uploads``() = - OptionalMultipleOptionalUploadOperation.operation.Run() + OptionalMultipleOptionalUploadOperation.operation.Run(context) |> OptionalMultipleOptionalUploadOperation.validateResult None [] let ``Should be able to execute a multiple optional upload asynchronously by sending no uploads``() : Task = task { - let! result = OptionalMultipleOptionalUploadOperation.operation.AsyncRun() + let! result = OptionalMultipleOptionalUploadOperation.operation.AsyncRun(context) result |> OptionalMultipleOptionalUploadOperation.validateResult None } @@ -415,7 +416,7 @@ let ``Should be able to execute a multiple optional upload by sending some uploa None Some { Name = "file2.txt"; ContentType = "text/plain"; Content = "Sample text file contents 2" } None |] - OptionalMultipleOptionalUploadOperation.operation.Run(files |> Array.map (Option.map _.MakeUpload()) |> Some) + OptionalMultipleOptionalUploadOperation.operation.Run(context, files |> Array.map (Option.map _.MakeUpload()) |> Some) |> OptionalMultipleOptionalUploadOperation.validateResult (Some files) [] @@ -425,7 +426,7 @@ let ``Should be able to execute a multiple optional upload asynchronously by sen None Some { Name = "file2.txt"; ContentType = "text/plain"; Content = "Sample text file contents 2" } None |] - let! result = OptionalMultipleOptionalUploadOperation.operation.AsyncRun(files |> Array.map (Option.map _.MakeUpload()) |> Some) + let! result = OptionalMultipleOptionalUploadOperation.operation.AsyncRun(context, files |> Array.map (Option.map _.MakeUpload()) |> Some) result |> OptionalMultipleOptionalUploadOperation.validateResult (Some files) } @@ -482,7 +483,7 @@ let ``Should be able to upload files inside another input type``() = multiple = Array.map makeUpload request.Multiple, nullableMultiple = Some (Array.map makeUpload request.NullableMultiple.Value), nullableMultipleNullable = Some (Array.map (Option.map makeUpload) request.NullableMultipleNullable.Value)) - UploadRequestOperation.operation.Run(input) + UploadRequestOperation.operation.Run(context, input) |> UploadRequestOperation.validateResult request module UploadComplexOperation = @@ -503,7 +504,7 @@ module UploadComplexOperation = 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()) - UploadComplexOperation.operation.Run(input) + UploadComplexOperation.operation.Run(context, input) |> UploadComplexOperation.validateResult file [] @@ -517,7 +518,7 @@ let ``Should be able to upload file using complex input object with context`` () 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) + let! result = UploadComplexOperation.operation.AsyncRun(context, input) result |> UploadComplexOperation.validateResult file } diff --git a/tests/FSharp.Data.GraphQL.IntegrationTests/OperationErrorTests.fs b/tests/FSharp.Data.GraphQL.IntegrationTests/OperationErrorTests.fs index f95b44df0..7dfa7b0f0 100644 --- a/tests/FSharp.Data.GraphQL.IntegrationTests/OperationErrorTests.fs +++ b/tests/FSharp.Data.GraphQL.IntegrationTests/OperationErrorTests.fs @@ -7,9 +7,12 @@ open FSharp.Data.GraphQL open FSharp.Data.GraphQL.Client [] -let ServerUrl = "http://localhost:8085" +let IntrospectionPath = "integration-introspection.json" -type Provider = GraphQLProvider +type Provider = GraphQLProvider + +let connection = TestHosts.createIntegrationConnection () +let context = Provider.GetContext(serverUrl = TestHosts.integrationServerUrl, connectionFactory = fun () -> connection) module ErrorOperation = let operation = @@ -106,7 +109,7 @@ let ``Should parse all combinations of optional operation error fields`` () = [] let ``Should map server error extensions and locations into operation result`` () = - let result = ErrorOperation.operation.Run () + let result = ErrorOperation.operation.Run(context) result.Errors.Length |> equals 1 diff --git a/tests/FSharp.Data.GraphQL.IntegrationTests/SwapiLocalProviderTests.fs b/tests/FSharp.Data.GraphQL.IntegrationTests/SwapiLocalProviderTests.fs index e673cba63..7d9ab8331 100644 --- a/tests/FSharp.Data.GraphQL.IntegrationTests/SwapiLocalProviderTests.fs +++ b/tests/FSharp.Data.GraphQL.IntegrationTests/SwapiLocalProviderTests.fs @@ -3,17 +3,16 @@ module FSharp.Data.GraphQL.IntegrationTests.SwapiLocalProviderTests open Xunit open Helpers open FSharp.Data.GraphQL -open System.Net.Http open System.Threading.Tasks // Local provider should be able to be created from local introspection json file. type Provider = GraphQLProvider<"introspection.json"> // We are going to re-use the same HttpClient through all requests. -let connection = new GraphQLClientConnection(new HttpClient()) +let connection = TestHosts.createStarWarsConnection () // As we are not using a connection to a server to get the introspection, we need a runtime context. -let getContext() = Provider.GetContext(serverUrl = "http://localhost:8086", connectionFactory = fun () -> connection) +let getContext() = Provider.GetContext(serverUrl = TestHosts.starWarsServerUrl, connectionFactory = fun () -> connection) type Episode = Provider.Types.Episode diff --git a/tests/FSharp.Data.GraphQL.IntegrationTests/SwapiRemoteProviderTests.fs b/tests/FSharp.Data.GraphQL.IntegrationTests/SwapiRemoteProviderTests.fs index dc73b38db..07a8c7ed0 100644 --- a/tests/FSharp.Data.GraphQL.IntegrationTests/SwapiRemoteProviderTests.fs +++ b/tests/FSharp.Data.GraphQL.IntegrationTests/SwapiRemoteProviderTests.fs @@ -5,7 +5,10 @@ open Helpers open FSharp.Data.GraphQL open System.Threading.Tasks -type Provider = GraphQLProvider<"http://localhost:8086"> +type Provider = GraphQLProvider<"introspection.json"> + +let connection = TestHosts.createStarWarsConnection () +let context = Provider.GetContext(serverUrl = TestHosts.starWarsServerUrl, connectionFactory = fun () -> connection) type Episode = Provider.Types.Episode @@ -47,13 +50,27 @@ hero (id: "1000") { result.Data.IsSome |> equals true result.Data.Value.Hero.IsSome |> equals true result.Data.Value.Hero.Value.AppearsIn |> equals [| Episode.NewHope; Episode.Empire; Episode.Jedi |] - let expectedFriends : Operation.Types.HeroFields.FriendsFields.EdgesFields.NodeFields.Character array = - [| Operation.Types.HeroFields.FriendsFields.EdgesFields.NodeFields.Human(name = "Han Solo") - Operation.Types.HeroFields.FriendsFields.EdgesFields.NodeFields.Human(name = "Leia Organa", homePlanet = "Alderaan") - Operation.Types.HeroFields.FriendsFields.EdgesFields.NodeFields.Droid(name = "C-3PO", primaryFunction = "Protocol") - Operation.Types.HeroFields.FriendsFields.EdgesFields.NodeFields.Droid(name = "R2-D2", primaryFunction = "Astromech") |] let friends = result.Data.Value.Hero.Value.Friends.Edges |> Array.map (fun e -> e.Node) - friends |> equals expectedFriends + friends.Length |> equals 4 + do + let friend0 = friends[0] + friend0.IsHuman() |> equals true + friend0.AsHuman().Name |> equals (Some "Han Solo") + do + let friend1 = friends[1] + friend1.IsHuman() |> equals true + friend1.AsHuman().Name |> equals (Some "Leia Organa") + friend1.AsHuman().HomePlanet |> equals (Some "Alderaan") + do + let friend2 = friends[2] + friend2.IsDroid() |> equals true + friend2.AsDroid().Name |> equals (Some "C-3PO") + friend2.AsDroid().PrimaryFunction |> equals (Some "Protocol") + do + let friend3 = friends[3] + friend3.IsDroid() |> equals true + friend3.AsDroid().Name |> equals (Some "R2-D2") + friend3.AsDroid().PrimaryFunction |> equals (Some "Astromech") result.Data.Value.Hero.Value.HomePlanet |> equals (Some "Tatooine") let actual = normalize <| sprintf "%A" result.Data let expected = normalize <| """Some @@ -80,18 +97,18 @@ hero (id: "1000") { [] let ``Should be able to start a simple query operation synchronously`` () = - SimpleOperation.operation.Run() + SimpleOperation.operation.Run(context) |> SimpleOperation.validateResult [] let ``Should be able to start a simple query operation asynchronously`` () : Task = task { - let! result = SimpleOperation.operation.AsyncRun() + let! result = SimpleOperation.operation.AsyncRun(context) result |> SimpleOperation.validateResult } [] let ``Should be able to use pattern matching methods on an union type`` () = - let result = SimpleOperation.operation.Run() + let result = SimpleOperation.operation.Run(context) result.Data.IsSome |> equals true result.Data.Value.Hero.IsSome |> equals true let friends = result.Data.Value.Hero.Value.Friends.Edges |> Array.map (fun e -> e.Node) @@ -149,12 +166,12 @@ module MutationOperation = [] let ``Should be able to run a mutation synchronously`` () = - MutationOperation.operation.Run() + MutationOperation.operation.Run(context) |> MutationOperation.validateResult [] let ``Should be able to run a mutation asynchronously`` () : Task = task { - let! result = MutationOperation.operation.AsyncRun() + let! result = MutationOperation.operation.AsyncRun(context) result |> MutationOperation.validateResult } @@ -169,13 +186,27 @@ module FileOperation = result.Data.IsSome |> equals true result.Data.Value.Hero.IsSome |> equals true result.Data.Value.Hero.Value.AppearsIn |> equals [| Episode.NewHope; Episode.Empire; Episode.Jedi |] - let expectedFriends : Operation.Types.HeroFields.FriendsFields.EdgesFields.NodeFields.Character array = - [| Operation.Types.HeroFields.FriendsFields.EdgesFields.NodeFields.Human(name = "Han Solo") - Operation.Types.HeroFields.FriendsFields.EdgesFields.NodeFields.Human(name = "Leia Organa", homePlanet = "Alderaan") - Operation.Types.HeroFields.FriendsFields.EdgesFields.NodeFields.Droid(name = "C-3PO", primaryFunction = "Protocol") - Operation.Types.HeroFields.FriendsFields.EdgesFields.NodeFields.Droid(name = "R2-D2", primaryFunction = "Astromech") |] let friends = result.Data.Value.Hero.Value.Friends.Edges |> Array.map _.Node - friends |> equals expectedFriends + friends.Length |> equals 4 + do + let friend0 = friends[0] + friend0.IsHuman() |> equals true + friend0.AsHuman().Name |> equals (Some "Han Solo") + do + let friend1 = friends[1] + friend1.IsHuman() |> equals true + friend1.AsHuman().Name |> equals (Some "Leia Organa") + friend1.AsHuman().HomePlanet |> equals (Some "Alderaan") + do + let friend2 = friends[2] + friend2.IsDroid() |> equals true + friend2.AsDroid().Name |> equals (Some "C-3PO") + friend2.AsDroid().PrimaryFunction |> equals (Some "Protocol") + do + let friend3 = friends[3] + friend3.IsDroid() |> equals true + friend3.AsDroid().Name |> equals (Some "R2-D2") + friend3.AsDroid().PrimaryFunction |> equals (Some "Astromech") result.Data.Value.Hero.Value.HomePlanet |> equals (Some "Tatooine") let actual = normalize <| sprintf "%A" result.Data let expected = normalize <| """Some @@ -202,5 +233,5 @@ module FileOperation = [] let ``Should be able to run a query from a query file`` () = - FileOperation.fileOp.Run() + FileOperation.fileOp.Run(context) |> FileOperation.validateResult diff --git a/tests/FSharp.Data.GraphQL.IntegrationTests/TestHosts.fs b/tests/FSharp.Data.GraphQL.IntegrationTests/TestHosts.fs new file mode 100644 index 000000000..31478a08c --- /dev/null +++ b/tests/FSharp.Data.GraphQL.IntegrationTests/TestHosts.fs @@ -0,0 +1,43 @@ +module FSharp.Data.GraphQL.IntegrationTests.TestHosts + +open FSharp.Data.GraphQL +open Microsoft.AspNetCore.Mvc.Testing +open System.Net.Http +open System + +type IntegrationServerApplicationFactory () = + inherit WebApplicationFactory () + +type StarWarsApplicationFactory () = + inherit WebApplicationFactory () + +let private integrationFactory = lazy (new IntegrationServerApplicationFactory ()) +let private starWarsFactory = lazy (new StarWarsApplicationFactory ()) + +let createIntegrationHttpClient () : HttpClient = + integrationFactory.Value.CreateClient () + +let createStarWarsHttpClient () : HttpClient = + starWarsFactory.Value.CreateClient () + +let private getIntegrationServerUrl () = + use client = createIntegrationHttpClient () + client.BaseAddress.ToString().TrimEnd '/' + +let private getStarWarsServerUrl () = + use client = createStarWarsHttpClient () + client.BaseAddress.ToString().TrimEnd '/' + +do + AppDomain.CurrentDomain.ProcessExit.Add(fun _ -> + if integrationFactory.IsValueCreated then + integrationFactory.Value.Dispose () + + if starWarsFactory.IsValueCreated then + starWarsFactory.Value.Dispose ()) + +let integrationServerUrl = getIntegrationServerUrl () +let starWarsServerUrl = getStarWarsServerUrl () + +let createIntegrationConnection () = new GraphQLClientConnection (createIntegrationHttpClient ()) +let createStarWarsConnection () = new GraphQLClientConnection (createStarWarsHttpClient ()) diff --git a/tests/FSharp.Data.GraphQL.IntegrationTests/integration-introspection.json b/tests/FSharp.Data.GraphQL.IntegrationTests/integration-introspection.json new file mode 100644 index 000000000..ad448c42f --- /dev/null +++ b/tests/FSharp.Data.GraphQL.IntegrationTests/integration-introspection.json @@ -0,0 +1,1929 @@ +{ + "documentId": 986164407, + "data": { + "__schema": { + "queryType": { + "name": "Query" + }, + "mutationType": { + "name": "Mutation" + }, + "subscriptionType": null, + "types": [ + { + "kind": "SCALAR", + "name": "Int", + "description": "The \u0060Int\u0060 scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "SCALAR", + "name": "String", + "description": "The \u0060String\u0060 scalar type represents textual data, represented as UTF-8 character sequences. The \u0060String\u0060 type is most often used by GraphQL to represent free-form human-readable text.", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "SCALAR", + "name": "Boolean", + "description": "The \u0060Boolean\u0060 scalar type represents \u0060true\u0060 or \u0060false\u0060.", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "SCALAR", + "name": "Float", + "description": "The \u0060Float\u0060 scalar type represents signed double-precision fractional values as specified by [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point).", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "SCALAR", + "name": "ID", + "description": "The \u0060ID\u0060 scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The \u0060ID\u0060 type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as \u0060\u00224\u0022\u0060) or integer (such as \u00604\u0060) input value will be accepted as an ID.", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "SCALAR", + "name": "DateTimeOffset", + "description": "The \u0060DateTimeOffset\u0060 scalar type represents a Date value with Time component. The \u0060DateTimeOffset\u0060 type appears in a JSON response as a String representation compatible with ISO-8601 format.", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "SCALAR", + "name": "DateOnly", + "description": "The \u0060DateOnly\u0060 scalar type represents a Date value without Time component. The \u0060DateOnly\u0060 type appears in a JSON response as a \u0060String\u0060 representation of full-date value as specified by [IETF 3339](https://www.ietf.org/rfc/rfc3339.txt).", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "SCALAR", + "name": "TimeOnly", + "description": "The \u0060TimeOnly\u0060 scalar type represents a Time value without Date component. The \u0060TimeOnly\u0060 type appears in a JSON response as a \u0060String\u0060 representation of full-time value as specified by [IETF 3339](https://www.ietf.org/rfc/rfc3339.txt).", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "SCALAR", + "name": "URI", + "description": "The \u0060URI\u0060 scalar type represents a string resource identifier compatible with URI standard. The \u0060URI\u0060 type appears in a JSON response as a String.", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "__Schema", + "description": "A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all available types and directives on the server, as well as the entry points for query, mutation, and subscription operations.", + "fields": [ + { + "name": "directives", + "description": "A list of all directives supported by this server.", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__Directive", + "ofType": null + } + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "mutationType", + "description": "If this server supports mutation, the type that mutation operations will be rooted at.", + "args": [], + "type": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "queryType", + "description": "The type that query operations will be rooted at.", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "subscriptionType", + "description": "If this server support subscription, the type that subscription operations will be rooted at.", + "args": [], + "type": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "types", + "description": "A list of all types supported by this server.", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + } + } + } + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "__Directive", + "description": "A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document. In some cases, you need to provide options to alter GraphQL\u2019s execution behavior in ways field arguments will not suffice, such as conditionally including or skipping a field. Directives provide this by describing additional information to the executor.", + "fields": [ + { + "name": "args", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__InputValue", + "ofType": null + } + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "description", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "locations", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "ENUM", + "name": "__DirectiveLocation", + "ofType": null + } + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "name", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "onField", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "onFragment", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "onOperation", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "__InputValue", + "description": "Arguments provided to Fields or Directives and the input fields of an InputObject are represented as Input Values which describe their type and optionally a default value.", + "fields": [ + { + "name": "defaultValue", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "description", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "name", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "type", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "__Type", + "description": "The fundamental unit of any GraphQL Schema is the type. There are many kinds of types in GraphQL as represented by the \u0060__TypeKind\u0060 enum. Depending on the kind of a type, certain fields describe information about that type. Scalar types provide no information beyond a name and description, while Enum types provide their values. Object and Interface types provide the fields they describe. Abstract types, Union and Interface, provide the Object types possible at runtime. List and NonNull types compose other types.", + "fields": [ + { + "name": "description", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "enumValues", + "description": null, + "args": [ + { + "name": "includeDeprecated", + "description": null, + "type": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + }, + "defaultValue": "false" + } + ], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__EnumValue", + "ofType": null + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "fields", + "description": null, + "args": [ + { + "name": "includeDeprecated", + "description": null, + "type": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + }, + "defaultValue": "false" + } + ], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__Field", + "ofType": null + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "inputFields", + "description": null, + "args": [], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__InputValue", + "ofType": null + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "interfaces", + "description": null, + "args": [], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "kind", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "ENUM", + "name": "__TypeKind", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "name", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "ofType", + "description": null, + "args": [], + "type": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "possibleTypes", + "description": null, + "args": [], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + } + } + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "__EnumValue", + "description": "One possible value for a given Enum. Enum values are unique values, not a placeholder for a string or numeric value. However an Enum value is returned in a JSON response as a string.", + "fields": [ + { + "name": "deprecationReason", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "description", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "isDeprecated", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "name", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "__Field", + "description": "Object and Interface types are described by a list of Fields, each of which has a name, potentially a list of arguments, and a return type.", + "fields": [ + { + "name": "args", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__InputValue", + "ofType": null + } + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "deprecationReason", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "description", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "isDeprecated", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "name", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "type", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "ENUM", + "name": "__TypeKind", + "description": "An enum describing what kind of type a given __Type is.", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": [ + { + "name": "SCALAR", + "description": "Indicates this type is a scalar.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "OBJECT", + "description": "Indicates this type is an object. \u0060fields\u0060 and \u0060interfaces\u0060 are valid fields.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "INTERFACE", + "description": "Indicates this type is an interface. \u0060fields\u0060 and \u0060possibleTypes\u0060 are valid fields.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "UNION", + "description": "Indicates this type is a union. \u0060possibleTypes\u0060 is a valid field.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "ENUM", + "description": "Indicates this type is an enum. \u0060enumValues\u0060 is a valid field.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "INPUT_OBJECT", + "description": "Indicates this type is an input object. \u0060inputFields\u0060 is a valid field.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "LIST", + "description": "Indicates this type is a list. \u0060ofType\u0060 is a valid field.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "NON_NULL", + "description": "Indicates this type is a non-null. \u0060ofType\u0060 is a valid field.", + "isDeprecated": false, + "deprecationReason": null + } + ], + "possibleTypes": null + }, + { + "kind": "ENUM", + "name": "__DirectiveLocation", + "description": "A Directive can be adjacent to many parts of the GraphQL language, a __DirectiveLocation describes one such possible adjacencies.", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": [ + { + "name": "QUERY", + "description": "Location adjacent to a query operation.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "MUTATION", + "description": "Location adjacent to a mutation operation.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "SUBSCRIPTION", + "description": "Location adjacent to a subscription operation.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "FIELD", + "description": "Location adjacent to a field.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "FRAGMENT_DEFINITION", + "description": "Location adjacent to a fragment definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "FRAGMENT_SPREAD", + "description": "Location adjacent to a fragment spread.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "INLINE_FRAGMENT", + "description": "Location adjacent to an inline fragment.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "SCHEMA", + "description": "Location adjacent to a schema IDL definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "SCALAR", + "description": "Location adjacent to a scalar IDL definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "OBJECT", + "description": "Location adjacent to an object IDL definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "FIELD_DEFINITION", + "description": "Location adjacent to a field IDL definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "ARGUMENT_DEFINITION", + "description": "Location adjacent to a field argument IDL definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "INTERFACE", + "description": "Location adjacent to an interface IDL definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "UNION", + "description": "Location adjacent to an union IDL definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "ENUM", + "description": "Location adjacent to an enum IDL definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "ENUM_VALUE", + "description": "Location adjacent to an enum value definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "INPUT_OBJECT", + "description": "Location adjacent to an input object IDL definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "INPUT_FIELD_DEFINITION", + "description": "Location adjacent to an input object field IDL definition.", + "isDeprecated": false, + "deprecationReason": null + } + ], + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "Query", + "description": "The query type.", + "fields": [ + { + "name": "alwaysError", + "description": "Always produces an execution error for integration tests.", + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "echo", + "description": "Enters an input type and get it back.", + "args": [ + { + "name": "input", + "description": "The input to be echoed as an output.", + "type": { + "kind": "INPUT_OBJECT", + "name": "Input", + "ofType": null + }, + "defaultValue": null + } + ], + "type": { + "kind": "OBJECT", + "name": "Output", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "Output", + "description": "The output for an input.", + "fields": [ + { + "name": "list", + "description": "A list of output fields.", + "args": [], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "OutputField", + "ofType": null + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "single", + "description": "A single output field.", + "args": [], + "type": { + "kind": "OBJECT", + "name": "OutputField", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "OutputField", + "description": "The output for a field input.", + "fields": [ + { + "name": "deprecated", + "description": "A string value through a deprecated field.", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "isDeprecated": true, + "deprecationReason": "This field is deprecated." + }, + { + "name": "guid", + "description": "A Guid value.", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Guid", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "guidId", + "description": "A Guid Id value.", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "ID", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "guidIdOption", + "description": "A Guid Id value.", + "args": [], + "type": { + "kind": "SCALAR", + "name": "ID", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "int", + "description": "An integer value.", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "intOption", + "description": "An integer option value.", + "args": [], + "type": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "string", + "description": "A string value.", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "stringId", + "description": "A String Id value.", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "ID", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "stringIdOption", + "description": "A String Id value.", + "args": [], + "type": { + "kind": "SCALAR", + "name": "ID", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "stringOption", + "description": "A string option value.", + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "uri", + "description": "An URI value.", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "URI", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "SCALAR", + "name": "Guid", + "description": "The \u0060Guid\u0060 scalar type represents a Globally Unique Identifier value. It\u0027s a 128-bit long byte key, that can be serialized to string.", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "INPUT_OBJECT", + "name": "Input", + "description": "Input object type.", + "fields": null, + "inputFields": [ + { + "name": "single", + "description": "A single input field.", + "type": { + "kind": "INPUT_OBJECT", + "name": "InputField", + "ofType": null + }, + "defaultValue": null + }, + { + "name": "list", + "description": "A list of input fields.", + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "INPUT_OBJECT", + "name": "InputField", + "ofType": null + } + } + }, + "defaultValue": null + } + ], + "interfaces": null, + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "INPUT_OBJECT", + "name": "InputField", + "description": null, + "fields": null, + "inputFields": [ + { + "name": "string", + "description": "A string value.", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "defaultValue": null + }, + { + "name": "int", + "description": "An integer value.", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + } + }, + "defaultValue": null + }, + { + "name": "stringOption", + "description": "A string option value.", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "defaultValue": null + }, + { + "name": "intOption", + "description": "An integer option value.", + "type": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + }, + "defaultValue": null + }, + { + "name": "uri", + "description": "An URI value.", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "URI", + "ofType": null + } + }, + "defaultValue": null + }, + { + "name": "guid", + "description": "A Guid value.", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Guid", + "ofType": null + } + }, + "defaultValue": null + } + ], + "interfaces": null, + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "Mutation", + "description": null, + "fields": [ + { + "name": "multipleUpload", + "description": "Uploads a list of files to the server and get them back.", + "args": [ + { + "name": "files", + "description": "The files to upload.", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "INPUT_OBJECT", + "name": "File", + "ofType": null + } + } + } + }, + "defaultValue": null + } + ], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "UploadedFile", + "ofType": null + } + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "nullableMultipleNullableUpload", + "description": "Uploads (maybe) a list of files (maybe) to the server and get them back (maybe).", + "args": [ + { + "name": "files", + "description": "The files to upload.", + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "INPUT_OBJECT", + "name": "File", + "ofType": null + } + }, + "defaultValue": null + } + ], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "UploadedFile", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "nullableMultipleUpload", + "description": "Uploads (maybe) a list of files to the server and get them back (maybe).", + "args": [ + { + "name": "files", + "description": "The files to upload.", + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "INPUT_OBJECT", + "name": "File", + "ofType": null + } + } + }, + "defaultValue": null + } + ], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "UploadedFile", + "ofType": null + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "nullableSingleUpload", + "description": "Uploads (maybe) a single file to the server and get it back (maybe).", + "args": [ + { + "name": "file", + "description": "The file to be uploaded.", + "type": { + "kind": "INPUT_OBJECT", + "name": "File", + "ofType": null + }, + "defaultValue": null + } + ], + "type": { + "kind": "OBJECT", + "name": "UploadedFile", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "singleUpload", + "description": "Uploads a single file to the server and get it back.", + "args": [ + { + "name": "file", + "description": "The file to be uploaded.", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "INPUT_OBJECT", + "name": "File", + "ofType": null + } + }, + "defaultValue": null + } + ], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "UploadedFile", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "uploadComplex", + "description": "", + "args": [ + { + "name": "input", + "description": null, + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "INPUT_OBJECT", + "name": "InputFile", + "ofType": null + } + }, + "defaultValue": null + } + ], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "uploadRequest", + "description": "Upload several files in different forms.", + "args": [ + { + "name": "request", + "description": "The request for uploading several files in different forms.", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "INPUT_OBJECT", + "name": "UploadRequest", + "ofType": null + } + }, + "defaultValue": null + } + ], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "UploadResponse", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "UploadedFile", + "description": "Contains data of an uploaded file.", + "fields": [ + { + "name": "contentAsText", + "description": "The content of the file as text.", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "contentType", + "description": "The content type of the file.", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "name", + "description": "The name of the file.", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "INPUT_OBJECT", + "name": "File", + "description": "The \u0060File\u0060 type represents a file on one or more fields of an object in an object list. The filter is represented by a JSON object where the fields are the complemented by specific suffixes to represent a query.", + "fields": null, + "inputFields": [], + "interfaces": null, + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "INPUT_OBJECT", + "name": "InputFile", + "description": null, + "fields": null, + "inputFields": [ + { + "name": "file", + "description": null, + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "INPUT_OBJECT", + "name": "File", + "ofType": null + } + }, + "defaultValue": null + } + ], + "interfaces": null, + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "UploadResponse", + "description": "Contains uploaded files of an upload files request.", + "fields": [ + { + "name": "multiple", + "description": "Multiple file uploads.", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "UploadedFile", + "ofType": null + } + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "nullableMultiple", + "description": "Optional list of multiple file uploads.", + "args": [], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "UploadedFile", + "ofType": null + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "nullableMultipleNullable", + "description": "Optional list of multiple optional file uploads.", + "args": [], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "UploadedFile", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "single", + "description": "A single file upload.", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "UploadedFile", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "INPUT_OBJECT", + "name": "UploadRequest", + "description": "Request for uploading files in several different forms.", + "fields": null, + "inputFields": [ + { + "name": "single", + "description": "A single file upload.", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "INPUT_OBJECT", + "name": "File", + "ofType": null + } + }, + "defaultValue": null + }, + { + "name": "multiple", + "description": "Multiple file uploads.", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "INPUT_OBJECT", + "name": "File", + "ofType": null + } + } + } + }, + "defaultValue": null + }, + { + "name": "nullableMultiple", + "description": "Optional list of multiple file uploads.", + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "INPUT_OBJECT", + "name": "File", + "ofType": null + } + } + }, + "defaultValue": null + }, + { + "name": "nullableMultipleNullable", + "description": "Optional list of multiple optional file uploads.", + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "INPUT_OBJECT", + "name": "File", + "ofType": null + } + }, + "defaultValue": null + } + ], + "interfaces": null, + "enumValues": null, + "possibleTypes": null + } + ], + "directives": [ + { + "name": "include", + "description": "Directs the executor to include this field or fragment only when the \u0060if\u0060 argument is true.", + "locations": [ + "FIELD", + "FRAGMENT_SPREAD", + "INLINE_FRAGMENT" + ], + "args": [ + { + "name": "if", + "description": "Included when true.", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + "defaultValue": null + } + ] + }, + { + "name": "skip", + "description": "Directs the executor to skip this field or fragment when the \u0060if\u0060 argument is true.", + "locations": [ + "FIELD", + "FRAGMENT_SPREAD", + "INLINE_FRAGMENT" + ], + "args": [ + { + "name": "if", + "description": "Skipped when true.", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + "defaultValue": null + } + ] + }, + { + "name": "defer", + "description": "Defers the resolution of this field or fragment", + "locations": [ + "FIELD", + "FRAGMENT_DEFINITION", + "FRAGMENT_SPREAD", + "INLINE_FRAGMENT" + ], + "args": [] + }, + { + "name": "stream", + "description": "Streams the resolution of this field or fragment", + "locations": [ + "FIELD", + "FRAGMENT_DEFINITION", + "FRAGMENT_SPREAD", + "INLINE_FRAGMENT" + ], + "args": [] + }, + { + "name": "live", + "description": "Subscribes for live updates of this field or fragment", + "locations": [ + "FIELD", + "FRAGMENT_DEFINITION", + "FRAGMENT_SPREAD", + "INLINE_FRAGMENT" + ], + "args": [] + } + ] + } + } +} \ No newline at end of file diff --git a/tests/FSharp.Data.GraphQL.IntegrationTests/introspection.json b/tests/FSharp.Data.GraphQL.IntegrationTests/introspection.json index 7b3d9abcf..a961111fd 100644 --- a/tests/FSharp.Data.GraphQL.IntegrationTests/introspection.json +++ b/tests/FSharp.Data.GraphQL.IntegrationTests/introspection.json @@ -1,5 +1,5 @@ { - "documentId": -128167532, + "documentId": 195530235, "data": { "__schema": { "queryType": { From 022d6336968609d00dd4c308c2de158af1f1dd1d Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Sun, 17 May 2026 20:02:19 +0200 Subject: [PATCH 2/9] Enforce input/output kind safety for `ListOf`/`Nullable` wrappers at compile time (#569) Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Andrii Chebukin --- .../SchemaDefinitions.fs | 86 +++++++++-- .../SchemaDefinitionsExtensions.fs | 6 +- src/FSharp.Data.GraphQL.Shared/TypeSystem.fs | 39 +++-- .../FSharp.Data.GraphQL.Tests.fsproj | 10 ++ .../PlanningTests.fs | 8 +- .../TypeWrappersKindSafety/.gitignore | 1 + .../ListOf.InputAsOutput.fsx | 15 ++ .../ListOf.OutputAsInput.fsx | 15 ++ .../Nullable.InputAsOutput.fsx | 15 ++ .../Nullable.OutputAsInput.fsx | 15 ++ .../StructNullable.InputAsOutput.fsx | 15 ++ .../StructNullable.OutputAsInput.fsx | 15 ++ .../TypeWrappersKindSafety/Valid.fsx | 26 ++++ .../TypeWrappersKindSafetyTests.fs | 144 ++++++++++++++++++ .../Variables and Inputs/InputComplexTests.fs | 2 +- .../Variables and Inputs/InputNestedTests.fs | 2 +- 16 files changed, 379 insertions(+), 35 deletions(-) create mode 100644 tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/.gitignore create mode 100644 tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/ListOf.InputAsOutput.fsx create mode 100644 tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/ListOf.OutputAsInput.fsx create mode 100644 tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/Nullable.InputAsOutput.fsx create mode 100644 tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/Nullable.OutputAsInput.fsx create mode 100644 tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/StructNullable.InputAsOutput.fsx create mode 100644 tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/StructNullable.OutputAsInput.fsx create mode 100644 tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/Valid.fsx create mode 100644 tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafetyTests.fs diff --git a/src/FSharp.Data.GraphQL.Shared/SchemaDefinitions.fs b/src/FSharp.Data.GraphQL.Shared/SchemaDefinitions.fs index 51f8682c5..bc33ab3e8 100644 --- a/src/FSharp.Data.GraphQL.Shared/SchemaDefinitions.fs +++ b/src/FSharp.Data.GraphQL.Shared/SchemaDefinitions.fs @@ -392,17 +392,73 @@ module SchemaDefinitions = | false, _ -> getParseError destinationType s | InlineConstant value -> value.GetCoerceError destinationType - /// Wraps a GraphQL type definition, allowing defining field/argument - /// to take option of provided value. - let Nullable(innerDef : #TypeDef<'Val>) : NullableDef<'Val> = upcast { NullableDefinition.OfType = innerDef } - - /// Wraps a GraphQL type definition, allowing defining field/argument - /// to take voption of provided value. - let StructNullable(innerDef : #TypeDef<'Val>) : StructNullableDef<'Val> = upcast { StructNullableDefinition.OfType = innerDef } - - /// Wraps a GraphQL type definition, allowing defining field/argument - /// to take collection of provided value. - let ListOf(innerDef : #TypeDef<'Val>) : ListOfDef<'Val, 'Seq> = upcast { ListOfDefinition.OfType = innerDef } + type TypeWrapperStaticDispatch = + + static member Nullable<'Val>(innerDef : InputOutputDef<'Val>) : NullableDef<'Val> = + let ofType : TypeDef<'Val> = upcast innerDef + upcast { NullableDefinition.OfType = ofType } + + static member Nullable<'Val>(innerDef : InputDef<'Val>) : InputDef<'Val option> = + let ofType : TypeDef<'Val> = upcast innerDef + upcast { NullableDefinition.OfType = ofType } + + static member Nullable<'Val>(innerDef : OutputDef<'Val>) : OutputDef<'Val option> = + let ofType : TypeDef<'Val> = upcast innerDef + upcast { NullableDefinition.OfType = ofType } + + static member StructNullable<'Val>(innerDef : InputOutputDef<'Val>) : StructNullableDef<'Val> = + let ofType : TypeDef<'Val> = upcast innerDef + upcast { StructNullableDefinition.OfType = ofType } + + static member StructNullable<'Val>(innerDef : InputDef<'Val>) : InputDef<'Val voption> = + let ofType : TypeDef<'Val> = upcast innerDef + upcast { StructNullableDefinition.OfType = ofType } + + static member StructNullable<'Val>(innerDef : OutputDef<'Val>) : OutputDef<'Val voption> = + let ofType : TypeDef<'Val> = upcast innerDef + upcast { StructNullableDefinition.OfType = ofType } + + static member ListOf<'Val, 'Seq when 'Seq :> 'Val seq>(innerDef : InputOutputDef<'Val>) : ListOfDef<'Val, 'Seq> = + let ofType : TypeDef<'Val> = upcast innerDef + upcast { ListOfDefinition.OfType = ofType } + + static member ListOf<'Val, 'Seq when 'Seq :> 'Val seq>(innerDef : InputDef<'Val>) : InputDef<'Seq> = + let ofType : TypeDef<'Val> = upcast innerDef + upcast { ListOfDefinition.OfType = ofType } + + static member ListOf<'Val, 'Seq when 'Seq :> 'Val seq>(innerDef : OutputDef<'Val>) : OutputDef<'Seq> = + let ofType : TypeDef<'Val> = upcast innerDef + upcast { ListOfDefinition.OfType = ofType } + + /// Wraps a GraphQL input or output type definition, allowing defining field/argument + /// to take option of provided value while preserving input/output kind of wrapped type. + /// Input wrappers produce input definitions, output wrappers produce output definitions, + /// and wrappers over types implementing both kinds keep both capabilities. + /// Dispatch is selected at compile time via SRTP. + let inline Nullable< ^Def, ^Wrapped when (^Def or TypeWrapperStaticDispatch) : (static member Nullable : ^Def -> ^Wrapped) > + (innerDef : ^Def) + : ^Wrapped = + ((^Def or TypeWrapperStaticDispatch) : (static member Nullable : ^Def -> ^Wrapped) innerDef) + + /// Wraps a GraphQL input or output type definition, allowing defining field/argument + /// to take voption of provided value while preserving input/output kind of wrapped type. + /// Input wrappers produce input definitions, output wrappers produce output definitions, + /// and wrappers over types implementing both kinds keep both capabilities. + /// Dispatch is selected at compile time via SRTP. + let inline StructNullable< ^Def, ^Wrapped when (^Def or TypeWrapperStaticDispatch) : (static member StructNullable : ^Def -> ^Wrapped) > + (innerDef : ^Def) + : ^Wrapped = + ((^Def or TypeWrapperStaticDispatch) : (static member StructNullable : ^Def -> ^Wrapped) innerDef) + + /// Wraps a GraphQL input or output type definition, allowing defining field/argument + /// to take collection of provided value while preserving input/output kind of wrapped type. + /// Input wrappers produce input definitions, output wrappers produce output definitions, + /// and wrappers over types implementing both kinds keep both capabilities. + /// Dispatch is selected at compile time via SRTP. + let inline ListOf< ^Def, ^Wrapped when (^Def or TypeWrapperStaticDispatch) : (static member ListOf : ^Def -> ^Wrapped) > + (innerDef : ^Def) + : ^Wrapped = + ((^Def or TypeWrapperStaticDispatch) : (static member ListOf : ^Def -> ^Wrapped) innerDef) let internal variableOrElse other (_ : InputExecutionContextProvider) value (variables : IReadOnlyDictionary) = match value with @@ -1415,13 +1471,14 @@ module SchemaDefinitions = /// If defined, this value will be used when no matching input has been provided by the requester. /// Optional input description. Usefull for generating documentation. static member SkippableInput(name : string, typedef : #InputDef<'In>, ?description : string) : InputFieldDef = + let typedef : InputDef<'In> = upcast typedef upcast { InputFieldDefinition.Name = name Description = description |> Option.map (fun s -> s + " Skip this field if you want to avoid saving it") IsSkippable = true TypeDef = - match (box typedef) with - | :? NullableDef<'In> as n -> n - | _ -> Nullable typedef + match (box typedef) with + | :? NullableDef<'In> as n -> (n :> InputDef<'In option>) + | _ -> Nullable typedef DefaultValue = None ExecuteInput = Unchecked.defaultof } @@ -1539,4 +1596,3 @@ module SchemaDefinitions = Description = description FieldsFn = fun () -> fieldsFn() |> List.toArray ResolveType = resolveType } - diff --git a/src/FSharp.Data.GraphQL.Shared/SchemaDefinitionsExtensions.fs b/src/FSharp.Data.GraphQL.Shared/SchemaDefinitionsExtensions.fs index b11909644..1da3341c7 100644 --- a/src/FSharp.Data.GraphQL.Shared/SchemaDefinitionsExtensions.fs +++ b/src/FSharp.Data.GraphQL.Shared/SchemaDefinitionsExtensions.fs @@ -27,8 +27,10 @@ type internal CustomFieldsObjectDefinition<'Val> (source : ObjectDef<'Val>, fiel member _.Implements = source.Implements member _.IsTypeOf = source.IsTypeOf interface TypeDef with - member this.MakeList () = upcast (ListOf this) - member this.MakeNullable () = upcast (Nullable this) + // We construct wrappers directly here because this API works with untyped TypeDef values. + // The public ListOf/Nullable helpers use SRTP dispatch and require statically known direction. + member this.MakeList () = upcast { ListOfDefinition.OfType = this } + member this.MakeNullable () = upcast { NullableDefinition.OfType = this } member _.Type = (source :> TypeDef).Type interface NamedDef with member _.Name = (source :> NamedDef).Name diff --git a/src/FSharp.Data.GraphQL.Shared/TypeSystem.fs b/src/FSharp.Data.GraphQL.Shared/TypeSystem.fs index 11006387b..be8e79b55 100644 --- a/src/FSharp.Data.GraphQL.Shared/TypeSystem.fs +++ b/src/FSharp.Data.GraphQL.Shared/TypeSystem.fs @@ -609,6 +609,24 @@ and OutputDef<'Val> = inherit TypeDef<'Val> end +/// Representation of type definitions that can be used as both inputs and outputs +/// (for example scalars and enums). This marker is also used by SRTP wrapper dispatch. +and InputOutputDef = + interface + inherit InputDef + inherit OutputDef + end + +/// Representation of all type definitions, that can be used as both inputs and outputs +/// and are constrained to represent the provided .NET type. +and InputOutputDef<'Val> = + interface + inherit InputOutputDef + inherit TypeDef<'Val> + inherit InputDef<'Val> + inherit OutputDef<'Val> + end + /// Representation of leaf type definitions. Leaf types represents leafs /// of the GraphQL query tree. Each query path must end with a leaf. /// By default only scalars and enums are valid leaf types. @@ -1067,8 +1085,7 @@ and ScalarDef = abstract CoerceOutput : obj -> obj option inherit TypeDef inherit NamedDef - inherit InputDef - inherit OutputDef + inherit InputOutputDef inherit LeafDef end @@ -1098,6 +1115,7 @@ and [] ScalarDefinition<'Primitive, 'Val> = { interface InputDef interface OutputDef + interface InputOutputDef interface ScalarDef with member x.Name = x.Name @@ -1107,6 +1125,7 @@ and [] ScalarDefinition<'Primitive, 'Val> = { interface InputDef<'Val> interface OutputDef<'Val> + interface InputOutputDef<'Val> interface LeafDef interface NamedDef with @@ -1182,8 +1201,7 @@ and EnumDef = /// List of available enum cases. abstract Options : EnumVal[] inherit TypeDef - inherit InputDef - inherit OutputDef + inherit InputOutputDef inherit LeafDef inherit NamedDef end @@ -1197,8 +1215,7 @@ and EnumDef<'Val> = abstract Options : EnumValue<'Val>[] inherit EnumDef inherit TypeDef<'Val> - inherit InputDef<'Val> - inherit OutputDef<'Val> + inherit InputOutputDef<'Val> end and internal EnumDefinition<'Val> = { @@ -1212,6 +1229,7 @@ and internal EnumDefinition<'Val> = { interface InputDef interface OutputDef + interface InputOutputDef interface TypeDef with member _.Type = typeof<'Val> @@ -1523,8 +1541,7 @@ and ListOfDef<'Val, 'Seq when 'Seq :> 'Val seq> = /// GraphQL type definition of the container element type. abstract OfType : TypeDef<'Val> inherit TypeDef<'Seq> - inherit InputDef<'Seq> - inherit OutputDef<'Seq> + inherit InputOutputDef<'Seq> inherit ListOfDef end @@ -1574,8 +1591,7 @@ and NullableDef<'Val> = interface /// GraphQL type definition of the nested type. abstract OfType : TypeDef<'Val> - inherit InputDef<'Val option> - inherit OutputDef<'Val option> + inherit InputOutputDef<'Val option> inherit NullableDef end @@ -1614,8 +1630,7 @@ and StructNullableDef<'Val> = interface /// GraphQL type definition of the nested type. abstract OfType : TypeDef<'Val> - inherit InputDef<'Val voption> - inherit OutputDef<'Val voption> + inherit InputOutputDef<'Val voption> inherit NullableDef end diff --git a/tests/FSharp.Data.GraphQL.Tests/FSharp.Data.GraphQL.Tests.fsproj b/tests/FSharp.Data.GraphQL.Tests/FSharp.Data.GraphQL.Tests.fsproj index 763d841ec..1bc224559 100644 --- a/tests/FSharp.Data.GraphQL.Tests/FSharp.Data.GraphQL.Tests.fsproj +++ b/tests/FSharp.Data.GraphQL.Tests/FSharp.Data.GraphQL.Tests.fsproj @@ -41,6 +41,16 @@ + + + + + + + + + + diff --git a/tests/FSharp.Data.GraphQL.Tests/PlanningTests.fs b/tests/FSharp.Data.GraphQL.Tests/PlanningTests.fs index 57b330da4..ad7cf74d5 100644 --- a/tests/FSharp.Data.GraphQL.Tests/PlanningTests.fs +++ b/tests/FSharp.Data.GraphQL.Tests/PlanningTests.fs @@ -139,7 +139,7 @@ let ``Planning must retain correct types for lists``() = } } }""" - let PersonList : ListOfDef = ListOf Person + let PersonList : OutputDef = ListOf Person let plan = schemaProcessor.CreateExecutionPlanOrFail(query) equals 1 plan.Fields.Length let listInfo = plan.Fields.Head @@ -178,7 +178,7 @@ let ``Planning must work with interfaces``() = }""" let plan = schemaProcessor.CreateExecutionPlanOrFail(query) equals 1 plan.Fields.Length - let INamedList : ListOfDef = ListOf INamed + let INamedList : OutputDef = ListOf INamed let listInfo = plan.Fields.Head listInfo.Identifier |> equals "names" listInfo.ReturnDef |> equals (upcast INamedList) @@ -215,7 +215,7 @@ let ``Planning must work with unions``() = let plan = schemaProcessor.CreateExecutionPlanOrFail(query) equals 1 plan.Fields.Length let listInfo = plan.Fields.Head - let UNamedList : ListOfDef = ListOf UNamed + let UNamedList : OutputDef = ListOf UNamed listInfo.Identifier |> equals "names" listInfo.ReturnDef |> equals (upcast UNamedList) let (ResolveCollection(info)) = listInfo.Kind @@ -309,7 +309,7 @@ let ``Planning must handle inline fragment with non-matching type condition in u // Verify the execution plan structure equals 1 plan.Fields.Length let listInfo = plan.Fields.Head - let UNamedList : ListOfDef = ListOf UNamed + let UNamedList : OutputDef = ListOf UNamed listInfo.Identifier |> equals "names" listInfo.ReturnDef |> equals (upcast UNamedList) let (ResolveCollection(info)) = listInfo.Kind diff --git a/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/.gitignore b/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/.gitignore new file mode 100644 index 000000000..a6b4595a5 --- /dev/null +++ b/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/.gitignore @@ -0,0 +1 @@ +References.fsx diff --git a/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/ListOf.InputAsOutput.fsx b/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/ListOf.InputAsOutput.fsx new file mode 100644 index 000000000..c13f43223 --- /dev/null +++ b/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/ListOf.InputAsOutput.fsx @@ -0,0 +1,15 @@ +#load "References.fsx" + +open FSharp.Data.GraphQL.Types + +type InputOnly = { Value: int } +type OutputOnly = { Value: int } + +let inputOnlyType = + Define.InputObject( + name = "InputOnlyType", + fields = [ Define.Input("value", IntType) ] + ) + +// This should fail: InputDef cannot be assigned to OutputDef +let _ : OutputDef = ListOf inputOnlyType diff --git a/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/ListOf.OutputAsInput.fsx b/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/ListOf.OutputAsInput.fsx new file mode 100644 index 000000000..00849d1db --- /dev/null +++ b/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/ListOf.OutputAsInput.fsx @@ -0,0 +1,15 @@ +#load "References.fsx" + +open FSharp.Data.GraphQL.Types + +type InputOnly = { Value: int } +type OutputOnly = { Value: int } + +let outputOnlyType = + Define.Object( + name = "OutputOnlyType", + fields = [ Define.Field("value", IntType, fun _ x -> x.Value) ] + ) + +// This should fail: OutputDef cannot be assigned to InputDef +let _ : InputDef = ListOf outputOnlyType diff --git a/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/Nullable.InputAsOutput.fsx b/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/Nullable.InputAsOutput.fsx new file mode 100644 index 000000000..f94d9e297 --- /dev/null +++ b/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/Nullable.InputAsOutput.fsx @@ -0,0 +1,15 @@ +#load "References.fsx" + +open FSharp.Data.GraphQL.Types + +type InputOnly = { Value: int } +type OutputOnly = { Value: int } + +let inputOnlyType = + Define.InputObject( + name = "InputOnlyType", + fields = [ Define.Input("value", IntType) ] + ) + +// This should fail: InputDef cannot be assigned to OutputDef +let _ : OutputDef = Nullable inputOnlyType diff --git a/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/Nullable.OutputAsInput.fsx b/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/Nullable.OutputAsInput.fsx new file mode 100644 index 000000000..65a876354 --- /dev/null +++ b/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/Nullable.OutputAsInput.fsx @@ -0,0 +1,15 @@ +#load "References.fsx" + +open FSharp.Data.GraphQL.Types + +type InputOnly = { Value: int } +type OutputOnly = { Value: int } + +let outputOnlyType = + Define.Object( + name = "OutputOnlyType", + fields = [ Define.Field("value", IntType, fun _ x -> x.Value) ] + ) + +// This should fail: OutputDef cannot be assigned to InputDef +let _ : InputDef = Nullable outputOnlyType diff --git a/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/StructNullable.InputAsOutput.fsx b/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/StructNullable.InputAsOutput.fsx new file mode 100644 index 000000000..ffd651eaf --- /dev/null +++ b/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/StructNullable.InputAsOutput.fsx @@ -0,0 +1,15 @@ +#load "References.fsx" + +open FSharp.Data.GraphQL.Types + +type InputOnly = { Value: int } +type OutputOnly = { Value: int } + +let inputOnlyType = + Define.InputObject( + name = "InputOnlyType", + fields = [ Define.Input("value", IntType) ] + ) + +// This should fail: InputDef cannot be assigned to OutputDef +let _ : OutputDef = StructNullable inputOnlyType diff --git a/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/StructNullable.OutputAsInput.fsx b/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/StructNullable.OutputAsInput.fsx new file mode 100644 index 000000000..6ec0f4950 --- /dev/null +++ b/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/StructNullable.OutputAsInput.fsx @@ -0,0 +1,15 @@ +#load "References.fsx" + +open FSharp.Data.GraphQL.Types + +type InputOnly = { Value: int } +type OutputOnly = { Value: int } + +let outputOnlyType = + Define.Object( + name = "OutputOnlyType", + fields = [ Define.Field("value", IntType, fun _ x -> x.Value) ] + ) + +// This should fail: OutputDef cannot be assigned to InputDef +let _ : InputDef = StructNullable outputOnlyType diff --git a/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/Valid.fsx b/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/Valid.fsx new file mode 100644 index 000000000..74c56dce3 --- /dev/null +++ b/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafety/Valid.fsx @@ -0,0 +1,26 @@ +#load "References.fsx" + +open FSharp.Data.GraphQL.Types + +type InputOnly = { Value: int } +type OutputOnly = { Value: int } + +let inputOnlyType = + Define.InputObject( + name = "InputOnlyType", + fields = [ Define.Input("value", IntType) ] + ) + +let outputOnlyType = + Define.Object( + name = "OutputOnlyType", + fields = [ Define.Field("value", IntType, fun _ x -> x.Value) ] + ) + +// These are all valid assignments and must compile successfully +let _inputList : InputDef = ListOf inputOnlyType +let _outputList : OutputDef = ListOf outputOnlyType +let _inputNullable : InputDef = Nullable inputOnlyType +let _outputNullable : OutputDef = Nullable outputOnlyType +let _inputStruct : InputDef = StructNullable inputOnlyType +let _outputStruct : OutputDef = StructNullable outputOnlyType diff --git a/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafetyTests.fs b/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafetyTests.fs new file mode 100644 index 000000000..cececf2dd --- /dev/null +++ b/tests/FSharp.Data.GraphQL.Tests/TypeWrappersKindSafetyTests.fs @@ -0,0 +1,144 @@ +module FSharp.Data.GraphQL.Tests.TypeWrappersKindSafetyTests + +open System +open System.Diagnostics +open System.Threading.Tasks +open FSharp.Data.GraphQL.Types +open Xunit + +type private InputOnly = { Value : int } +type private OutputOnly = { Value : int } + +let private InputOnlyType = + Define.InputObject (name = "InputOnlyType", fields = [ Define.Input ("value", IntType) ]) + +let private OutputOnlyType = + Define.Object (name = "OutputOnlyType", fields = [ Define.Field ("value", IntType, fun _ x -> x.Value) ]) + +type TypeWrappersKindSafetyFixture () = + + let scriptsDir = IO.Path.Combine (AppContext.BaseDirectory, "TypeWrappersKindSafety") + let referencesPath = IO.Path.Combine (scriptsDir, "References.fsx") + let sourceProjectDir = + IO.Path.GetFullPath (IO.Path.Combine (AppContext.BaseDirectory, "..", "..", "..")) + let sourceScriptsDir = IO.Path.Combine (sourceProjectDir, "TypeWrappersKindSafety") + let sourceReferencesPath = IO.Path.Combine (sourceScriptsDir, "References.fsx") + + let ensureFileContentAsync (path : string) (content : string) : Task = task { + if IO.File.Exists (path) then + let! existing = IO.File.ReadAllTextAsync (path) + + if not (String.Equals (existing, content, StringComparison.Ordinal)) then + do! IO.File.WriteAllTextAsync (path, content) + else + do! IO.File.WriteAllTextAsync (path, content) + } + + member _.ScriptPath (name : string) = IO.Path.Combine (scriptsDir, name) + + member _.RunFsiCheckAsync (scriptPath : string) : Task = task { + let psi = + ProcessStartInfo ( + "dotnet", + sprintf "fsi --noninteractive \"%s\"" scriptPath, + UseShellExecute = false, + RedirectStandardOutput = true, + RedirectStandardError = true, + WorkingDirectory = AppContext.BaseDirectory + ) + + use proc = Process.Start (psi) + do! proc.WaitForExitAsync () + return proc.ExitCode + } + + member private _.ReferencesContent = + let sharedAssembly = IO.Path.Combine (AppContext.BaseDirectory, "FSharp.Data.GraphQL.Shared.dll") + let serverAssembly = IO.Path.Combine (AppContext.BaseDirectory, "FSharp.Data.GraphQL.Server.dll") + + [| sprintf "#r @\"%s\"" sharedAssembly; sprintf "#r @\"%s\"" serverAssembly |] + |> String.concat "\n" + + interface IAsyncLifetime with + + member this.InitializeAsync () : Task = + task { + IO.Directory.CreateDirectory (scriptsDir) |> ignore + IO.Directory.CreateDirectory (sourceScriptsDir) |> ignore + + let content = this.ReferencesContent + + do! ensureFileContentAsync referencesPath content + do! ensureFileContentAsync sourceReferencesPath content + } + + member _.DisposeAsync () = Task.CompletedTask + +type TypeWrappersKindSafetyTests (fixture : TypeWrappersKindSafetyFixture) = + interface IClassFixture + + [] + member _.``ListOf keeps input-output direction`` () : Task = task { + let inputList : InputDef = ListOf InputOnlyType + let outputList : OutputDef = ListOf OutputOnlyType + Assert.Equal ("[InputOnlyType!]!", inputList.ToString ()) + Assert.Equal ("[OutputOnlyType!]!", outputList.ToString ()) + } + + [] + member _.``Nullable keeps input-output direction`` () : Task = task { + let nullableInput : InputDef = Nullable InputOnlyType + let nullableOutput : OutputDef = Nullable OutputOnlyType + Assert.Equal ("InputOnlyType", nullableInput.ToString ()) + Assert.Equal ("OutputOnlyType", nullableOutput.ToString ()) + } + + [] + member _.``StructNullable keeps input-output direction`` () : Task = task { + let nullableInput : InputDef = StructNullable InputOnlyType + let nullableOutput : OutputDef = StructNullable OutputOnlyType + Assert.Equal ("InputOnlyType", nullableInput.ToString ()) + Assert.Equal ("OutputOnlyType", nullableOutput.ToString ()) + } + + [] + member _.``Valid script compiles successfully`` () : Task = task { + let! exitCode = fixture.RunFsiCheckAsync (fixture.ScriptPath ("Valid.fsx")) + Assert.Equal (0, exitCode) + } + + [] + member _.``ListOf rejects output type as input at compile time`` () : Task = task { + let! exitCode = fixture.RunFsiCheckAsync (fixture.ScriptPath ("ListOf.OutputAsInput.fsx")) + Assert.NotEqual (0, exitCode) + } + + [] + member _.``ListOf rejects input type as output at compile time`` () : Task = task { + let! exitCode = fixture.RunFsiCheckAsync (fixture.ScriptPath ("ListOf.InputAsOutput.fsx")) + Assert.NotEqual (0, exitCode) + } + + [] + member _.``Nullable rejects output type as input at compile time`` () : Task = task { + let! exitCode = fixture.RunFsiCheckAsync (fixture.ScriptPath ("Nullable.OutputAsInput.fsx")) + Assert.NotEqual (0, exitCode) + } + + [] + member _.``Nullable rejects input type as output at compile time`` () : Task = task { + let! exitCode = fixture.RunFsiCheckAsync (fixture.ScriptPath ("Nullable.InputAsOutput.fsx")) + Assert.NotEqual (0, exitCode) + } + + [] + member _.``StructNullable rejects output type as input at compile time`` () : Task = task { + let! exitCode = fixture.RunFsiCheckAsync (fixture.ScriptPath ("StructNullable.OutputAsInput.fsx")) + Assert.NotEqual (0, exitCode) + } + + [] + member _.``StructNullable rejects input type as output at compile time`` () : Task = task { + let! exitCode = fixture.RunFsiCheckAsync (fixture.ScriptPath ("StructNullable.InputAsOutput.fsx")) + Assert.NotEqual (0, exitCode) + } diff --git a/tests/FSharp.Data.GraphQL.Tests/Variables and Inputs/InputComplexTests.fs b/tests/FSharp.Data.GraphQL.Tests/Variables and Inputs/InputComplexTests.fs index 954ace7ec..1e7053574 100644 --- a/tests/FSharp.Data.GraphQL.Tests/Variables and Inputs/InputComplexTests.fs +++ b/tests/FSharp.Data.GraphQL.Tests/Variables and Inputs/InputComplexTests.fs @@ -46,7 +46,7 @@ type TestInput = optArr : string option array option voptArr : string option array voption } // string voption array voption is too hard to implement -let InputArrayOf (innerDef : #TypeDef<'Val>) : ListOfDef<'Val, 'Val array> = ListOf innerDef +let InputArrayOf (innerDef : #InputDef<'Val>) : InputDef<'Val array> = ListOf (innerDef :> InputDef<'Val>) let TestInputObject = Define.InputObject ( diff --git a/tests/FSharp.Data.GraphQL.Tests/Variables and Inputs/InputNestedTests.fs b/tests/FSharp.Data.GraphQL.Tests/Variables and Inputs/InputNestedTests.fs index 69fc2b825..de5730092 100644 --- a/tests/FSharp.Data.GraphQL.Tests/Variables and Inputs/InputNestedTests.fs +++ b/tests/FSharp.Data.GraphQL.Tests/Variables and Inputs/InputNestedTests.fs @@ -14,7 +14,7 @@ open FSharp.Data.GraphQL.Types open FSharp.Data.GraphQL.Parser open FSharp.Data.GraphQL.Shared -let InputArrayOf (innerDef : #TypeDef<'Val>) : ListOfDef<'Val, 'Val array> = ListOf innerDef +let InputArrayOf (innerDef : #InputDef<'Val>) : InputDef<'Val array> = ListOf (innerDef :> InputDef<'Val>) let TestInputObject = InputComplexTests.TestInputObject From 24902f162aebe31aab55f5692d17f987c86e17a7 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Sun, 17 May 2026 23:08:59 +0200 Subject: [PATCH 3/9] Pin CI workflows and build script to .NET SDK 10.0.300 (#578) Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Andrii Chebukin --- .github/workflows/publish-ci.yml | 2 +- .github/workflows/publish-release.yml | 2 +- .github/workflows/pull-request.yml | 2 +- build/Program.fs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish-ci.yml b/.github/workflows/publish-ci.yml index f31487b5c..e141251e7 100644 --- a/.github/workflows/publish-ci.yml +++ b/.github/workflows/publish-ci.yml @@ -8,7 +8,7 @@ on: env: DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 DOTNET_NOLOGO: true - DOTNET_SDK_VERSION: 10.0.202 + DOTNET_SDK_VERSION: 10.0.300 jobs: publish: diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index d4df8454f..a73e62012 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -9,7 +9,7 @@ env: DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 DOTNET_NOLOGO: true SLEEP_DURATION: 60 - DOTNET_SDK_VERSION: 10.0.202 + DOTNET_SDK_VERSION: 10.0.300 jobs: publish: diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 07356a39c..7befa633e 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -21,7 +21,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-22.04, windows-latest, macOS-latest] - dotnet: [10.0.202] + dotnet: [10.0.300] runs-on: ${{ matrix.os }} steps: diff --git a/build/Program.fs b/build/Program.fs index f23d68415..9624a0470 100644 --- a/build/Program.fs +++ b/build/Program.fs @@ -30,7 +30,7 @@ let ctx = Context.forceFakeContext () let embedAll = ctx.Arguments |> List.exists (fun arg -> arg = BuildArguments.EmbedAll) module DotNetCli = - let setVersion (o : DotNet.Options) = { o with Version = Some "10.0.202" } + let setVersion (o : DotNet.Options) = { o with Version = Some "10.0.300" } let setRestoreOptions (o : DotNet.RestoreOptions) = o.WithCommon setVersion let configurationString = Environment.environVarOrDefault "CONFIGURATION" "Release" From 49f6f49f0c6ff7ce62b25d8e9399b2f603e9bcf3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 17 May 2026 14:45:37 +0000 Subject: [PATCH 4/9] ci: publish test results to pull request discussions Agent-Logs-Url: https://github.com/fsprojects/FSharp.Data.GraphQL/sessions/ae314b8b-9c8a-4f87-a8b0-b77c4bfa2cef Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com> --- .github/workflows/publish-test-results.yml | 43 ++++++++++++++++++++++ .github/workflows/pull-request.yml | 18 +++++++++ build/Program.fs | 9 ++++- 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/publish-test-results.yml diff --git a/.github/workflows/publish-test-results.yml b/.github/workflows/publish-test-results.yml new file mode 100644 index 000000000..0d87a2438 --- /dev/null +++ b/.github/workflows/publish-test-results.yml @@ -0,0 +1,43 @@ +name: Publish Test Results + +on: + workflow_run: + workflows: ["Build and Test"] + types: + - completed + +permissions: {} + +jobs: + test-results: + if: github.event.workflow_run.conclusion != 'skipped' && github.event.workflow_run.event == 'pull_request' + name: Test Results + runs-on: ubuntu-latest + + permissions: + actions: read + checks: write + pull-requests: write + + steps: + - name: Download event file + uses: dawidd6/action-download-artifact@v4 + with: + run_id: ${{ github.event.workflow_run.id }} + path: artifacts + name: EventFile + + - name: Download test results + uses: dawidd6/action-download-artifact@v4 + with: + run_id: ${{ github.event.workflow_run.id }} + path: test-results + pattern: test-results-* + + - name: Publish test results + uses: EnricoMi/publish-unit-test-result-action@v2 + with: + commit: ${{ github.event.workflow_run.head_sha }} + event_file: artifacts/event.json + event_name: ${{ github.event.workflow_run.event }} + files: "test-results/**/*.trx" diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 7befa633e..8a81d9413 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -15,6 +15,17 @@ env: DOTNET_NOLOGO: true jobs: + event_file: + if: github.event_name == 'pull_request' + name: Publish event file + runs-on: ubuntu-latest + steps: + - name: Upload event file + uses: actions/upload-artifact@v4 + with: + name: EventFile + path: ${{ github.event_path }} + build: strategy: @@ -50,3 +61,10 @@ jobs: - name: Build and run integration tests run: dotnet run --project build/Build.fsproj --launch-profile BuildAndTest + + - name: Upload test results + if: always() + uses: actions/upload-artifact@v4 + with: + name: test-results-${{ matrix.os }} + path: test-results diff --git a/build/Program.fs b/build/Program.fs index 9624a0470..2a60acd1f 100644 --- a/build/Program.fs +++ b/build/Program.fs @@ -98,12 +98,17 @@ let startGraphQLServer (project : string) port (streamRef : DataRef) = System.Threading.Thread.Sleep (2000) -let runTests (project : string) (args : string) = +let runTests (project : string) = + let projectName = Path.GetFileNameWithoutExtension project + let resultsFileName = $"{projectName}.trx" + DotNet.test (fun options -> { options with NoBuild = true + Logger = Some $"trx;LogFileName={resultsFileName}" + ResultsDirectory = Some "test-results" Framework = Some DotNetMoniker Configuration = configuration MSBuildParams = { @@ -184,7 +189,7 @@ let unitTestsProjectPath = let [] RunUnitTestsTarget = "RunUnitTests" Target.create RunUnitTestsTarget <| fun _ -> - runTests unitTestsProjectPath "" + runTests unitTestsProjectPath let prepareDocGen () = Shell.rm "docs/release-notes.md" From c3c9adf8859aef74a224acfda6e1a734dd0e3129 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 17 May 2026 14:46:32 +0000 Subject: [PATCH 5/9] ci: tighten workflow permissions and resolve event file path Agent-Logs-Url: https://github.com/fsprojects/FSharp.Data.GraphQL/sessions/ae314b8b-9c8a-4f87-a8b0-b77c4bfa2cef Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com> --- .github/workflows/publish-test-results.yml | 16 +++++++++++++++- .github/workflows/pull-request.yml | 6 ++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-test-results.yml b/.github/workflows/publish-test-results.yml index 0d87a2438..47d45c23b 100644 --- a/.github/workflows/publish-test-results.yml +++ b/.github/workflows/publish-test-results.yml @@ -34,10 +34,24 @@ jobs: path: test-results pattern: test-results-* + - name: Resolve event file path + id: event_file + shell: pwsh + run: | + $eventFilePath = + Get-ChildItem -Path artifacts -Filter event.json -Recurse | + Select-Object -First 1 -ExpandProperty FullName + + if ($null -eq $eventFilePath) { + throw "event.json file was not found in downloaded artifacts" + } + + "path=$eventFilePath" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append + - name: Publish test results uses: EnricoMi/publish-unit-test-result-action@v2 with: commit: ${{ github.event.workflow_run.head_sha }} - event_file: artifacts/event.json + event_file: ${{ steps.event_file.outputs.path }} event_name: ${{ github.event.workflow_run.event }} files: "test-results/**/*.trx" diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 8a81d9413..8ec033e43 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -14,11 +14,15 @@ env: DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 DOTNET_NOLOGO: true +permissions: {} + jobs: event_file: if: github.event_name == 'pull_request' name: Publish event file runs-on: ubuntu-latest + permissions: + contents: read steps: - name: Upload event file uses: actions/upload-artifact@v4 @@ -27,6 +31,8 @@ jobs: path: ${{ github.event_path }} build: + permissions: + contents: read strategy: fail-fast: false From a347a1c38707288ab09d28911f7f05925c51c76b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 17 May 2026 14:47:37 +0000 Subject: [PATCH 6/9] ci: update action-download-artifact to v6 Agent-Logs-Url: https://github.com/fsprojects/FSharp.Data.GraphQL/sessions/ae314b8b-9c8a-4f87-a8b0-b77c4bfa2cef Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com> --- .github/workflows/publish-test-results.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-test-results.yml b/.github/workflows/publish-test-results.yml index 47d45c23b..3187e328e 100644 --- a/.github/workflows/publish-test-results.yml +++ b/.github/workflows/publish-test-results.yml @@ -21,14 +21,14 @@ jobs: steps: - name: Download event file - uses: dawidd6/action-download-artifact@v4 + uses: dawidd6/action-download-artifact@v6 with: run_id: ${{ github.event.workflow_run.id }} path: artifacts name: EventFile - name: Download test results - uses: dawidd6/action-download-artifact@v4 + uses: dawidd6/action-download-artifact@v6 with: run_id: ${{ github.event.workflow_run.id }} path: test-results From 80c801b0e5b034d7049619cbd1076499f0cff9cf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 17 May 2026 18:26:20 +0000 Subject: [PATCH 7/9] ci: tolerate missing test-result artifacts in publish workflow Agent-Logs-Url: https://github.com/fsprojects/FSharp.Data.GraphQL/sessions/aa451f1b-8f2c-4148-b6fe-ac4d6356af9f Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com> --- .github/workflows/publish-test-results.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/publish-test-results.yml b/.github/workflows/publish-test-results.yml index 3187e328e..0a28ba910 100644 --- a/.github/workflows/publish-test-results.yml +++ b/.github/workflows/publish-test-results.yml @@ -33,6 +33,7 @@ jobs: run_id: ${{ github.event.workflow_run.id }} path: test-results pattern: test-results-* + if_no_artifact_found: warn - name: Resolve event file path id: event_file @@ -49,6 +50,7 @@ jobs: "path=$eventFilePath" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append - name: Publish test results + if: ${{ hashFiles('test-results/**/*.trx') != '' }} uses: EnricoMi/publish-unit-test-result-action@v2 with: commit: ${{ github.event.workflow_run.head_sha }} From 857933c8d8e071b66931f86f595f2212b0a20e53 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 17 May 2026 18:35:29 +0000 Subject: [PATCH 8/9] build: emit trx for introspection update test target Agent-Logs-Url: https://github.com/fsprojects/FSharp.Data.GraphQL/sessions/75e24ea8-3ef8-4ff9-b896-387e88504c2a Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com> --- build/Program.fs | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/build/Program.fs b/build/Program.fs index 2a60acd1f..ba1b999dd 100644 --- a/build/Program.fs +++ b/build/Program.fs @@ -169,18 +169,36 @@ let integrationTestsProjectPath = let [] UpdateIntrospectionFileTarget = "UpdateIntrospectionFile" Target.create UpdateIntrospectionFileTarget <| fun _ -> - integrationTestsProjectPath - |> DotNet.test (fun options -> { - options with - Framework = Some DotNetMoniker - Configuration = configuration - Common = { DotNetCli.setVersion options.Common with CustomParams = Some "--filter FullyQualifiedName~IntrospectionUpdateTests" } - MSBuildParams = { - options.MSBuildParams with - DisableInternalBinLog = true - Verbosity = Some Normal + let projectName = Path.GetFileNameWithoutExtension integrationTestsProjectPath + let resultsFileName = $"{projectName}.trx" + + DotNet.test + (fun options -> + { + options with + NoBuild = true + Logger = Some $"trx;LogFileName={resultsFileName}" + ResultsDirectory = Some "test-results" + Framework = Some DotNetMoniker + Configuration = configuration + Common = { + options.Common with + CustomParams = Some "--filter FullyQualifiedName~IntrospectionUpdateTests" + } + MSBuildParams = { + options.MSBuildParams with + DisableInternalBinLog = true + Verbosity = Some Normal + Properties = [ + if embedAll then + ("DebugType", "embedded") + ("EmbedAllSources", "true") + ] + } } - }) + |> _.WithRedirectOutput(true) + |> _.WithCommon(DotNetCli.setVersion)) + integrationTestsProjectPath let unitTestsProjectPath = "tests" From 1cf3cef59e0e52deedba5449176c6c0f680b951b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 18 May 2026 09:14:45 +0000 Subject: [PATCH 9/9] ci: fix artifact filter and enable explicit PR comment mode Agent-Logs-Url: https://github.com/fsprojects/FSharp.Data.GraphQL/sessions/313ed2f1-9407-4f24-8c8b-a0e2663bc4ee Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com> --- .github/workflows/publish-test-results.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-test-results.yml b/.github/workflows/publish-test-results.yml index 0a28ba910..5de1f3a10 100644 --- a/.github/workflows/publish-test-results.yml +++ b/.github/workflows/publish-test-results.yml @@ -32,7 +32,8 @@ jobs: with: run_id: ${{ github.event.workflow_run.id }} path: test-results - pattern: test-results-* + name: ^test-results-.* + name_is_regexp: true if_no_artifact_found: warn - name: Resolve event file path @@ -54,6 +55,7 @@ jobs: uses: EnricoMi/publish-unit-test-result-action@v2 with: commit: ${{ github.event.workflow_run.head_sha }} + comment_mode: always event_file: ${{ steps.event_file.outputs.path }} event_name: ${{ github.event.workflow_run.event }} files: "test-results/**/*.trx"