diff --git a/tests/FSharp.Data.GraphQL.Benchmarks/ComplexExecutionBenchmark.fs b/tests/FSharp.Data.GraphQL.Benchmarks/ComplexExecutionBenchmark.fs new file mode 100644 index 000000000..c9e934fb5 --- /dev/null +++ b/tests/FSharp.Data.GraphQL.Benchmarks/ComplexExecutionBenchmark.fs @@ -0,0 +1,14 @@ +/// The MIT License (MIT) +/// Copyright (c) 2016 Bazinga Technologies Inc +module FSharp.Data.GraphQL.ComplexExecutionBenchmark + +#nowarn "40" + +open FSharp.Data.GraphQL +open FSharp.Data.GraphQL.Types +open FSharp.Data.GraphQL.Parser +open BenchmarkDotNet.Attributes +open FSharp.Data.GraphQL.Benchmarks + +[); Jobs.MonoJob; Jobs.CoreJob>] +type ComplexExecutionBenchmark() = class end \ No newline at end of file diff --git a/tests/FSharp.Data.GraphQL.Benchmarks/ComplexSchema.fs b/tests/FSharp.Data.GraphQL.Benchmarks/ComplexSchema.fs new file mode 100644 index 000000000..6f40ee79a --- /dev/null +++ b/tests/FSharp.Data.GraphQL.Benchmarks/ComplexSchema.fs @@ -0,0 +1,212 @@ +namespace FSharp.Data.GraphQL.Benchmarks + +#nowarn "40" + +open System.Linq +open FSharp.Data.GraphQL.Types +open FSharp.Data.GraphQL.Server.Middlewares +open System.Data.Entity +open System.ComponentModel.DataAnnotations +open System.ComponentModel.DataAnnotations.Schema + +[] +type Movie = + { [] MovieId : int + Genres : string + Title : string } + +[] +type Rating = + { [] MovieId : int + [] UserId : int + Rating : decimal + Timestamp : int } + +[] +type Link = + { [] MovieId : int + ImdbId : int + TmdbId : System.Nullable } + +[] +type Tag = + { [] TagId : int + MovieId : int + UserId : int + Tag : string + Timestamp : int } + +[] +type GenomeTag = + { [] TagId : int + Tag : string } + +[] +type GenomeScore = + { [] MovieId : int + [] TagId : int + Relevance : decimal } + +type MovieDbContext() = + inherit DbContext() + + [] + val mutable private movies : DbSet + member this.Movies + with get() = this.movies + and set(value) = this.movies <- value + + [] + val mutable private ratings : DbSet + member this.Ratings + with get() = this.ratings + and set(value) = this.ratings <- value + + [] + val mutable private links : DbSet + member this.Links + with get() = this.links + and set(value) = this.links <- value + + [] + val mutable private tags : DbSet + member this.Tags + with get() = this.tags + and set(value) = this.tags <- value + + [] + val mutable private genomeTags : DbSet + member this.GenomeTags + with get() = this.genomeTags + and set(value) = this.genomeTags <- value + + [] + val mutable private genomeScores : DbSet + member this.GenomeScores + with get() = this.genomeScores + and set(value) = this.genomeScores <- value + +module ComplexSchemaDefinition = + let Context = new MovieDbContext() + + let rec Rating = + Define.Object( + name = "Rating", + isTypeOf = (fun o -> o :? Rating), + fieldsFn = fun () -> + [ Define.Field("movieId", Int, resolve = fun _ (r : Rating) -> r.MovieId) + Define.Field("movie", Movie, resolve = fun _ (r : Rating) -> query { + for movie in Context.Movies do + find (r.MovieId = movie.MovieId) }) + Define.Field("userId", Int, resolve = fun _ (r : Rating) -> r.UserId) + Define.Field("rating", Float, resolve = fun _ (r : Rating) -> System.Convert.ToDouble(r.Rating)) + Define.Field("timestamp", Int, resolve = fun _ (r : Rating) -> r.Timestamp) ]) + + and Link = + Define.Object( + name = "Link", + isTypeOf = (fun o -> o :? Link), + fieldsFn = fun () -> + [ Define.Field("movieId", Int, resolve = fun _ (l : Link) -> l.MovieId) + Define.Field("movie", Movie, resolve = fun _ (l : Link) -> query { + for movie in Context.Movies do + find (l.MovieId = movie.MovieId) }) + Define.Field("imdbId", Int, resolve = fun _ (l : Link) -> l.ImdbId) + Define.Field("tmdbId", Nullable Int, resolve = fun _ (l : Link) -> l.TmdbId |> Option.ofNullable) ]) + + and Tag = + Define.Object( + name = "Tag", + isTypeOf = (fun o -> o :? Tag), + fieldsFn = fun () -> + [ Define.Field("tagId", Int, resolve = fun _ (t : Tag) -> t.TagId) + Define.Field("movieId", Int, resolve = fun _ (t : Tag) -> t.MovieId) + Define.Field("movie", Movie, resolve = fun _ (t : Tag) -> query { + for movie in Context.Movies do + find (t.MovieId = movie.MovieId) }) + Define.Field("userId", Int, resolve = fun _ (t : Tag) -> t.UserId) + Define.Field("timestamp", Int, resolve = fun _ (t : Tag) -> t.Timestamp) ]) + + and GenomeTag = + Define.Object( + name = "GenomeTag", + isTypeOf = (fun o -> o :? GenomeTag), + fieldsFn = fun () -> + [ Define.Field("tagId", Int, resolve = fun _ (gn : GenomeTag) -> gn.TagId) + Define.Field("tag", Tag, resolve = fun _ (gn : GenomeTag) -> query { + for tag in Context.Tags do + find (gn.TagId = tag.TagId) }) + Define.Field("value", String, resolve = fun _ (gn : GenomeTag) -> gn.Tag) ]) + + and GenomeScore = + Define.Object( + name = "GenomeScore", + isTypeOf = (fun o -> o :? GenomeScore), + fieldsFn = fun () -> + [ Define.Field("movieId", Int, resolve = fun _ (gs : GenomeScore) -> gs.MovieId) + Define.Field("movie", Movie, resolve = fun _ (gs : GenomeScore) -> query { + for movie in Context.Movies do + find (gs.MovieId = movie.MovieId) }) + Define.Field("tagId", Int, resolve = fun _ (gs : GenomeScore) -> gs.TagId) + Define.Field("tag", Tag, resolve = fun _ (gs : GenomeScore) -> query { + for tag in Context.Tags do + find (gs.TagId = tag.TagId) }) + Define.Field("relevance", Float, resolve = fun _ (gs : GenomeScore) -> System.Convert.ToDouble(gs.Relevance)) ]) + + and Movie = + Define.Object( + name = "Movie", + isTypeOf = (fun o -> o :? Movie), + fieldsFn = fun () -> + [ Define.Field("movieId", Int, resolve = fun _ (m : Movie) -> m.MovieId) + Define.Field("title", String, resolve = fun _ (m : Movie) -> m.Title) + Define.Field("genres", ListOf String, resolve = fun _ (m : Movie) -> m.Genres.Split('|')) + Define.Field( + "ratings", + ListOf Rating, + args = [ Define.Input("userId", Nullable Int) ], + resolve = fun ctx (m : Movie) -> + let ratings = query { + for rating in Context.Ratings do + where (rating.MovieId = m.MovieId) + select rating } + match ctx.Arg("userId") with + | Some userId -> query { + for rating in ratings do + where (rating.UserId = userId) + select rating } + | None -> ratings) + Define.Field("links", ListOf Link, resolve = fun _ (m : Movie) -> query { + for link in Context.Links do + where (link.MovieId = m.MovieId) + select link }) + Define.Field( + "tags", + ListOf Tag, + args = [ Define.Input("userId", Nullable Int) ], + resolve = fun ctx (m : Movie) -> + let tags = query { + for tag in Context.Tags do + where (tag.MovieId = m.MovieId) + select tag } + match ctx.Arg("userId") with + | Some userId -> query { + for tag in tags do + where (tag.UserId = userId) + select tag } + | None -> tags) + Define.Field( + "genomeScores", + ListOf GenomeScore, + args = [ Define.Input("tagId", Nullable Tag) ], + resolve = fun ctx (m : Movie) -> + let scores = query { + for score in Context.GenomeScores do + where (score.MovieId = m.MovieId) + select score } + match ctx.Arg("tagId") with + | Some tagId -> query { + for score in scores do + where (score.TagId = tagId) + select score } + | None -> scores) ]) \ No newline at end of file diff --git a/tests/FSharp.Data.GraphQL.Benchmarks/FSharp.Data.GraphQL.Benchmarks.fsproj b/tests/FSharp.Data.GraphQL.Benchmarks/FSharp.Data.GraphQL.Benchmarks.fsproj index f7292a3e3..03e466f0e 100644 --- a/tests/FSharp.Data.GraphQL.Benchmarks/FSharp.Data.GraphQL.Benchmarks.fsproj +++ b/tests/FSharp.Data.GraphQL.Benchmarks/FSharp.Data.GraphQL.Benchmarks.fsproj @@ -1,19 +1,21 @@ - Exe netcoreapp2.0;net47 - false - true true true - full + Full $(DefineConstants);NETSTANDARD2_0 + + + + + @@ -22,15 +24,13 @@ + + - - - - - + \ No newline at end of file