diff --git a/tests/FSharp.Data.GraphQL.Tests/AbstractionTests.fs b/tests/FSharp.Data.GraphQL.Tests/AbstractionTests.fs index b77b9cff3..e130b04b3 100644 --- a/tests/FSharp.Data.GraphQL.Tests/AbstractionTests.fs +++ b/tests/FSharp.Data.GraphQL.Tests/AbstractionTests.fs @@ -19,58 +19,75 @@ type IPet = end type Dog = - { Name: string; Woofs: bool } + { Name : string + Woofs : bool } + interface IPet with member x.Name = x.Name type Cat = - { Name: string; Meows: bool } + { Name : string + Meows : bool } + interface IPet with member x.Name = x.Name -type Human = { Name: string; } +type Human = { Name : string } type Pet = | DogCase of Dog | CatCase of Cat -let resolvePet = function +let resolvePet = + function | DogCase d -> box d | CatCase c -> upcast c let schemaWithInterface = lazy - let PetType = Define.Interface("Pet", fun () -> [ Define.Field("name", StringType) ]) + let PetType = Define.Interface ("Pet", (fun () -> [ Define.Field ("name", StringType) ])) + let DogType = - Define.Object( - name = "Dog", - isTypeOf = is, - interfaces = [ PetType ], - fields = [ - Define.Field("name", StringType, resolve = fun _ d -> d.Name) - Define.Field("woofs", BooleanType, fun _ d -> d.Woofs) - ]) + Define.Object ( + name = "Dog", + isTypeOf = is, + interfaces = [ PetType ], + fields = + [ Define.Field ("name", StringType, resolve = fun _ d -> d.Name) + Define.Field ("woofs", BooleanType, (fun _ d -> d.Woofs)) ] + ) + let CatType = - Define.Object( - name = "Cat", - isTypeOf = is, - interfaces = [ PetType ], - fields = [ - Define.Field("name", StringType, resolve = fun _ c -> c.Name) - Define.Field("meows", BooleanType, fun _ c -> c.Meows) - ]) + Define.Object ( + name = "Cat", + isTypeOf = is, + interfaces = [ PetType ], + fields = + [ Define.Field ("name", StringType, resolve = fun _ c -> c.Name) + Define.Field ("meows", BooleanType, (fun _ c -> c.Meows)) ] + ) + let schema = - Schema( - query = Define.Object("Query", fun () -> - [ - Define.Field("pets", ListOf PetType, fun _ _ -> [ { Name = "Odie"; Woofs = true } :> IPet ; upcast { Name = "Garfield"; Meows = false } ]) - ]), - config = { SchemaConfig.Default with Types = [CatType; DogType] }) - Executor(schema) + Schema ( + query = + Define.Object ( + "Query", + fun () -> + [ Define.Field ( + "pets", + ListOf PetType, + fun _ _ -> [ { Name = "Odie"; Woofs = true } :> IPet; upcast { Name = "Garfield"; Meows = false } ] + ) ] + ), + config = { SchemaConfig.Default with Types = [ CatType; DogType ] } + ) + + Executor (schema) [] let ``Execute handles execution of abstract types: isTypeOf is used to resolve runtime type for Interface`` () = - let query = """{ + let query = + """{ pets { name ... on Dog { @@ -81,25 +98,26 @@ let ``Execute handles execution of abstract types: isTypeOf is used to resolve r } } }""" - let result = sync <| schemaWithInterface.Value.AsyncExecute(parse query) + + let result = sync <| schemaWithInterface.Value.AsyncExecute (parse query) + let expected = - NameValueLookup.ofList [ - "pets", upcast [ - NameValueLookup.ofList [ - "name", "Odie" :> obj - "woofs", upcast true ] :> obj - upcast NameValueLookup.ofList [ - "name", "Garfield" :> obj - "meows", upcast false]]] + NameValueLookup.ofList + [ "pets", + upcast + [ NameValueLookup.ofList [ "name", "Odie" :> obj; "woofs", upcast true ] :> obj + NameValueLookup.ofList [ "name", "Garfield" :> obj; "meows", upcast false ] ] ] + match result with - | Direct(data, errors) -> + | Direct (data, errors) -> empty errors data |> equals (upcast expected) - | _ -> fail "Expected a direct GQLResponse" + | _ -> fail "Expected a direct GQLResponse" [] let ``Execute handles execution of abstract types: absent field resolution produces errors for Interface`` () = - let query = """{ + let query = + """{ pets { name ... on Dog { @@ -112,18 +130,27 @@ let ``Execute handles execution of abstract types: absent field resolution produ } } }""" - let result = sync <| schemaWithInterface.Value.AsyncExecute(parse query) + + let result = sync <| schemaWithInterface.Value.AsyncExecute (parse query) + let expected = - [{ Message = "Field 'unknownField1' is not defined in schema type 'Dog'."; Path = Include ["pets"; "unknownField1"]; Locations = Skip; Extensions = Skip } - { Message = "Field 'unknownField2' is not defined in schema type 'Cat'."; Path = Include ["pets"; "unknownField2"]; Locations = Skip; Extensions = Skip }] + [ { Message = "Field 'unknownField1' is not defined in schema type 'Dog'." + Path = Include [ "pets"; "unknownField1" ] + Locations = Skip + Extensions = Skip } + { Message = "Field 'unknownField2' is not defined in schema type 'Cat'." + Path = Include [ "pets"; "unknownField2" ] + Locations = Skip + Extensions = Skip } ] + match result with - | RequestError(errors) -> - equals expected errors - | _ -> fail "Expected a requets error GQLResponse" + | RequestError (errors) -> equals expected errors + | _ -> fail "Expected a requets error GQLResponse" [] let ``Execute handles execution of abstract types: absent type resolution produces errors for Interface`` () = - let query = """{ + let query = + """{ pets { name ... on UnknownDog { @@ -136,46 +163,62 @@ let ``Execute handles execution of abstract types: absent type resolution produc } } }""" - let result = sync <| schemaWithInterface.Value.AsyncExecute(parse query) + + let result = sync <| schemaWithInterface.Value.AsyncExecute (parse query) + let expected = - [{ Message = "Field 'unknownField2' is not defined in schema type 'Cat'."; Path = Include ["pets"; "unknownField2"]; Locations = Skip; Extensions = Skip } - { Message = "Inline fragment has type condition 'UnknownDog', but that type does not exist in the schema."; Path = Include ["pets"]; Locations = Skip; Extensions = Skip }] + [ { Message = "Field 'unknownField2' is not defined in schema type 'Cat'." + Path = Include [ "pets"; "unknownField2" ] + Locations = Skip + Extensions = Skip } + { Message = "Inline fragment has type condition 'UnknownDog', but that type does not exist in the schema." + Path = Include [ "pets" ] + Locations = Skip + Extensions = Skip } ] + match result with - | RequestError(errors) -> - equals expected errors - | _ -> fail "Expected a requets error GQLResponse" + | RequestError (errors) -> equals expected errors + | _ -> fail "Expected a requets error GQLResponse" let schemaWithUnion = lazy let DogType = - Define.Object( - name = "Dog", - isTypeOf = is, - fields = [ - Define.AutoField("name", StringType) - Define.AutoField("woofs", BooleanType) - ]) + Define.Object ( + name = "Dog", + isTypeOf = is, + fields = [ Define.AutoField ("name", StringType); Define.AutoField ("woofs", BooleanType) ] + ) + let CatType = - Define.Object( - name = "Cat", - isTypeOf = is, - fields = [ - Define.AutoField("name", StringType) - Define.AutoField("meows", BooleanType) - ]) - let PetType = Define.Union("Pet", [ DogType; CatType ], resolvePet) + Define.Object ( + name = "Cat", + isTypeOf = is, + fields = [ Define.AutoField ("name", StringType); Define.AutoField ("meows", BooleanType) ] + ) + + let PetType = Define.Union ("Pet", [ DogType; CatType ], resolvePet) + let schema = - Schema( - query = Define.Object("Query", fun () -> - [ - Define.Field("pets", ListOf PetType, fun _ _ -> [ DogCase { Name = "Odie"; Woofs = true }; CatCase { Name = "Garfield"; Meows = false } ]) - ])) - Executor(schema) + Schema ( + query = + Define.Object ( + "Query", + fun () -> + [ Define.Field ( + "pets", + ListOf PetType, + fun _ _ -> [ DogCase { Name = "Odie"; Woofs = true }; CatCase { Name = "Garfield"; Meows = false } ] + ) ] + ) + ) + + Executor (schema) [] let ``Execute handles execution of abstract types: isTypeOf is used to resolve runtime type for Union`` () = - let query = """{ + let query = + """{ pets { ... on Dog { name @@ -187,25 +230,26 @@ let ``Execute handles execution of abstract types: isTypeOf is used to resolve r } } }""" - let result = sync <| schemaWithUnion.Value.AsyncExecute(parse query) + + let result = sync <| schemaWithUnion.Value.AsyncExecute (parse query) + let expected = - NameValueLookup.ofList [ - "pets", upcast [ - NameValueLookup.ofList [ - "name", "Odie" :> obj - "woofs", upcast true ] :> obj - upcast NameValueLookup.ofList [ - "name", "Garfield" :> obj - "meows", upcast false]]] + NameValueLookup.ofList + [ "pets", + upcast + [ NameValueLookup.ofList [ "name", "Odie" :> obj; "woofs", upcast true ] :> obj + NameValueLookup.ofList [ "name", "Garfield" :> obj; "meows", upcast false ] ] ] + match result with - | Direct(data, errors) -> + | Direct (data, errors) -> empty errors data |> equals (upcast expected) - | _ -> fail "Expected a direct GQLResponse" + | _ -> fail "Expected a direct GQLResponse" [] let ``Execute handles execution of abstract types: absent field resolution produces errors for Union`` () = - let query = """{ + let query = + """{ pets { name ... on Dog { @@ -218,18 +262,27 @@ let ``Execute handles execution of abstract types: absent field resolution produ } } }""" - let result = sync <| schemaWithInterface.Value.AsyncExecute(parse query) + + let result = sync <| schemaWithInterface.Value.AsyncExecute (parse query) + let expected = - [{ Message = "Field 'unknownField1' is not defined in schema type 'Dog'."; Path = Include ["pets"; "unknownField1"]; Locations = Skip; Extensions = Skip } - { Message = "Field 'unknownField2' is not defined in schema type 'Cat'."; Path = Include ["pets"; "unknownField2"]; Locations = Skip; Extensions = Skip }] + [ { Message = "Field 'unknownField1' is not defined in schema type 'Dog'." + Path = Include [ "pets"; "unknownField1" ] + Locations = Skip + Extensions = Skip } + { Message = "Field 'unknownField2' is not defined in schema type 'Cat'." + Path = Include [ "pets"; "unknownField2" ] + Locations = Skip + Extensions = Skip } ] + match result with - | RequestError(errors) -> - equals expected errors - | _ -> fail "Expected a requets error GQLResponse" + | RequestError (errors) -> equals expected errors + | _ -> fail "Expected a requets error GQLResponse" [] let ``Execute handles execution of abstract types: absent type resolution produces errors for Union`` () = - let query = """{ + let query = + """{ pets { name ... on Dog { @@ -242,90 +295,19 @@ let ``Execute handles execution of abstract types: absent type resolution produc } } }""" - let result = sync <| schemaWithInterface.Value.AsyncExecute(parse query) - let expected = - [{ Message = "Field 'unknownField1' is not defined in schema type 'Dog'."; Path = Include ["pets"; "unknownField1"]; Locations = Skip; Extensions = Skip } - { Message = "Inline fragment has type condition 'UnknownCat', but that type does not exist in the schema."; Path = Include ["pets"]; Locations = Skip; Extensions = Skip }] - - match result with - | RequestError(errors) -> - equals expected errors - | _ -> fail "Expected a requets error GQLResponse" - -type Widget = - { Id: string; - Name: string } + let result = sync <| schemaWithInterface.Value.AsyncExecute (parse query) -type User = - { Id: string; - Name: string; - Widgets: Widget list } + let expected = + [ { Message = "Field 'unknownField1' is not defined in schema type 'Dog'." + Path = Include [ "pets"; "unknownField1" ] + Locations = Skip + Extensions = Skip } + { Message = "Inline fragment has type condition 'UnknownCat', but that type does not exist in the schema." + Path = Include [ "pets" ] + Locations = Skip + Extensions = Skip } ] -// TODO: should not this test have a better name? Is it an abstraction test? -[] -let ``inner types `` () = - let viewer = { - Id = "1" - Name = "Anonymous" - Widgets = - [ { Id = "1"; Name = "What's it"} - { Id = "2"; Name = "Who's it"} - { Id = "3"; Name = "How's it"} ]} - - let getUser id = if viewer.Id = id then Some viewer else None - let getWidget id = viewer.Widgets |> List.tryFind (fun w -> w.Id = id) - - let rec Widget = - Define.Object( - name = "Widget", - description = "A shiny widget", - interfaces = [ Node ], - fields = - [ Define.GlobalIdField(fun _ w -> w.Id) - Define.Field("name", StringType, fun _ (w : Widget) -> w.Name) ] - ) - - and WidgetsField name (getUser: ResolveFieldContext -> 'a -> User) = - let resolve ctx xx = - let user = getUser ctx xx - let widgets = user.Widgets |> List.toArray - Connection.ofArray widgets - - Define.Field(name, ConnectionOf Widget, "A person's collection of widgets", Connection.allArgs, resolve) - - and User = - Define.Object( - name = "User", - description = "A person who uses our app", - interfaces = [ Node ], - fields = - [ Define.GlobalIdField(fun _ w -> w.Id) - Define.Field("name", StringType, fun _ w -> w.Name) - WidgetsField "widgets" (fun _ user -> user) ] - ) - - and Node = Define.Node(fun () -> [ User; Widget ]) - - let Query = - Define.Object("Query", - [ Define.NodeField(Node, fun _ () id -> - match id with - | GlobalId("User", i) -> getUser i |> Option.map box - | GlobalId("Widget", i) -> getWidget i |> Option.map box - | _ -> None) - Define.Field("viewer", User, fun _ () -> viewer) - WidgetsField "widgets" (fun _ () -> viewer) ] - ) - - let schema = Schema(query = Query, config = { SchemaConfig.Default with Types = [ User; Widget ]}) - let schemaProcessor = Executor(schema) - - let query = "{ - viewer {name}, widgets { edges { cursor } } - }" - let result = sync <| schemaProcessor.AsyncExecute(parse query) match result with - | Direct(_, errors) -> - empty errors - | _ -> fail "Expected a direct GQLResponse" + | RequestError (errors) -> equals expected errors + | _ -> fail "Expected a requets error GQLResponse" diff --git a/tests/FSharp.Data.GraphQL.Tests/AstExtensionsTests.fs b/tests/FSharp.Data.GraphQL.Tests/AstExtensionsTests.fs index 8462acff9..8e82c0e8c 100644 --- a/tests/FSharp.Data.GraphQL.Tests/AstExtensionsTests.fs +++ b/tests/FSharp.Data.GraphQL.Tests/AstExtensionsTests.fs @@ -8,7 +8,7 @@ open FSharp.Data.GraphQL.Parser open FSharp.Data.GraphQL.Ast.Extensions /// Converts line breaks to a single standard to avoid different SO line break termination issues. -let normalize (str : string) = str.Replace("\r\n", "\n") +let normalize (str : string) = str.Replace ("\r\n", "\n") /// Generates an Ast.Document from a query string, prints it to another /// query string and expects it to be equal. Input query must be formatted (with line breaks and identation). @@ -16,20 +16,22 @@ let normalize (str : string) = str.Replace("\r\n", "\n") let private printAndAssert (query : string) = let document = parse query let expected = normalize query - let actual = normalize <| document.ToQueryString() + let actual = normalize <| document.ToQueryString () actual |> equals expected [] -let ``Should be able to print a simple query`` () = - printAndAssert """query q { +let ``Can print a simple query`` () = + printAndAssert + """query q { hero { name } }""" [] -let ``Should be able to print a simple query with 2 fields`` () = - printAndAssert """query q { +let ``Can print a simple query with 2 fields`` () = + printAndAssert + """query q { hero { id name @@ -37,8 +39,9 @@ let ``Should be able to print a simple query with 2 fields`` () = }""" [] -let ``Should be able to print a query with variables`` () = - printAndAssert """query q($id: String!) { +let ``Can print a query with variables`` () = + printAndAssert + """query q($id: String!) { hero(id: $id) { id name @@ -46,26 +49,30 @@ let ``Should be able to print a query with variables`` () = }""" [] -let ``Should be able to parse a query with an object input in the internal method`` () = - printAndAssert """mutation q($id: String!, $name: String!) { +let ``Can parse a query with an object input in the internal method`` () = + printAndAssert + """mutation q($id: String!, $name: String!) { addHero(input: { id: $id, label: $name }) }""" [] -let ``Should be able to parse a query with an object having array properties input in the internal method`` () = - printAndAssert """mutation q($id: String!, $name: String!, $friend1: String!) { +let ``Can parse a query with an object having array properties input in the internal method`` () = + printAndAssert + """mutation q($id: String!, $name: String!, $friend1: String!) { addHero(input: { friends: [ $friend1 ], id: $id, label: $name }) }""" [] -let ``Should be able to parse a query with an object having multi-element array input in the internal method`` () = - printAndAssert """mutation q($id: String!, $name: String!) { +let ``Can parse a query with an object having multi-element array input in the internal method`` () = + printAndAssert + """mutation q($id: String!, $name: String!) { addHero(input: { friends: [ 7, 5, -3 ], id: $id, label: $name }) }""" [] let ``Should be able print ObjectValue names properly`` () = - printAndAssert """query GetCampaigns { + printAndAssert + """query GetCampaigns { campaigns(params: { limit: 100, offset: 0 }) { campaigns { code @@ -74,8 +81,9 @@ let ``Should be able print ObjectValue names properly`` () = }""" [] -let ``Should be able to print a query with aliases`` () = - printAndAssert """query q($myId: String!, $hisId: String!) { +let ``Can print a query with aliases`` () = + printAndAssert + """query q($myId: String!, $hisId: String!) { myHero: hero(id: $myId) { id name @@ -90,8 +98,9 @@ let ``Should be able to print a query with aliases`` () = }""" [] -let ``Should be able to print a query with fragment spreads`` () = - printAndAssert """query q($myId: String!, $hisId: String!) { +let ``Can print a query with fragment spreads`` () = + printAndAssert + """query q($myId: String!, $hisId: String!) { myHero: hero(id: $myId) { id name @@ -120,15 +129,17 @@ fragment friend on Character { }""" [] -let ``Should be able to print a short hand format query`` () = - printAndAssert """{ +let ``Can print a short hand format query`` () = + printAndAssert + """{ field1 field2 }""" [] let ``Should not print query without name in short hand format`` () = - printAndAssert """query ($rId: Int) { + printAndAssert + """query ($rId: Int) { answer(id: $rId) { id answer @@ -136,8 +147,9 @@ let ``Should not print query without name in short hand format`` () = }""" [] -let ``Should be able to print a query with inline fragments`` () = - printAndAssert """query q($myId: String!, $hisId: String!) { +let ``Can print a query with inline fragments`` () = + printAndAssert + """query q($myId: String!, $hisId: String!) { myHero: hero(id: $myId) { id name @@ -174,8 +186,9 @@ fragment friend on Character { }""" [] -let ``Should be able to print arguments inside fragment spreads and default variable values`` () = - printAndAssert """query HeroComparison($first: Int = 3) { +let ``Can print arguments inside fragment spreads and default variable values`` () = + printAndAssert + """query HeroComparison($first: Int = 3) { leftComparison: hero(episode: EMPIRE) { ...comparisonFields } @@ -197,8 +210,9 @@ fragment comparisonFields on Character { }""" [] -let ``Should be able to print directives`` () = - printAndAssert """query Hero($episode: Episode, $withFriends: Boolean!) { +let ``Can print directives`` () = + printAndAssert + """query Hero($episode: Episode, $withFriends: Boolean!) { hero(episode: $episode) { name friends @include(if: $withFriends) { @@ -208,8 +222,9 @@ let ``Should be able to print directives`` () = }""" [] -let ``Should be able to print multiple directives and arguments`` () = - printAndAssert """query q($skip: Boolean!) { +let ``Can print multiple directives and arguments`` () = + printAndAssert + """query q($skip: Boolean!) { hero(id: "1000") { name friends(first: 1, name_starts_with: "D") @defer @skip(if: $skip) { @@ -226,8 +241,9 @@ let ``Should be able to print multiple directives and arguments`` () = }""" [] -let ``Should be able to print a mutation`` () = - printAndAssert """mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) { +let ``Can print a mutation`` () = + printAndAssert + """mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) { createReview(episode: $ep, review: $review) { stars commentary @@ -235,8 +251,9 @@ let ``Should be able to print a mutation`` () = }""" [] -let ``Should be able to print a subscription`` () = - printAndAssert """subscription onCommentAdded($repoFullName: String!) { +let ``Can print a subscription`` () = + printAndAssert + """subscription onCommentAdded($repoFullName: String!) { commentAdded(repoFullName: $repoFullName) { id content @@ -244,8 +261,10 @@ let ``Should be able to print a subscription`` () = }""" [] -let ``Should be able to print type name meta field`` () = - let expected = normalize """query q { +let ``Can print type name meta field`` () = + let expected = + normalize + """query q { hero(id: "1000") { name friends { @@ -265,7 +284,9 @@ let ``Should be able to print type name meta field`` () = } __typename }""" - let query = """query q { + + let query = + """query q { hero(id: "1000") { name friends { @@ -281,13 +302,15 @@ let ``Should be able to print type name meta field`` () = } } """ + let document = parse query - let actual = normalize <| document.ToQueryString(QueryStringPrintingOptions.IncludeTypeNames) + let actual = normalize <| document.ToQueryString (QueryStringPrintingOptions.IncludeTypeNames) actual |> equals expected [] let ``Should generate information map correctly`` () = - let query = """query q { + let query = + """query q { hero(id: "1000") { name friends { @@ -304,31 +327,22 @@ let ``Should generate information map correctly`` () = } """ let document = parse query - let actual = document.GetInfoMap() |> Map.toList - let expected = [(Some "q", [TypeField - {Name = "hero"; - Alias = None; - Fields = - [TypeField - {Name = "friends"; - Alias = None; - Fields = - [FragmentField {Name = "primaryFunction"; - Alias = None; - TypeCondition = "Droid"; - Fields = [];}; - FragmentField {Name = "id"; - Alias = None; - TypeCondition = "Droid"; - Fields = [];}; - FragmentField {Name = "homePlanet"; - Alias = None; - TypeCondition = "Human"; - Fields = [];}; - FragmentField {Name = "id"; - Alias = None; - TypeCondition = "Human"; - Fields = [];}];}; TypeField {Name = "name"; - Alias = None; - Fields = [];}];}])] + let actual = document.GetInfoMap () |> Map.toList + + let expected = + [ (Some "q", + [ TypeField + { Name = "hero" + Alias = None + Fields = + [ TypeField + { Name = "friends" + Alias = None + Fields = + [ FragmentField { Name = "primaryFunction"; Alias = None; TypeCondition = "Droid"; Fields = [] } + FragmentField { Name = "id"; Alias = None; TypeCondition = "Droid"; Fields = [] } + FragmentField { Name = "homePlanet"; Alias = None; TypeCondition = "Human"; Fields = [] } + FragmentField { Name = "id"; Alias = None; TypeCondition = "Human"; Fields = [] } ] } + TypeField { Name = "name"; Alias = None; Fields = [] } ] } ]) ] + actual |> equals expected diff --git a/tests/FSharp.Data.GraphQL.Tests/IntrospectionTests.fs b/tests/FSharp.Data.GraphQL.Tests/IntrospectionTests.fs index 22561eb2a..e0993193a 100644 --- a/tests/FSharp.Data.GraphQL.Tests/IntrospectionTests.fs +++ b/tests/FSharp.Data.GraphQL.Tests/IntrospectionTests.fs @@ -41,7 +41,7 @@ let inputFieldQuery = """{ """ [] -let ``Input field should be marked as nullable when defaultValue is provided`` () = +let ``Input field must be marked as nullable when defaultValue is provided`` () = let root = Define.Object("Query", [ Define.Field("onlyField", StringType, "The only field", [ Define.Input("in", StringType, defaultValue = "1") @@ -75,7 +75,7 @@ let ``Input field should be marked as nullable when defaultValue is provided`` ( | _ -> fail "Expected Direct GQResponse" [] -let ``Input field should be marked as non-nullable when defaultValue is not provided`` () = +let ``Input field must be marked as non-nullable when defaultValue is not provided`` () = let root = Define.Object("Query", [ Define.Field("onlyField", StringType, "The only field", [ Define.Input("in", StringType) @@ -109,7 +109,7 @@ let ``Input field should be marked as non-nullable when defaultValue is not prov | _ -> fail "Expected Direct GQResponse" [] -let ``Input field should be marked as nullable when its type is nullable`` () = +let ``Input field must be marked as nullable when its type is nullable`` () = let root = Define.Object("Query", [ Define.Field("onlyField", StringType, "The only field", [ Define.Input("in", Nullable StringType) @@ -143,7 +143,7 @@ let ``Input field should be marked as nullable when its type is nullable`` () = | _ -> fail "Expected Direct GQResponse" [] -let ``Input field should be marked as nullable when its type is nullable and have default value provided`` () = +let ``Input field must be marked as nullable when its type is nullable and have default value provided`` () = let root = Define.Object("Query", [ Define.Field("onlyField", StringType, "The only field", [ Define.Input("in", Nullable StringType, defaultValue = Some "1") @@ -177,7 +177,7 @@ let ``Input field should be marked as nullable when its type is nullable and hav | _ -> fail "Expected Direct GQResponse" [] -let ``Introspection schema should be serializable back and forth using json`` () = +let ``Introspection schema must be serializable back and forth using json`` () = let root = Define.Object("Query", [ Define.Field("onlyField", StringType) ]) let schema = Schema(root) let query = """query IntrospectionQuery { diff --git a/tests/FSharp.Data.GraphQL.Tests/ObservableExtensionsTests.fs b/tests/FSharp.Data.GraphQL.Tests/ObservableExtensionsTests.fs index 621051e21..a51c342de 100644 --- a/tests/FSharp.Data.GraphQL.Tests/ObservableExtensionsTests.fs +++ b/tests/FSharp.Data.GraphQL.Tests/ObservableExtensionsTests.fs @@ -24,7 +24,7 @@ let ``ofSeq should call OnComplete and return items in expected order`` () = sub.Received |> seqEquals source [] -let `` bind should call OnComplete and return items in expected order`` () = +let ``bind should call OnComplete and return items in expected order`` () = let source = seq { for x in 1 .. 5 do yield x } let obs = Observable.ofSeq source |> Observable.bind (fun x -> Observable.ofSeq [x; x]) use sub = Observer.create obs diff --git a/tests/FSharp.Data.GraphQL.Tests/ParserTests.fs b/tests/FSharp.Data.GraphQL.Tests/ParserTests.fs index 7d62a4598..3bad68e89 100644 --- a/tests/FSharp.Data.GraphQL.Tests/ParserTests.fs +++ b/tests/FSharp.Data.GraphQL.Tests/ParserTests.fs @@ -86,18 +86,18 @@ let directive name arguments = { Directive.Name = name; Arguments = arguments } let directive1 name argument = directive name [ argument ] [] -let ``parser should parse empty query``() = +let ``Parser must parse empty query``() = let expected = docN [] test expected "" [] -let ``parser should parse empty query with whitespace``() = +let ``Parser must parse empty query with whitespace``() = let expected = docN [] test expected """ """ [] -let ``parser should parse simple query with single field``() = +let ``Parser must parse simple query with single field``() = let expected = field "uri" |> queryWithSelection @@ -105,7 +105,7 @@ let ``parser should parse simple query with single field``() = test expected """{uri}""" [] -let ``parser should parse simple query with operation identifier, but no operation name``() = +let ``Parser must parse simple query with operation identifier, but no operation name``() = let expected = field "uri" |> queryWithSelection @@ -113,7 +113,7 @@ let ``parser should parse simple query with operation identifier, but no operati test expected """query {uri}""" [] -let ``parser should parse simple query with single field with whitespace``() = +let ``Parser must parse simple query with single field with whitespace``() = let expected = field "uri" |> queryWithSelection @@ -123,7 +123,7 @@ let ``parser should parse simple query with single field with whitespace``() = }""" [] -let ``parser should parse simple fields``() = +let ``Parser must parse simple fields``() = let expected = [ "uri"; "width"; "height" ] |> List.map field @@ -132,7 +132,7 @@ let ``parser should parse simple fields``() = test expected """{uri,width,height}""" [] -let ``parser should parse simple fields with whitespace``() = +let ``Parser must parse simple fields with whitespace``() = let expected = [ "uri"; "width"; "height" ] |> List.map field @@ -145,7 +145,7 @@ let ``parser should parse simple fields with whitespace``() = }""" [] -let ``parser should parse simple fields without commas whitespace``() = +let ``Parser must parse simple fields without commas whitespace``() = let expected = [ "uri"; "width"; "height" ] |> List.map field @@ -158,7 +158,7 @@ let ``parser should parse simple fields without commas whitespace``() = }""" [] -let ``parser should parse nested field``() = +let ``Parser must parse nested field``() = let expected = [ "phone"; "name" ] |> List.map field @@ -173,7 +173,7 @@ let ``parser should parse nested field``() = }""" [] -let ``parser should parse nested field no commas``() = +let ``Parser must parse nested field no commas``() = let expected = [ "phone"; "name" ] |> List.map field @@ -188,7 +188,7 @@ let ``parser should parse nested field no commas``() = }""" [] -let ``parser should parse nested fields``() = +let ``Parser must parse nested fields``() = let contact = [ "phone"; "name" ] |> List.map field @@ -209,7 +209,7 @@ let ``parser should parse nested fields``() = }""" [] -let ``parser should parse nested fields no commas``() = +let ``Parser must parse nested fields no commas``() = let contact = [ "phone"; "name" ] |> List.map field @@ -230,7 +230,7 @@ let ``parser should parse nested fields no commas``() = }""" [] -let ``parser should parse multi level nested fields``() = +let ``Parser must parse multi level nested fields``() = let profile = field "uri" |> fieldWithNameAndSelection "profile_picture" let author = @@ -253,7 +253,7 @@ let ``parser should parse multi level nested fields``() = }""" [] -let ``parser should parse GraphQL``() = +let ``Parser must parse GraphQL``() = let profile = [ field "uri"; field "width"; field "height" ] |> fieldWithNameAndArgsAndSelections "profilePicture" [ argInt "size" 50 ] @@ -281,7 +281,7 @@ let ``parser should parse GraphQL``() = }""" [] -let ``parser should parse query with null arguments``() = +let ``Parser must parse query with null arguments``() = let expected = [ field "name" ] |> fieldWithNameAndArgsAndSelections "user" [ argNull "id" ] @@ -294,7 +294,7 @@ let ``parser should parse query with null arguments``() = }""" [] -let ``parser should parse query with quoted arguments``() = +let ``Parser must parse query with quoted arguments``() = let expected = [ field "id" ] |> fieldWithNameAndArgsAndSelections "search" [ argString "query" "the cow said \"moo\"!" ] @@ -307,7 +307,7 @@ let ``parser should parse query with quoted arguments``() = }""" [] -let ``parser should parse query with single-quoted arguments``() = +let ``Parser must parse query with single-quoted arguments``() = let expected = [ field "id" ] |> fieldWithNameAndArgsAndSelections "search" [ argString "query" "It's working!" ] @@ -320,7 +320,7 @@ let ``parser should parse query with single-quoted arguments``() = }""" [] -let ``parser should parse query with arguments``() = +let ``Parser must parse query with arguments``() = let expected = [ field "name" ] |> fieldWithNameAndArgsAndSelections "user" [ argInt "id" 4 ] @@ -333,7 +333,7 @@ let ``parser should parse query with arguments``() = }""" [] -let ``parser should parse query with arguments 1``() = +let ``Parser must parse query with arguments 1``() = let expected = [ field "id"; field "name"; fieldWithNameAndArgs "profilePic" [ argInt "size" 100 ] ] |> fieldWithNameAndArgsAndSelections "user" [ argInt "id" 4 ] @@ -348,7 +348,7 @@ let ``parser should parse query with arguments 1``() = }""" [] -let ``parser should parse query with multiple arguments``() = +let ``Parser must parse query with multiple arguments``() = let profilePic = [ argInt "width" 100; argInt "height" 50 ] |> fieldWithNameAndArgs "profilePic" @@ -368,7 +368,7 @@ let ``parser should parse query with multiple arguments``() = }""" [] -let ``parser should parse query with field alias``() = +let ``Parser must parse query with field alias``() = let profilePic alias size = [ argInt "size" size ] |> fieldWithNameAndArgs "profilePic" @@ -390,7 +390,7 @@ let ``parser should parse query with field alias``() = }""" [] -let ``parser should parse query with top level field alias``() = +let ``Parser must parse query with top level field alias``() = let expected = [ field "id"; field "name" ] |> fieldWithNameAndArgsAndSelections "user" [ argInt "id" 4 ] @@ -405,7 +405,7 @@ let ``parser should parse query with top level field alias``() = }""" [] -let ``parser should parse query without fragments``() = +let ``Parser must parse query without fragments``() = let friends name = [ field "id"; field "name"; fieldWithNameAndArgs "profilePic" [ argInt "size" 50 ] ] |> fieldWithNameAndArgsAndSelections name [ argInt "first" 10 ] @@ -432,7 +432,7 @@ let ``parser should parse query without fragments``() = }""" [] -let ``parser should parse query with fragments ``() = +let ``Parser must parse query with fragments ``() = let friends name = spread "friendFields" |> fieldWithNameArgsAndSelection name [ argInt "first" 10 ] let withFragments = @@ -462,7 +462,7 @@ let ``parser should parse query with fragments ``() = }""" [] -let ``parser should parse query with nested fragments ``() = +let ``Parser must parse query with nested fragments ``() = let friends name = spread "friendFields" |> fieldWithNameArgsAndSelection name [ argInt "first" 10 ] let withFragments = @@ -497,7 +497,7 @@ let ``parser should parse query with nested fragments ``() = }""" [] -let ``parser should parse query with type conditions``() = +let ``Parser must parse query with type conditions``() = let nestedFrag name typ fieldName = field "count" |> fieldWithNameAndSelection fieldName @@ -533,7 +533,7 @@ let ``parser should parse query with type conditions``() = }""" [] -let ``parser should parse query with inline fragments``() = +let ``Parser must parse query with inline fragments``() = let nestedFragment typ fieldName = field "count" |> fieldWithNameAndSelection fieldName @@ -565,7 +565,7 @@ let ``parser should parse query with inline fragments``() = }""" [] -let ``parser should parse query with fragment directives``() = +let ``Parser must parse query with fragment directives``() = let maybeFragment = field "name" |> fieldWithNameAndSelection "me" @@ -651,5 +651,5 @@ fragment frag on Friend { }""" [] -let ``parser should parse kitchen sink``() = +let ``Parser must parse kitchen sink``() = parse KitchenSink diff --git a/tests/FSharp.Data.GraphQL.Tests/PlanningTests.fs b/tests/FSharp.Data.GraphQL.Tests/PlanningTests.fs index ba7990dc2..2bfe064e2 100644 --- a/tests/FSharp.Data.GraphQL.Tests/PlanningTests.fs +++ b/tests/FSharp.Data.GraphQL.Tests/PlanningTests.fs @@ -59,7 +59,7 @@ and UNamed = | Person p -> upcast p) [] -let ``Planning should retain correct types for leafs``() = +let ``Planning must retain correct types for leafs``() = let schema = Schema(Person) let schemaProcessor = Executor(schema) let query = """{ @@ -77,7 +77,7 @@ let ``Planning should retain correct types for leafs``() = ("age", upcast Person, upcast IntType) ] [] -let ``Planning should work with fragments``() = +let ``Planning must work with fragments``() = let schema = Schema(Person) let schemaProcessor = Executor(schema) let query = """query Example { @@ -98,7 +98,7 @@ let ``Planning should work with fragments``() = ("age", upcast Person, upcast IntType) ] [] -let ``Planning should work with parallel fragments``() = +let ``Planning must work with parallel fragments``() = let schema = Schema(Person) let schemaProcessor = Executor(schema) let query = """query Example { @@ -123,7 +123,7 @@ let ``Planning should work with parallel fragments``() = ("age", upcast Person, upcast IntType) ] [] -let ``Planning should retain correct types for lists``() = +let ``Planning must retain correct types for lists``() = let Query = Define.Object("Query", [ Define.Field("people", ListOf Person, fun _ () -> people) ]) let schema = Schema(Query) let schemaProcessor = Executor(schema) @@ -158,7 +158,7 @@ let ``Planning should retain correct types for lists``() = friendInfo.ReturnDef |> equals (upcast Person) [] -let ``Planning should work with interfaces``() = +let ``Planning must work with interfaces``() = let Query = Define.Object("Query", [ Define.Field("names", ListOf INamed, fun _ () -> []) ]) let schema = Schema(query = Query, config = { SchemaConfig.Default with Types = [ Person; Animal ] }) let schemaProcessor = Executor(schema) @@ -194,7 +194,7 @@ let ``Planning should work with interfaces``() = ("species", upcast INamed, upcast StringType) ] ]) [] -let ``Planning should work with unions``() = +let ``Planning must work with unions``() = let Query = Define.Object("Query", [ Define.Field("names", ListOf UNamed, fun _ () -> []) ]) let schema = Schema(Query) let schemaProcessor = Executor(schema) diff --git a/tests/FSharp.Data.GraphQL.Tests/Relay/NodeTests.fs b/tests/FSharp.Data.GraphQL.Tests/Relay/NodeTests.fs index 85e2cbb11..4b5554b93 100644 --- a/tests/FSharp.Data.GraphQL.Tests/Relay/NodeTests.fs +++ b/tests/FSharp.Data.GraphQL.Tests/Relay/NodeTests.fs @@ -6,6 +6,7 @@ module FSharp.Data.GraphQL.Tests.Relay.NodeTests #nowarn "40" open System +open Xunit open FSharp.Data.GraphQL open FSharp.Data.GraphQL.Types open FSharp.Data.GraphQL.Execution @@ -50,9 +51,6 @@ and Node = Define.Node (fun () -> [ Person; Car ]) let schema = Schema(Define.Object("Query", [ Define.NodeField(Node, resolve) ]), config = { SchemaConfig.Default with Types = [ Person; Car ] }) -open Xunit -open System.Threading -open System.Collections.Concurrent let execAndValidateNode (query: string) expectedDirect expectedDeferred = let result = sync <| Executor(schema).AsyncExecute(query) diff --git a/tests/FSharp.Data.GraphQL.Tests/SubscriptionTests.fs b/tests/FSharp.Data.GraphQL.Tests/SubscriptionTests.fs index 78bf42164..17f9786c0 100644 --- a/tests/FSharp.Data.GraphQL.Tests/SubscriptionTests.fs +++ b/tests/FSharp.Data.GraphQL.Tests/SubscriptionTests.fs @@ -1,12 +1,9 @@ module FSharp.Data.GraphQL.Tests.SubscriptionTests open Xunit -open FSharp.Control open FSharp.Data.GraphQL open FSharp.Data.GraphQL.Parser open FSharp.Data.GraphQL.Execution -open System.Threading -open System.Collections.Concurrent open FSharp.Data.GraphQL.Types type Value = @@ -104,7 +101,7 @@ let schema = Schema(Query, subscription = Subscription, config = schemaConfig) let executor = Executor(schema) [] -let ``Should be able to subscribe to sync field and get results``() = +let ``Can subscribe to sync field and get results``() = let expected = SubscriptionResult (NameValueLookup.ofList [ "watchData", upcast NameValueLookup.ofList [ "id", upcast 1 @@ -131,7 +128,7 @@ let ``Should be able to subscribe to sync field and get results``() = | _ -> failwith "Expected Stream GQLResponse" [] -let ``Should be able to subscribe to tagged sync field and get results with expected tag``() = +let ``Can subscribe to tagged sync field and get results with expected tag``() = let expected = SubscriptionResult (NameValueLookup.ofList [ "watchDataByKey", upcast NameValueLookup.ofList [ "id", upcast 1 @@ -158,7 +155,7 @@ let ``Should be able to subscribe to tagged sync field and get results with expe | _ -> failwith "Expected Stream GQLResponse" [] -let ``Should be able to subscribe to tagged sync field and do not get results with unexpected tag``() = +let ``Can subscribe to tagged sync field and do not get results with unexpected tag``() = let query = parse """subscription Test { watchDataByKey(id: 1, key: "tag2") { id @@ -174,7 +171,7 @@ let ``Should be able to subscribe to tagged sync field and do not get results wi | _ -> failwith "Expected Stream GQLResponse" [] -let ``Should be able to subscribe to async field and get results``() = +let ``Can subscribe to async field and get results``() = let expected = SubscriptionResult (NameValueLookup.ofList [ "watchDataAsync", upcast NameValueLookup.ofList [ "id", upcast 1 @@ -200,7 +197,7 @@ let ``Should be able to subscribe to async field and get results``() = | _ -> failwith "Expected Stream GQLResponse" [] -let ``Should be able to subscribe to tagged async field and get results with expected tag``() = +let ``Can subscribe to tagged async field and get results with expected tag``() = let expected = SubscriptionResult (NameValueLookup.ofList [ "watchDataByKeyAsync", upcast NameValueLookup.ofList [ "id", upcast 1 @@ -227,7 +224,7 @@ let ``Should be able to subscribe to tagged async field and get results with exp | _ -> failwith "Expected Stream GQLResponse" [] -let ``Should be able to subscribe to tagged async field and do not get results with unexpected tag``() = +let ``Can subscribe to tagged async field and do not get results with unexpected tag``() = let query = parse """subscription Test { watchDataByKeyAsync(id: 1, key: "tag2") { id diff --git a/tests/FSharp.Data.GraphQL.Tests/TypeValidationTests.fs b/tests/FSharp.Data.GraphQL.Tests/TypeValidationTests.fs index 34bd9b3a2..70b5f394c 100644 --- a/tests/FSharp.Data.GraphQL.Tests/TypeValidationTests.fs +++ b/tests/FSharp.Data.GraphQL.Tests/TypeValidationTests.fs @@ -28,7 +28,7 @@ let TestInterface = Define.Input("y", StringType) ], (fun _ _ -> "")) ]) [] -let ``Validation should inform about not implemented fields``() = +let ``Validation must inform about not implemented fields``() = let TestData = Define.Object (name = "TestData", fields = [ Define.Field("property", StringType, (fun _ d -> d.TestProperty)) ], @@ -39,7 +39,7 @@ let ``Validation should inform about not implemented fields``() = equals expected result [] -let ``Validation should inform about fields with not matching signatures``() = +let ``Validation must inform about fields with not matching signatures``() = let TestData = Define.Object (name = "TestData", @@ -55,7 +55,7 @@ let ``Validation should inform about fields with not matching signatures``() = equals expected result [] -let ``Validation should succeed if object implements interface correctly``() = +let ``Validation must succeed if object implements interface correctly``() = let TestData = Define.Object (name = "TestData", diff --git a/tests/FSharp.Data.GraphQL.Tests/UnionInterfaceTests.fs b/tests/FSharp.Data.GraphQL.Tests/UnionInterfaceTests.fs index 163078a87..81bb0f7fb 100644 --- a/tests/FSharp.Data.GraphQL.Tests/UnionInterfaceTests.fs +++ b/tests/FSharp.Data.GraphQL.Tests/UnionInterfaceTests.fs @@ -3,10 +3,8 @@ module FSharp.Data.GraphQL.Tests.UnionInterfaceTests -open System open Xunit open FSharp.Data.GraphQL -open FSharp.Data.GraphQL.Ast open FSharp.Data.GraphQL.Types open FSharp.Data.GraphQL.Parser open FSharp.Data.GraphQL.Execution