Skip to content

Commit f0723e5

Browse files
author
Viktor Tochonov
committed
Remove unnecessary types of Animals
1 parent 6b2a1e0 commit f0723e5

2 files changed

Lines changed: 37 additions & 44 deletions

File tree

tests/FSharp.Data.GraphQL.Tests/MiddlewareTests.fs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,16 @@ let getExecutor (expectedFilter : ObjectListFilter voption) =
161161
Define.Union<_, _> (
162162
name = "Property",
163163
options = [ ComplexType; BuildingType; CommunityType ],
164-
resolveValue = id,
164+
resolveValue =
165+
(function
166+
| Complex c -> box c
167+
| Building b -> box b
168+
| Community c -> box c),
165169
resolveType =
166170
(function
167-
| Complex _ -> ComplexType
168-
| Building _ -> BuildingType
169-
| Community _ -> CommunityType)
171+
| Complex _ -> upcast ComplexType
172+
| Building _ -> upcast BuildingType
173+
| Community _ -> upcast CommunityType)
170174
)
171175
let Query =
172176
Define.Object<Root> (

tests/FSharp.Data.GraphQL.Tests/ObjectListFilterLinqTests.fs

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -339,32 +339,33 @@ let ``ObjectListFilter works with getDiscriminator and getDiscriminatorValue for
339339
c.Name |> equals "Complex AA"
340340
| _ -> failwith "Expected Complex"
341341

342-
type Cow = { ID : int; Name : string; Discriminator : string; __typename : string }
342+
// Dummy types to be used in OfType filter
343+
type Cow = class end
344+
type Horse = class end
345+
type Hamster = class end
343346

344-
type Horse = { ID : int; Name : string; Discriminator : string; __typename : string }
345-
346-
type Hamster = { ID : int; Name : string; Discriminator : string; __typename : string }
347+
type Animal = { ID : int; Name : string; Discriminator : string; __typename : string }
347348

348349
let animalData = [
349-
{ ID = 1; Discriminator = "Cow"; Name = "Cow A"; __typename = typeof<Cow>.Name }
350+
{ ID = 1; Discriminator = "Cow"; Name = "Cow A"; __typename = "Cow" }
350351
{
351352
ID = 2
352353
Discriminator = "Horse"
353354
Name = "Horse B"
354-
__typename = typeof<Horse>.Name
355+
__typename = "Horse"
355356
}
356-
{ ID = 3; Discriminator = "Cow"; Name = "Cow C"; __typename = typeof<Cow>.Name }
357+
{ ID = 3; Discriminator = "Cow"; Name = "Cow C"; __typename = "Cow" }
357358
{
358359
ID = 4
359360
Discriminator = "Horse"
360361
Name = "Horse D"
361-
__typename = typeof<Horse>.Name
362+
__typename = "Horse"
362363
}
363364
{
364365
ID = 5
365366
Discriminator = "Hamster"
366367
Name = "Hamster E"
367-
__typename = typeof<Hamster>.Name
368+
__typename = "Hamster"
368369
}
369370
]
370371

@@ -383,17 +384,13 @@ let ``ObjectListFilter works with getDiscriminatorValue for Horse`` () =
383384
let filteredData = queryable.Apply (filter, options) |> Seq.toList
384385
List.length filteredData |> equals 2
385386
do
386-
let result = List.head filteredData
387-
match result with
388-
| h ->
389-
h.ID |> equals 2
390-
h.Name |> equals "Horse B"
387+
let animal = List.head filteredData
388+
animal.ID |> equals 2
389+
animal.Name |> equals "Horse B"
391390
do
392-
let result = List.last filteredData
393-
match result with
394-
| h ->
395-
h.ID |> equals 4
396-
h.Name |> equals "Horse D"
391+
let animal = List.last filteredData
392+
animal.ID |> equals 4
393+
animal.Name |> equals "Horse D"
397394

398395
[<Fact>]
399396
let ``ObjectListFilter works with getDiscriminatorValue startsWith for Horse and Hamster`` () =
@@ -406,23 +403,19 @@ let ``ObjectListFilter works with getDiscriminatorValue startsWith for Horse and
406403
(function
407404
| t when t = typeof<Cow> -> t.Name
408405
| t when t = typeof<Horse> -> t.Name
409-
| t when t = typeof<Hamster> -> t.Name
406+
| t when t = typeof<Animal> -> t.Name
410407
| _ -> raise (NotSupportedException "Type not supported"))
411408
)
412409
let filteredData = queryable.Apply (filter, options) |> Seq.toList
413410
List.length filteredData |> equals 3
414411
do
415-
let result = List.head filteredData
416-
match result with
417-
| c ->
418-
c.ID |> equals 2
419-
c.Name |> equals "Horse B"
412+
let animal = List.head filteredData
413+
animal.ID |> equals 2
414+
animal.Name |> equals "Horse B"
420415
do
421-
let result = List.last filteredData
422-
match result with
423-
| c ->
424-
c.ID |> equals 5
425-
c.Name |> equals "Hamster E"
416+
let animal = List.last filteredData
417+
animal.ID |> equals 5
418+
animal.Name |> equals "Hamster E"
426419

427420
type ListTagsProduct = { Name : string; Tags : string list }
428421

@@ -505,14 +498,10 @@ let ``ObjectListFilter OfTypes works with two or more types`` () =
505498
let filteredData = queryable.Apply (filter, options) |> Seq.toList
506499
List.length filteredData |> equals 4
507500
do
508-
let result = List.head filteredData
509-
match result with
510-
| c ->
511-
c.ID |> equals 1
512-
c.Name |> equals "Cow A"
501+
let animal = List.head filteredData
502+
animal.ID |> equals 1
503+
animal.Name |> equals "Cow A"
513504
do
514-
let result = List.last filteredData
515-
match result with
516-
| h ->
517-
h.ID |> equals 4
518-
h.Name |> equals "Horse D"
505+
let animal = List.last filteredData
506+
animal.ID |> equals 4
507+
animal.Name |> equals "Horse D"

0 commit comments

Comments
 (0)