From dc3787e0d1eba751f3d0000ae57913684baf8d2f Mon Sep 17 00:00:00 2001 From: Andrii Chebukin Date: Mon, 4 Nov 2024 04:41:30 +0400 Subject: [PATCH 1/4] Included and fixed `FSharp.Data.GraphQL.Tests.Sql` --- FSharp.Data.GraphQL.sln | 41 ++++++---- Packages.props | 1 + src/FSharp.Data.GraphQL.Server/Linq.fs | 24 +++--- .../AssemblyInfo.fs | 41 ---------- .../FSharp.Data.GraphQL.Tests.Sql.fsproj | 30 ++++---- .../FSharp.Data.GraphQL.Tests.Sql/Helpers.fs | 31 ++++---- .../LinqToSqlTests.fs | 75 +++++++++++++------ .../FSharp.Data.GraphQL.Tests.fsproj | 9 +-- .../PropertyTrackingTests.fs | 64 ++++++++-------- 9 files changed, 157 insertions(+), 159 deletions(-) delete mode 100644 tests/FSharp.Data.GraphQL.Tests.Sql/AssemblyInfo.fs diff --git a/FSharp.Data.GraphQL.sln b/FSharp.Data.GraphQL.sln index 1fe3f9cfd..2f9265473 100644 --- a/FSharp.Data.GraphQL.sln +++ b/FSharp.Data.GraphQL.sln @@ -89,6 +89,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{ED8079DD EndProject Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Data.GraphQL.Tests", "tests\FSharp.Data.GraphQL.Tests\FSharp.Data.GraphQL.Tests.fsproj", "{54AAFE43-FA5F-485A-AD40-0240165FC633}" EndProject +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.Data.GraphQL.Tests.Sql", "tests\FSharp.Data.GraphQL.Tests.Sql\FSharp.Data.GraphQL.Tests.Sql.fsproj", "{AC3963FE-427B-4E49-A1BF-EA6B024B2CE8}" +EndProject Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Data.GraphQL.Benchmarks", "tests\FSharp.Data.GraphQL.Benchmarks\FSharp.Data.GraphQL.Benchmarks.fsproj", "{A6A162DF-9FBB-4C2A-913F-FD5FED35A09B}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{B0C25450-74BF-40C2-9E02-09AADBAE2C2F}" @@ -210,6 +212,18 @@ Global {225B0790-C6B6-425C-9093-F359A4C635D3}.Release|x64.Build.0 = Release|Any CPU {225B0790-C6B6-425C-9093-F359A4C635D3}.Release|x86.ActiveCfg = Release|Any CPU {225B0790-C6B6-425C-9093-F359A4C635D3}.Release|x86.Build.0 = Release|Any CPU + {C24EB38E-326C-4770-BB20-9838694EE5E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C24EB38E-326C-4770-BB20-9838694EE5E6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C24EB38E-326C-4770-BB20-9838694EE5E6}.Debug|x64.ActiveCfg = Debug|Any CPU + {C24EB38E-326C-4770-BB20-9838694EE5E6}.Debug|x64.Build.0 = Debug|Any CPU + {C24EB38E-326C-4770-BB20-9838694EE5E6}.Debug|x86.ActiveCfg = Debug|Any CPU + {C24EB38E-326C-4770-BB20-9838694EE5E6}.Debug|x86.Build.0 = Debug|Any CPU + {C24EB38E-326C-4770-BB20-9838694EE5E6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C24EB38E-326C-4770-BB20-9838694EE5E6}.Release|Any CPU.Build.0 = Release|Any CPU + {C24EB38E-326C-4770-BB20-9838694EE5E6}.Release|x64.ActiveCfg = Release|Any CPU + {C24EB38E-326C-4770-BB20-9838694EE5E6}.Release|x64.Build.0 = Release|Any CPU + {C24EB38E-326C-4770-BB20-9838694EE5E6}.Release|x86.ActiveCfg = Release|Any CPU + {C24EB38E-326C-4770-BB20-9838694EE5E6}.Release|x86.Build.0 = Release|Any CPU {6768EA38-1335-4B8E-BC09-CCDED1F9AAF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6768EA38-1335-4B8E-BC09-CCDED1F9AAF6}.Debug|Any CPU.Build.0 = Debug|Any CPU {6768EA38-1335-4B8E-BC09-CCDED1F9AAF6}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -342,18 +356,18 @@ Global {A6A162DF-9FBB-4C2A-913F-FD5FED35A09B}.Release|x64.Build.0 = Release|Any CPU {A6A162DF-9FBB-4C2A-913F-FD5FED35A09B}.Release|x86.ActiveCfg = Release|Any CPU {A6A162DF-9FBB-4C2A-913F-FD5FED35A09B}.Release|x86.Build.0 = Release|Any CPU - {C24EB38E-326C-4770-BB20-9838694EE5E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C24EB38E-326C-4770-BB20-9838694EE5E6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C24EB38E-326C-4770-BB20-9838694EE5E6}.Debug|x64.ActiveCfg = Debug|Any CPU - {C24EB38E-326C-4770-BB20-9838694EE5E6}.Debug|x64.Build.0 = Debug|Any CPU - {C24EB38E-326C-4770-BB20-9838694EE5E6}.Debug|x86.ActiveCfg = Debug|Any CPU - {C24EB38E-326C-4770-BB20-9838694EE5E6}.Debug|x86.Build.0 = Debug|Any CPU - {C24EB38E-326C-4770-BB20-9838694EE5E6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C24EB38E-326C-4770-BB20-9838694EE5E6}.Release|Any CPU.Build.0 = Release|Any CPU - {C24EB38E-326C-4770-BB20-9838694EE5E6}.Release|x64.ActiveCfg = Release|Any CPU - {C24EB38E-326C-4770-BB20-9838694EE5E6}.Release|x64.Build.0 = Release|Any CPU - {C24EB38E-326C-4770-BB20-9838694EE5E6}.Release|x86.ActiveCfg = Release|Any CPU - {C24EB38E-326C-4770-BB20-9838694EE5E6}.Release|x86.Build.0 = Release|Any CPU + {AC3963FE-427B-4E49-A1BF-EA6B024B2CE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AC3963FE-427B-4E49-A1BF-EA6B024B2CE8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AC3963FE-427B-4E49-A1BF-EA6B024B2CE8}.Debug|x64.ActiveCfg = Debug|Any CPU + {AC3963FE-427B-4E49-A1BF-EA6B024B2CE8}.Debug|x64.Build.0 = Debug|Any CPU + {AC3963FE-427B-4E49-A1BF-EA6B024B2CE8}.Debug|x86.ActiveCfg = Debug|Any CPU + {AC3963FE-427B-4E49-A1BF-EA6B024B2CE8}.Debug|x86.Build.0 = Debug|Any CPU + {AC3963FE-427B-4E49-A1BF-EA6B024B2CE8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AC3963FE-427B-4E49-A1BF-EA6B024B2CE8}.Release|Any CPU.Build.0 = Release|Any CPU + {AC3963FE-427B-4E49-A1BF-EA6B024B2CE8}.Release|x64.ActiveCfg = Release|Any CPU + {AC3963FE-427B-4E49-A1BF-EA6B024B2CE8}.Release|x64.Build.0 = Release|Any CPU + {AC3963FE-427B-4E49-A1BF-EA6B024B2CE8}.Release|x86.ActiveCfg = Release|Any CPU + {AC3963FE-427B-4E49-A1BF-EA6B024B2CE8}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -363,6 +377,7 @@ Global {78D10788-601D-4D53-808B-36661911EDD1} = {56640EAF-82A6-4439-AD14-69F44A90DA99} {B837B3ED-83CE-446F-A4E5-44CB06AA6505} = {B0C25450-74BF-40C2-9E02-09AADBAE2C2F} {225B0790-C6B6-425C-9093-F359A4C635D3} = {B0C25450-74BF-40C2-9E02-09AADBAE2C2F} + {C24EB38E-326C-4770-BB20-9838694EE5E6} = {B0C25450-74BF-40C2-9E02-09AADBAE2C2F} {6768EA38-1335-4B8E-BC09-CCDED1F9AAF6} = {BEFD8748-2467-45F9-A4AD-B450B12D5F78} {474179D3-0090-49E9-88F8-2971C0966077} = {BEFD8748-2467-45F9-A4AD-B450B12D5F78} {554A6833-1E72-41B4-AAC1-C19371EC061B} = {BEFD8748-2467-45F9-A4AD-B450B12D5F78} @@ -385,7 +400,7 @@ Global {A8F031E0-2BD5-4BAE-830A-60CBA76A047D} = {600D4BE2-FCE0-4684-AC6F-2DC829B395BA} {6EEA0E79-693F-4D4F-B55B-DB0C64EBDA45} = {600D4BE2-FCE0-4684-AC6F-2DC829B395BA} {7AA3516E-60F5-4969-878F-4E3DCF3E63A3} = {A8F031E0-2BD5-4BAE-830A-60CBA76A047D} - {C24EB38E-326C-4770-BB20-9838694EE5E6} = {B0C25450-74BF-40C2-9E02-09AADBAE2C2F} + {AC3963FE-427B-4E49-A1BF-EA6B024B2CE8} = {ED8079DD-2B06-4030-9F0F-DC548F98E1C4} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C5B9895C-9DF8-4557-8D44-7D0C4C31F86E} diff --git a/Packages.props b/Packages.props index 46ef28beb..5ffff7284 100644 --- a/Packages.props +++ b/Packages.props @@ -83,6 +83,7 @@ + diff --git a/src/FSharp.Data.GraphQL.Server/Linq.fs b/src/FSharp.Data.GraphQL.Server/Linq.fs index be3b2cf3d..4cae50ed6 100644 --- a/src/FSharp.Data.GraphQL.Server/Linq.fs +++ b/src/FSharp.Data.GraphQL.Server/Linq.fs @@ -70,11 +70,11 @@ type Track = type Tracker = /// Leaf of the tree. Marks a direct field/property access with no sub-trees. /// Consists of record and (neglible in this case) list of arguments. - | Direct of Track * Arg list + | Direct of Track * Arg Set /// Marks branched field/property access - property value withh possible sub-trees. /// Consists of record list of arguments used to parametrize GraphQL /// field definition and set of subtrees. - | Compose of Track * Arg list * Set + | Compose of Track * Arg Set * Tracker Set member x.Track = match x with | Direct(track, _) -> track @@ -134,7 +134,7 @@ type CallableArg = Argument: Arg /// List of all other arguments resolved as part of other possible /// applications on the current property track. - AllArguments: Arg list + AllArguments: Arg Set /// Track describing field or property access. Track: Track /// Source type of the property - in case when track returns a collection or option, @@ -219,7 +219,7 @@ let private applyFirst: ArgApplication = fun expression callable -> let orderBy = methods.OrderBy.MakeGenericMethod [| tSource; idAccess.ReturnType |] let ordered = Expression.Call(null, orderBy, expression, idAccess) - let afterOption = callable.AllArguments |> List.tryFind (fun a -> a.Name = "after") + let afterOption = callable.AllArguments |> Seq.tryFind (fun a -> a.Name = "after") let result = match afterOption with | Some(after) -> @@ -244,7 +244,7 @@ let private applyLast: ArgApplication = fun expression callable -> let orderByDesc = methods.OrderByDesc.MakeGenericMethod [| tSource; idAccess.ReturnType |] let ordered = Expression.Call(null, orderByDesc, expression, idAccess) - let beforeOption = callable.AllArguments |> List.tryFind (fun a -> a.Name = "after") + let beforeOption = callable.AllArguments |> Seq.tryFind (fun a -> a.Name = "after") let result = match beforeOption with | Some(before) -> @@ -262,13 +262,13 @@ let private applyLast: ArgApplication = fun expression callable -> /// from a given ExecutionInfo and variables collection let private linqArgs vars info = let argDefs = info.Definition.Args - if Array.isEmpty argDefs then [] + if Array.isEmpty argDefs then Set.empty else let args = info.Ast.Arguments argDefs - |> Array.map (fun a -> (a.Name, a, args |> List.tryFind (fun x -> x.Name = a.Name))) - |> Array.choose (resolveLinqArg vars) - |> Array.toList + |> Seq.map (fun a -> (a.Name, a, args |> List.tryFind (fun x -> x.Name = a.Name))) + |> Seq.choose (resolveLinqArg vars) + |> Set.ofSeq let rec private track set e = match e with @@ -388,7 +388,7 @@ let rec private infoComposer (root: Tracker) (allTracks: Set) : Set Set.filter (fun track -> match track with | Direct (track, _) -> canJoin grandpaType track.ParentType && isOwn track - | x -> failwith <| sprintf "Expected Direct Track, but got %A" x) + | x -> failwithf "Expected Direct Track, but got %A" x) if Set.isEmpty members then root |> Set.singleton else @@ -426,7 +426,7 @@ let rec private getTracks alreadyFound info = | _ -> failwith <| sprintf "Unexpected Resolve Definition Expression!" let tracks = track Set.empty expr - |> Set.map(fun track -> Direct(track, [])) + |> Set.map(fun track -> Direct(track, Set.empty)) |> flip Set.difference alreadyFound match info.Kind with | ResolveDeferred inner -> getTracks alreadyFound inner @@ -568,7 +568,7 @@ and private constructCollection argApplicators tracker (inParam: Expression) : E Expression.Convert(inParam, methods.Type.MakeGenericType [| tSource |]), // `mapFunc` param - (p0 => body ) Expression.Lambda(body, p0)) - let final = args |> List.fold (fun acc (arg: Arg) -> + let final = args |> Set.fold (fun acc (arg: Arg) -> match Map.tryFind (arg.Name.ToLowerInvariant()) argApplicators with | Some apply -> apply acc { AllArguments = args; Argument = arg; Track = track; Fields = fields; Type = tSource } | None -> acc) call diff --git a/tests/FSharp.Data.GraphQL.Tests.Sql/AssemblyInfo.fs b/tests/FSharp.Data.GraphQL.Tests.Sql/AssemblyInfo.fs deleted file mode 100644 index 0189c7080..000000000 --- a/tests/FSharp.Data.GraphQL.Tests.Sql/AssemblyInfo.fs +++ /dev/null @@ -1,41 +0,0 @@ -namespace FSharp.Data.GraphQL.Tests.Sql.AssemblyInfo - -open System.Reflection -open System.Runtime.CompilerServices -open System.Runtime.InteropServices - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[] -[] -[] -[] -[] -[] -[] -[] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [] -[] -[] - -do - () \ No newline at end of file diff --git a/tests/FSharp.Data.GraphQL.Tests.Sql/FSharp.Data.GraphQL.Tests.Sql.fsproj b/tests/FSharp.Data.GraphQL.Tests.Sql/FSharp.Data.GraphQL.Tests.Sql.fsproj index 3b8142cca..346de042e 100644 --- a/tests/FSharp.Data.GraphQL.Tests.Sql/FSharp.Data.GraphQL.Tests.Sql.fsproj +++ b/tests/FSharp.Data.GraphQL.Tests.Sql/FSharp.Data.GraphQL.Tests.Sql.fsproj @@ -1,25 +1,29 @@ - - + + - net47 - false + $(DotNetVersion) true + false + Exe - - true - full - + - - - + + + + + + + + - + + + - \ No newline at end of file diff --git a/tests/FSharp.Data.GraphQL.Tests.Sql/Helpers.fs b/tests/FSharp.Data.GraphQL.Tests.Sql/Helpers.fs index 673000249..3b751046d 100644 --- a/tests/FSharp.Data.GraphQL.Tests.Sql/Helpers.fs +++ b/tests/FSharp.Data.GraphQL.Tests.Sql/Helpers.fs @@ -1,5 +1,5 @@ -/// The MIT License (MIT) -/// Copyright (c) 2016 Bazinga Technologies Inc +// The MIT License (MIT) +// Copyright (c) 2016 Bazinga Technologies Inc [] module Helpers @@ -11,26 +11,23 @@ open FSharp.Data.GraphQL.Types open FSharp.Data.GraphQL.Types.Introspection open FSharp.Data.GraphQL.Execution -let equals (expected : 'x) (actual : 'x) = - Assert.True((actual = expected), sprintf "expected %+A\nbut got %+A" expected actual) -let noErrors (result: IDictionary) = - match result.TryGetValue("errors") with +let equals (expected : 'x) (actual : 'x) = + Assert.True ((actual = expected), sprintf "expected %+A\nbut got %+A" expected actual) +let noErrors (result : IDictionary) = + match result.TryGetValue ("errors") with | true, errors -> failwithf "expected ExecutionResult to have no errors but got %+A" errors | false, _ -> () -let throws<'e when 'e :> exn> (action : unit -> unit) = Assert.Throws<'e>(action) +let throws<'e when 'e :> exn> (action : unit -> unit) = Assert.Throws<'e> (action) let sync = Async.RunSynchronously -let is<'t> (o: obj) = o :? 't -let hasError errMsg (errors: string seq) = - let containsMessage = - errors - |> Seq.exists (fun e -> e.Contains(errMsg)) - Assert.True (containsMessage, sprintf "expected to contain message '%s', but no such message was found. Messages found: %A" errMsg errors) +let is<'t> (o : obj) = o :? 't +let hasError (errMsg : string) (errors : string seq) = + let containsMessage = errors |> Seq.exists (fun e -> e.Contains (errMsg)) + Assert.True (containsMessage, $"expected to contain message '%s{errMsg}', but no such message was found. Messages found: %A{errors}") -let ( Some other | _ -> opt -let undefined (value: 't) = - Assert.True((value = Unchecked.defaultof<'t>), sprintf "Expected value to be undefined, but was: %A" value) - +let undefined (value : 't) = + Assert.True ((value = Unchecked.defaultof<'t>), $"Expected value to be undefined, but was: %A{value}") diff --git a/tests/FSharp.Data.GraphQL.Tests.Sql/LinqToSqlTests.fs b/tests/FSharp.Data.GraphQL.Tests.Sql/LinqToSqlTests.fs index b79290e96..a7fc0e9eb 100644 --- a/tests/FSharp.Data.GraphQL.Tests.Sql/LinqToSqlTests.fs +++ b/tests/FSharp.Data.GraphQL.Tests.Sql/LinqToSqlTests.fs @@ -1,42 +1,71 @@ -/// The MIT License (MIT) -/// Copyright (c) 2016 Bazinga Technologies Inc +// The MIT License (MIT) +// Copyright (c) 2016 Bazinga Technologies Inc module FSharp.Data.GraphQL.Tests.LinqToSqlTests open System open System.Linq open Xunit -open FSharp.Data.TypeProviders +open FSharp.Data.Sql open FSharp.Data.GraphQL open FSharp.Data.GraphQL.Parser open FSharp.Data.GraphQL.Types open FSharp.Data.GraphQL.Execution open FSharp.Data.GraphQL.Linq -type Db = SqlDataConnection<"Server=.;Database=NORTHWND;Trusted_Connection=True;"> +// https://github.com/microsoft/sql-server-samples/blob/master/samples/databases/northwind-pubs/instnwnd.sql +type Db = + SqlDataProvider< + Common.DatabaseProviderTypes.MSSQLSERVER, + "Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Northwnd;Integrated Security=True;Encrypt=False;" + > -let Order = Define.Object("Order", [ - Define.Field("orderId", ID, fun _ (o: Db.ServiceTypes.Orders) -> o.OrderID) - Define.Field("shipAddress", String, fun _ o -> o.ShipAddress) - Define.Field("shipCity", String, fun _ o -> o.ShipCity) - Define.Field("shipCountry", String, fun _ o -> o.ShipCountry) ]) +let OrderType = + Define.Object ( + "Order", + [ + Define.Field ("orderId", IDType, resolve = (fun _ o -> o.OrderId |> string)) + Define.Field ("shipAddress", StringType, resolve = (fun _ o -> o.ShipAddress)) + Define.Field ("shipCity", StringType, resolve = (fun _ o -> o.ShipCity)) + Define.Field ("shipCountry", StringType, resolve = (fun _ o -> o.ShipCountry)) + ] + ) + +let Customer = + Define.Object ( + "Customer", + [ + Define.Field ("customerID", IDType, resolve = (fun _ c -> c.CustomerId)) + Define.Field ("contactName", StringType, resolve = (fun _ c -> c.ContactName)) + Define.Field ("orders", ListOf OrderType, resolve = (fun _ c -> c.``dbo.Orders by CustomerID``)) + ] + ) -let Customer = Define.Object("Customer", [ - Define.Field("customerID", ID, fun _ (c: Db.ServiceTypes.Customers) -> c.CustomerID) - Define.Field("contactName", String, fun _ c -> c.ContactName) - Define.Field("orders", ListOf Order, fun _ c -> c.Orders) ]) - [] let ``LINQ: should create an executable flat SQL query`` () = - let schema = Schema(Define.Object("RootQuery", [ - Define.Field("customers", ListOf Customer, fun ctx (dbContext: Db.ServiceTypes.SimpleDataContextTypes.NORTHWND) -> - let query = ctx.ExecutionPlan.ToLinq(dbContext.Customers) - query |> Seq.toList) ])) - let query = parse """{ + let schema = + Schema ( + Define.Object ( + "RootQuery", + [ + Define.Field ( + "customers", + ListOf Customer, + fun ctx (dbContext : Db.dataContext) -> + let query = dbContext.Dbo.Customers.Apply (ctx.ExecutionInfo, ctx.Variables) + query |> Seq.toList + ) + ] + ) + ) + let query = + parse + """query { customers { contactName - } + } }""" - use db = Db.GetDataContext() - let result = sync <| schema.AsyncExecute(query, db) - () \ No newline at end of file + let db = Db.GetDataContext () + let executor = Executor (schema) + let result = sync <| executor.AsyncExecute (query, db) + () 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 f67afae82..c3b890c9b 100644 --- a/tests/FSharp.Data.GraphQL.Tests/FSharp.Data.GraphQL.Tests.fsproj +++ b/tests/FSharp.Data.GraphQL.Tests/FSharp.Data.GraphQL.Tests.fsproj @@ -5,13 +5,6 @@ true false Exe - - FSharp implementation of Facebook GraphQL query language (Server) - - - - true - portable @@ -35,7 +28,6 @@ - @@ -45,6 +37,7 @@ + diff --git a/tests/FSharp.Data.GraphQL.Tests/PropertyTrackingTests.fs b/tests/FSharp.Data.GraphQL.Tests/PropertyTrackingTests.fs index eaa607a08..fd69c98db 100644 --- a/tests/FSharp.Data.GraphQL.Tests/PropertyTrackingTests.fs +++ b/tests/FSharp.Data.GraphQL.Tests/PropertyTrackingTests.fs @@ -21,39 +21,39 @@ type OuterType = FirstName : string LastName : string NestedCollection : DeepType list } -// + //let private complex name nodes = Direct(name, Set.ofList nodes) //let private leaf name = Direct(name, Set.empty) -//let private collection name nodes = Collection(name, Set.ofList nodes) -// +//let private collection name nodes = Compose(name, Set.empty, Set.ofList nodes) + //let private test expected (Patterns.Lambda(arg, expr))= // let actual = tracker arg expr // actual |> equals expected -// + //[] //let ``Collect getters from properties``() = <@ fun o -> o.X @> |> test (complex "o" [ leaf "X"]) -// + //[] //let ``Collect getters from nested properties``() = <@ fun o -> o.X.Y.Z @> |> test (complex "o" [ (complex "X" [ (complex "Y" [ leaf "Z" ])])]) -// + //[] //let ``Collect getters from mutliple properties``() = <@ fun o -> o.FirstName + " " + o.LastName @> |> test (complex "o" [ leaf "FirstName"; leaf "LastName" ]) -// + //[] //let ``Collect getters from function calls``() = <@ fun o -> string o.X @> |> test (complex "o" [ leaf "X"]) -// + //[] //let ``Collect getters from type coercions``() = // let e : Exprobj> = <@ fun o -> upcast o.X @> // e |> test (complex "o" [ leaf "X"]) -// + //[] //let ``Collect getters from for loops``() = // <@ fun o -> // for i=1 to o.NestedCollection.Length do // () // @> |> test (complex "o" [ (collection "NestedCollection" [ leaf "Length" ])]) -// + //[] //let ``Collect getters from if-else expressions``() = // <@ fun o -> @@ -61,21 +61,21 @@ type OuterType = // then o.FirstName // else o.LastName // @> |> test (complex "o" [ leaf "FirstName"; leaf "LastName" ]) -// + //[] //let ``Collect getters from let statements``() = // <@ fun o -> // let x = o.X // x.Y // @> |> test (complex "o" [ (complex "X" [ leaf "Y" ])]) -// + //[] //let ``Collect getters from mutable assignments``() = // <@ fun o -> // let mutable x = o.FirstName // x <- o.LastName // @> |> test (complex "o" [ leaf "FirstName"; leaf "LastName" ]) -// + //[] //let ``Collect getters from recursive let statements``() = // <@ fun o -> @@ -85,49 +85,49 @@ type OuterType = // | _ -> loop (n-1) a // loop 4 o // @> |> test (complex "o" [ leaf "X"]) -// + //[] //let ``Collect getters from new array``() = // <@ fun o -> [| o.X |] @> |> test (complex "o" [ leaf "X"]) -// + //[] //let ``Collect getters from new delegates``() = // <@ fun o -> // let a y = o.FirstName + y // a // @> |> test (complex "o" [ leaf "FirstName"]) -// + //type TestRecord = { Contained: string } -// + //[] //let ``Collect getters from new records``() = // <@ fun o -> { Contained = o.FirstName } @> |> test (complex "o" [ leaf "FirstName"]) -// + //[] //let ``Collect getters from tuples``() = // <@ fun o -> (o.FirstName, o.LastName) @> |> test (complex "o" [ leaf "FirstName"; leaf "LastName" ]) -// + //type TestDU = TestDU of string * string -// + //[] //let ``Collect getters from discriminated unions``() = // <@ fun o -> TestDU(o.FirstName, o.LastName) @> |> test (complex "o" [ leaf "FirstName"; leaf "LastName" ]) -// + //[] //let ``Collect getters from typed sub-quotes``() = // <@ fun o -> <@ o.FirstName + "x" @> @> |> test (complex "o" [ leaf "FirstName"]) -// + //[] //let ``Collect getters from untyped sub-quotes``() = // <@ fun o -> <@@ o.FirstName + "x" @@> @> |> test (complex "o" [ leaf "FirstName"]) -// + //[] //let ``Collect getters from sequential expressions``() = // <@ fun o -> // o.FirstName // o.LastName // @> |> test (complex "o" [ leaf "FirstName"; leaf "LastName" ]) -// + //[] //let ``Collect getters from try-finally``() = // <@ fun o -> @@ -136,7 +136,7 @@ type OuterType = // finally // o.LastName // @> |> test (complex "o" [ leaf "FirstName"; leaf "LastName" ]) -// + //[] //let ``Collect getters from try-with``() = // <@ fun o -> @@ -145,7 +145,7 @@ type OuterType = // with // | e -> o.LastName + e.Message // @> |> test (complex "o" [ leaf "FirstName"; leaf "LastName" ]) -// + //[] //let ``Collect getters from pattern matches``() = // <@ fun o -> @@ -153,14 +153,14 @@ type OuterType = // | { Y = y } when o.FirstName = "" -> y // | { Y = y } -> y // @> |> test (complex "o" [ (complex "X" [ leaf "Y" ]); leaf "FirstName"; ]) -// + //[] //let ``Collect getters from while loops``() = // <@ fun o -> // while o.FirstName = "" do // o.LastName // @> |> test (complex "o" [ leaf "FirstName"; leaf "LastName" ]) -// + //[] //let ``Collect getters from foreach loops``() = // <@ fun o -> @@ -168,7 +168,7 @@ type OuterType = // let x = i.Y // () // @> |> test (complex "o" [ (collection "NestedCollection" [ leaf "Y" ])]) -// + //[] //let ``Collect getters from repinned field``() = // <@ fun o -> @@ -176,7 +176,7 @@ type OuterType = // let y = x.Y // y // @> |> test (complex "o" [ (complex "X" [ leaf "Y" ])]) -// + //[] //let ``Collect getters from multiple repinned fields``() = // <@ fun o -> @@ -186,9 +186,9 @@ type OuterType = // let z = x2.Y.Z // y // @> |> test (complex "o" [ (complex "X" [ (complex "Y" [ leaf "Z" ])])]) -// + //type OmittedType = { X: int; Y: string } -// + //[] //let ``Doesn't collect getters of objects not being used from root``() = // <@ fun o -> From 6e7e17e836dda0f94997801d0bd7ed72d5b08828 Mon Sep 17 00:00:00 2001 From: Andrii Chebukin Date: Mon, 4 Nov 2024 05:34:16 +0400 Subject: [PATCH 2/4] Fixed `LinqToSqlTests` execution --- Packages.props | 1 + .../FSharp.Data.GraphQL.Tests.Sql.fsproj | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Packages.props b/Packages.props index 5ffff7284..9eb8c969c 100644 --- a/Packages.props +++ b/Packages.props @@ -78,6 +78,7 @@ + diff --git a/tests/FSharp.Data.GraphQL.Tests.Sql/FSharp.Data.GraphQL.Tests.Sql.fsproj b/tests/FSharp.Data.GraphQL.Tests.Sql/FSharp.Data.GraphQL.Tests.Sql.fsproj index 346de042e..48bf50dc5 100644 --- a/tests/FSharp.Data.GraphQL.Tests.Sql/FSharp.Data.GraphQL.Tests.Sql.fsproj +++ b/tests/FSharp.Data.GraphQL.Tests.Sql/FSharp.Data.GraphQL.Tests.Sql.fsproj @@ -3,13 +3,13 @@ $(DotNetVersion) true - false Exe + From 929df7c82491f6acdf1e4281176a06ecccc169a1 Mon Sep 17 00:00:00 2001 From: Andrii Chebukin Date: Tue, 5 Nov 2024 00:21:17 +0400 Subject: [PATCH 3/4] Fixed CI --- FSharp.Data.GraphQL.CI.slnf | 21 +++++++++++++++++++++ build/Program.fs | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 FSharp.Data.GraphQL.CI.slnf diff --git a/FSharp.Data.GraphQL.CI.slnf b/FSharp.Data.GraphQL.CI.slnf new file mode 100644 index 000000000..6bb549f58 --- /dev/null +++ b/FSharp.Data.GraphQL.CI.slnf @@ -0,0 +1,21 @@ +{ + "solution": { + "path": "FSharp.Data.GraphQL.sln", + "projects": [ + "samples\\chat-app\\server\\chat-app.fsproj", + "samples\\relay-book-store\\relay-book-store.fsproj", + "samples\\star-wars-api\\star-wars-api.fsproj", + "src\\FSharp.Data.GraphQL.Client.DesignTime\\FSharp.Data.GraphQL.Client.DesignTime.fsproj", + "src\\FSharp.Data.GraphQL.Client\\FSharp.Data.GraphQL.Client.fsproj", + "src\\FSharp.Data.GraphQL.Server.AspNetCore\\FSharp.Data.GraphQL.Server.AspNetCore.fsproj", + "src\\FSharp.Data.GraphQL.Server.Giraffe\\FSharp.Data.GraphQL.Server.Giraffe.fsproj", + "src\\FSharp.Data.GraphQL.Server.Middleware\\FSharp.Data.GraphQL.Server.Middleware.fsproj", + "src\\FSharp.Data.GraphQL.Server.Oxpecker\\FSharp.Data.GraphQL.Server.Oxpecker.fsproj", + "src\\FSharp.Data.GraphQL.Server.Relay\\FSharp.Data.GraphQL.Server.Relay.fsproj", + "src\\FSharp.Data.GraphQL.Server\\FSharp.Data.GraphQL.Server.fsproj", + "src\\FSharp.Data.GraphQL.Shared\\FSharp.Data.GraphQL.Shared.fsproj", + "tests\\FSharp.Data.GraphQL.Benchmarks\\FSharp.Data.GraphQL.Benchmarks.fsproj", + "tests\\FSharp.Data.GraphQL.Tests\\FSharp.Data.GraphQL.Tests.fsproj" + ] + } +} \ No newline at end of file diff --git a/build/Program.fs b/build/Program.fs index 2a8614175..54fdfc364 100644 --- a/build/Program.fs +++ b/build/Program.fs @@ -74,7 +74,7 @@ Target.create RestoreTarget <| fun _ -> let [] BuildTarget = "Build" Target.create BuildTarget <| fun _ -> - "FSharp.Data.GraphQL.sln" + "FSharp.Data.GraphQL.CI.slnf" |> DotNet.build (fun options -> { options with Configuration = configuration From 855941f1b21d80f3daa6bc274f22372577135722 Mon Sep 17 00:00:00 2001 From: Andrii Chebukin Date: Tue, 5 Nov 2024 00:32:20 +0400 Subject: [PATCH 4/4] fixup! Included and fixed `FSharp.Data.GraphQL.Tests.Sql` --- .../PropertyTrackerTests.fs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/FSharp.Data.GraphQL.Tests/PropertyTrackerTests.fs b/tests/FSharp.Data.GraphQL.Tests/PropertyTrackerTests.fs index 46f48f0b2..eb29042ba 100644 --- a/tests/FSharp.Data.GraphQL.Tests/PropertyTrackerTests.fs +++ b/tests/FSharp.Data.GraphQL.Tests/PropertyTrackerTests.fs @@ -128,10 +128,10 @@ let ``Property tracker can track indirect properties`` () = let expected = Compose ( track null typeof typeof, - [], + Set.empty, Set.ofList [ - Tracker.Direct (track "FirstName" typeof typeof, []) - Tracker.Direct (track "LastName" typeof typeof, []) + Tracker.Direct (track "FirstName" typeof typeof, Set.empty) + Tracker.Direct (track "LastName" typeof typeof, Set.empty) ] ) let actual = tracker ImmutableDictionary.Empty info @@ -161,7 +161,7 @@ let ``Property tracker can correctly jump over properties not being part of the let expected = Compose ( { Name = None; ParentType = typeof; ReturnType = typeof }, - [], + Set.empty, set [ Direct ( { @@ -169,9 +169,9 @@ let ``Property tracker can correctly jump over properties not being part of the ParentType = typeof ReturnType = typeof }, - [] + Set.empty ) - Direct ({ Name = Some "Id"; ParentType = typeof; ReturnType = typeof }, []) + Direct ({ Name = Some "Id"; ParentType = typeof; ReturnType = typeof }, Set.empty) ] )