-
Notifications
You must be signed in to change notification settings - Fork 73
/
field_aliases.fsx
55 lines (41 loc) · 1.68 KB
/
field_aliases.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Uncomment those to use build script client assembly using netstandard2.0
//#r "../../bin/FSharp.Data.GraphQL.Shared/netstandard2.0/FSharp.Data.GraphQL.Shared.dll"
//#r "../../bin/FSharp.Data.GraphQL.Client/netstandard2.0/FSharp.Data.GraphQL.Client.dll"
//Uncomment those to use dotnet build command for the client assembly using netstandard2.0
#r "../../src/FSharp.Data.GraphQL.Shared/bin/Debug/netstandard2.0/FSharp.Data.GraphQL.Shared.dll"
#r "../../src/FSharp.Data.GraphQL.Client/bin/Debug/netstandard2.0/FSharp.Data.GraphQL.Client.dll"
open FSharp.Data.GraphQL
type MyProvider = GraphQLProvider<"swapi_schema.json">
let operation =
MyProvider.Operation<"""query TestQuery {
myHero: hero(id: "1000") {
hisName: name
appearsIn
homePlanet
hisFriends: friends {
... on Human {
humanName: name
appearsIn
homePlanet
}
... on Droid {
droidName: name
appearsIn
primaryFunction
}
}
}
}""">
()
let ctx = MyProvider.GetContext (serverUrl = "http://localhost:8086")
let result = operation.Run (ctx)
let hisName = result.Data.Value.MyHero.Value.HisName.Value
let hisFriends = result.Data.Value.MyHero.Value.HisFriends |> Array.choose id
let humanFriendNames =
hisFriends |> Array.choose (fun f -> f.TryAsHuman ()) |> Array.map (fun h -> h.HumanName)
let droidFriendNames =
hisFriends |> Array.choose (fun f -> f.TryAsDroid ()) |> Array.map (fun h -> h.DroidName)
printfn "His name: %s" hisName
printfn "Human friend names: %A" humanFriendNames
printfn "Droid friend names: %A" droidFriendNames
printfn "Data: %A" result.Data