-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Included and fixed
FSharp.Data.GraphQL.Tests.Sql
- Loading branch information
1 parent
b904b04
commit b7cbcf9
Showing
9 changed files
with
157 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
30 changes: 17 additions & 13 deletions
30
tests/FSharp.Data.GraphQL.Tests.Sql/FSharp.Data.GraphQL.Tests.Sql.fsproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,29 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project Sdk="FSharp.NET.Sdk;Microsoft.NET.Sdk"> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net47</TargetFrameworks> | ||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems> | ||
<TargetFramework>$(DotNetVersion)</TargetFramework> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
<GenerateProgramFile>false</GenerateProgramFile> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="AssemblyInfo.fs" /> | ||
<Compile Include="Helpers.fs" /> | ||
<Compile Include="LinqToSqlTests.fs" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" /> | ||
<PackageReference Include="BenchmarkDotNet" /> | ||
<PackageReference Include="SQLProvider" /> | ||
<PackageReference Include="Validus" /> | ||
<PackageReference Include="xunit" /> | ||
<PackageReference Include="xunit.runner.utility" /> | ||
<PackageReference Include="xunit.runner.visualstudio" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FSharp.NET.Sdk" Version="1.0.*" PrivateAssets="All" /> | ||
<Compile Include="Helpers.fs" /> | ||
<Compile Include="LinqToSqlTests.fs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\FSharp.Data.GraphQL.Shared\FSharp.Data.GraphQL.Shared.fsproj" /> | ||
<ProjectReference Include="..\..\src\FSharp.Data.GraphQL.Server\FSharp.Data.GraphQL.Server.fsproj" /> | ||
</ItemGroup> | ||
<Import Project="..\..\.paket\Paket.Restore.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Db.dataContext.``dbo.OrdersEntity``> ( | ||
"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<Db.dataContext.``dbo.CustomersEntity``> ( | ||
"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) ]) | ||
|
||
[<Fact>] | ||
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) | ||
() | ||
let db = Db.GetDataContext () | ||
let executor = Executor<Db.dataContext> (schema) | ||
let result = sync <| executor.AsyncExecute (query, db) | ||
() |
Oops, something went wrong.