Skip to content

Commit 7a5462f

Browse files
committed
Formatted scripts and samples
1 parent 05551ec commit 7a5462f

File tree

15 files changed

+373
-350
lines changed

15 files changed

+373
-350
lines changed

build.fsx

Lines changed: 83 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ open Octokit
3333

3434
#if !FAKE
3535
let execContext =
36-
System.Environment.GetCommandLineArgs()
36+
System.Environment.GetCommandLineArgs ()
3737
|> Array.skip 2 // skip fsi.exe; build.fsx
3838
|> Array.toList
3939
|> Fake.Core.Context.FakeExecutionContext.Create false __SOURCE_FILE__
40+
4041
execContext
4142
|> Fake.Core.Context.RuntimeContext.Fake
4243
|> Fake.Core.Context.setExecutionContext
@@ -57,93 +58,85 @@ let projectRepo = "https://github.com/fsprojects/FSharp.Data.GraphQL.git"
5758
// --------------------------------------------------------------------------------------
5859
// Clean build results
5960

60-
Target.create "Clean" (fun _ ->
61-
Shell.cleanDirs ["bin"; "temp"]
62-
)
61+
Target.create "Clean" <| fun _ -> Shell.cleanDirs [ "bin"; "temp" ]
6362

64-
Target.create "CleanDocs" (fun _ ->
65-
Shell.cleanDirs ["docs/output"]
66-
)
63+
Target.create "CleanDocs" <| fun _ -> Shell.cleanDirs [ "docs/output" ]
6764

6865
// --------------------------------------------------------------------------------------
6966
// Build library & test project
7067

71-
Target.create "Restore" (fun _ ->
68+
Target.create "Restore" <| fun _ ->
7269
!! "src/**/*.??proj"
7370
-- "src/**/*.shproj"
74-
|> Seq.iter (fun pattern -> DotNet.restore id pattern))
71+
|> Seq.iter (fun pattern -> DotNet.restore id pattern)
7572

7673

77-
Target.create "Build" <| fun _ ->
74+
Target.create "Build" <| fun _ ->
7875
"FSharp.Data.GraphQL.sln"
79-
|> DotNet.build (fun o ->
80-
{ o with Configuration = DotNet.BuildConfiguration.Release; MSBuildParams = { o.MSBuildParams with DisableInternalBinLog = true }})
81-
82-
let startGraphQLServer (project: string) (streamRef: DataRef<Stream>) =
83-
DotNet.build (fun options ->
84-
{ options with
76+
|> DotNet.build (fun o ->
77+
{ o with
8578
Configuration = DotNet.BuildConfiguration.Release
86-
MSBuildParams = { options.MSBuildParams with DisableInternalBinLog = true }}) project
87-
88-
let projectName = Path.GetFileNameWithoutExtension(project)
89-
let projectPath = Path.GetDirectoryName(project)
79+
MSBuildParams = { o.MSBuildParams with DisableInternalBinLog = true } })
80+
81+
let startGraphQLServer (project : string) (streamRef : DataRef<Stream>) =
82+
DotNet.build
83+
(fun options ->
84+
{ options with
85+
Configuration = DotNet.BuildConfiguration.Release
86+
MSBuildParams = { options.MSBuildParams with DisableInternalBinLog = true } })
87+
project
88+
89+
let projectName = Path.GetFileNameWithoutExtension (project)
90+
let projectPath = Path.GetDirectoryName (project)
9091
let serverExe = projectPath </> "bin" </> "Release" </> DotNetMoniker </> (projectName + ".dll")
9192

9293
CreateProcess.fromRawCommandLine "dotnet" serverExe
93-
|> CreateProcess.withStandardInput (CreatePipe streamRef)
94-
|> Proc.start
95-
|> ignore
94+
|> CreateProcess.withStandardInput (CreatePipe streamRef) |> Proc.start |> ignore
9695

97-
System.Threading.Thread.Sleep(2000)
96+
System.Threading.Thread.Sleep (2000)
9897

9998
let runTests (project : string) =
100-
DotNet.build (fun options ->
101-
{ options with
102-
Configuration = DotNet.BuildConfiguration.Release
103-
MSBuildParams = { options.MSBuildParams with DisableInternalBinLog = true }} ) project
104-
DotNet.test (fun options ->
105-
{ options with
106-
Configuration = DotNet.BuildConfiguration.Release
107-
MSBuildParams = { options.MSBuildParams with DisableInternalBinLog = true }
108-
Common = { options.Common with
109-
CustomParams = Some "--no-build -v=normal" } }) project
99+
DotNet.build
100+
(fun options ->
101+
{ options with
102+
Configuration = DotNet.BuildConfiguration.Release
103+
MSBuildParams = { options.MSBuildParams with DisableInternalBinLog = true } })
104+
project
105+
106+
DotNet.test
107+
(fun options ->
108+
{ options with
109+
Configuration = DotNet.BuildConfiguration.Release
110+
MSBuildParams = { options.MSBuildParams with DisableInternalBinLog = true }
111+
Common = { options.Common with CustomParams = Some "--no-build -v=normal" } })
112+
project
110113

111114
let starWarsServerStream = StreamRef.Empty
112-
Target.create "StartStarWarsServer" (fun _ ->
115+
116+
Target.create "StartStarWarsServer" <| fun _ ->
113117
Target.activateFinal "StopStarWarsServer"
114118
let project = "samples" </> "star-wars-api" </> "FSharp.Data.GraphQL.Samples.StarWarsApi.fsproj"
115119
startGraphQLServer project starWarsServerStream
116-
)
117120

118-
Target.createFinal "StopStarWarsServer" (fun _ ->
119-
try
120-
starWarsServerStream.Value.Write([|0uy|],0,1)
121-
with
122-
| e -> printfn "%s" e.Message
123-
)
121+
Target.createFinal "StopStarWarsServer" <| fun _ ->
122+
try starWarsServerStream.Value.Write ([| 0uy |], 0, 1)
123+
with e -> printfn "%s" e.Message
124124

125125

126126
let integrationServerStream = StreamRef.Empty
127-
Target.create "StartIntegrationServer" (fun _ ->
127+
128+
Target.create "StartIntegrationServer" <| fun _ ->
128129
Target.activateFinal "StopIntegrationServer"
129130
let project = "tests" </> "FSharp.Data.GraphQL.IntegrationTests.Server" </> "FSharp.Data.GraphQL.IntegrationTests.Server.fsproj"
130131
startGraphQLServer project integrationServerStream
131-
)
132132

133-
Target.createFinal "StopIntegrationServer" (fun _ ->
134-
try
135-
integrationServerStream.Value.Write([|0uy|],0,1)
136-
with
137-
| e -> printfn "%s" e.Message
138-
)
133+
Target.createFinal "StopIntegrationServer" <| fun _ ->
134+
try integrationServerStream.Value.Write ([| 0uy |], 0, 1)
135+
with e -> printfn "%s" e.Message
139136

140-
Target.create "RunUnitTests" (fun _ ->
141-
runTests "tests/FSharp.Data.GraphQL.Tests/FSharp.Data.GraphQL.Tests.fsproj"
142-
)
137+
Target.create "RunUnitTests" <| fun _ -> runTests "tests/FSharp.Data.GraphQL.Tests/FSharp.Data.GraphQL.Tests.fsproj"
143138

144-
Target.create "RunIntegrationTests" (fun _ ->
145-
runTests "tests/FSharp.Data.GraphQL.IntegrationTests/FSharp.Data.GraphQL.IntegrationTests.fsproj"
146-
)
139+
Target.create "RunIntegrationTests" <| fun _ -> runTests "tests/FSharp.Data.GraphQL.IntegrationTests/FSharp.Data.GraphQL.IntegrationTests.fsproj"
147140

148141
let prepareDocGen () =
149142
Shell.rm "docs/release-notes.md"
@@ -156,70 +149,51 @@ let prepareDocGen () =
156149

157150
Shell.cleanDir ".fsdocs"
158151

159-
Target.create "GenerateDocs" (fun _ ->
152+
Target.create "GenerateDocs" <| fun _ ->
160153
prepareDocGen ()
161154
DotNet.exec id "fsdocs" "build --clean" |> ignore
162-
)
163155

164-
Target.create "GenerateDocsWatch" (fun _ ->
156+
Target.create "GenerateDocsWatch" <| fun _ ->
165157
prepareDocGen ()
166158
DotNet.exec id "fsdocs" "watch --clean" |> ignore
167-
System.Console.ReadKey() |> ignore
168-
)
159+
System.Console.ReadKey () |> ignore
169160

170-
Target.create "ReleaseDocs" (fun _ ->
161+
Target.create "ReleaseDocs" <| fun _ ->
171162
Git.Repository.clone "" projectRepo "temp/gh-pages"
172163
Git.Branches.checkoutBranch "temp/gh-pages" "gh-pages"
173-
Shell.copyRecursive "output" "temp/gh-pages" true |> printfn "%A"
164+
Shell.copyRecursive "output" "temp/gh-pages" true |> printfn "%A"
174165
Git.CommandHelper.runSimpleGitCommand "temp/gh-pages" "add ." |> printfn "%s"
166+
175167
let cmd = sprintf """commit -a -m "Update generated documentation for version %s""" release.NugetVersion
176-
Git.CommandHelper.runSimpleGitCommand "temp/gh-pages" cmd |> printfn "%s"
168+
Git.CommandHelper.runSimpleGitCommand "temp/gh-pages" cmd |> printfn "%s"
177169
Git.Branches.push "temp/gh-pages"
178-
)
179170

180171
let pack id =
181172
Shell.cleanDir <| sprintf "nuget/%s.%s" project id
182-
id
183-
|> NuGet.NuGetPack(fun p ->
173+
id |> NuGet.NuGetPack (fun p ->
184174
{ p with
185175
Version = release.NugetVersion
186176
OutputPath = sprintf "nuget/%s.%s" project id
187-
//IncludeReferencedProjects = false
188-
})
177+
//IncludeReferencedProjects = false
178+
})
189179

190180
let publishPackage id =
191181
pack id
192-
NuGet.NuGetPublish(fun p ->
193-
{ p with
194-
WorkingDir = sprintf "nuget/%s.%s" project id })
182+
NuGet.NuGetPublish <| fun p -> { p with WorkingDir = sprintf "nuget/%s.%s" project id }
195183

196-
Target.create "PublishServer" (fun _ ->
197-
publishPackage "Server"
198-
)
184+
Target.create "PublishServer" <| fun _ -> publishPackage "Server"
199185

200-
Target.create "PublishClient" (fun _ ->
201-
publishPackage "Client"
202-
)
186+
Target.create "PublishClient" <| fun _ -> publishPackage "Client"
203187

204-
Target.create "PublishMiddleware" (fun _ ->
205-
publishPackage "Server.Middleware"
206-
)
188+
Target.create "PublishMiddleware" <| fun _ -> publishPackage "Server.Middleware"
207189

208-
Target.create "PackShared" (fun _ ->
209-
pack "Shared"
210-
)
190+
Target.create "PackShared" <| fun _ -> pack "Shared"
211191

212-
Target.create "PackServer" (fun _ ->
213-
pack "Server"
214-
)
192+
Target.create "PackServer" <| fun _ -> pack "Server"
215193

216-
Target.create "PackClient" (fun _ ->
217-
pack "Client"
218-
)
194+
Target.create "PackClient" <| fun _ -> pack "Client"
219195

220-
Target.create "PackMiddleware" (fun _ ->
221-
pack "Server.Middleware"
222-
)
196+
Target.create "PackMiddleware" <| fun _ -> pack "Server.Middleware"
223197

224198

225199
// --------------------------------------------------------------------------------------
@@ -229,26 +203,25 @@ Target.create "All" ignore
229203
Target.create "PackAll" ignore
230204

231205
"Clean"
232-
==> "Restore"
233-
==> "Build"
234-
==> "RunUnitTests"
235-
==> "StartStarWarsServer"
236-
==> "StartIntegrationServer"
237-
==> "RunIntegrationTests"
238-
==> "All"
239-
=?> ("GenerateDocs", Environment.environVar "APPVEYOR" = "True")
240-
241-
"CleanDocs"
242-
==> "GenerateDocs"
206+
==> "Restore"
207+
==> "Build"
208+
==> "RunUnitTests"
209+
==> "StartStarWarsServer"
210+
==> "StartIntegrationServer"
211+
==> "RunIntegrationTests"
212+
==> "All"
213+
=?> ("GenerateDocs", Environment.environVar "APPVEYOR" = "True")
214+
215+
"CleanDocs" ==> "GenerateDocs"
243216

244217
"PackShared"
245-
==> "PackServer"
246-
==> "PackClient"
247-
==> "PackMiddleware"
248-
==> "PackAll"
218+
==> "PackServer"
219+
==> "PackClient"
220+
==> "PackMiddleware"
221+
==> "PackAll"
249222

250223
Target.runOrDefaultWithArguments "All"
251224

252225
#if !FAKE
253-
execContext.Context.Clear()
254-
#endif
226+
execContext.Context.Clear ()
227+
#endif

samples/client-provider/field_aliases.fsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,27 @@ let operation =
3939
}
4040
}
4141
}
42-
}""">()
42+
}""">
43+
()
4344

44-
let ctx = MyProvider.GetContext(serverUrl = "http://localhost:8086")
45+
let ctx = MyProvider.GetContext (serverUrl = "http://localhost:8086")
4546

46-
let result = operation.Run(ctx)
47+
let result = operation.Run (ctx)
4748

4849
let hisName = result.Data.Value.MyHero.Value.HisName.Value
4950

5051
let hisFriends = result.Data.Value.MyHero.Value.HisFriends |> Array.choose id
5152

5253
let humanFriendNames =
53-
hisFriends |> Array.choose (fun f -> f.TryAsHuman()) |> Array.map (fun h -> h.HumanName)
54+
hisFriends |> Array.choose (fun f -> f.TryAsHuman ()) |> Array.map (fun h -> h.HumanName)
5455

5556
let droidFriendNames =
56-
hisFriends |> Array.choose (fun f -> f.TryAsDroid()) |> Array.map (fun h -> h.DroidName)
57+
hisFriends |> Array.choose (fun f -> f.TryAsDroid ()) |> Array.map (fun h -> h.DroidName)
5758

5859
printfn "His name: %s" hisName
5960

6061
printfn "Human friend names: %A" humanFriendNames
6162

6263
printfn "Droid friend names: %A" droidFriendNames
6364

64-
printfn "Data: %A" result.Data
65+
printfn "Data: %A" result.Data

samples/client-provider/github_access.fsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ open FSharp.Data.GraphQL
2323
// The classical way via POST is done.
2424
type MyProvider = GraphQLProvider<"github_schema.json">
2525

26-
let operation = MyProvider.Operation<"""query q { viewer { login } }""">()
26+
let operation = MyProvider.Operation<"""query q { viewer { login } }"""> ()
2727

2828
let headers = HttpHeaders.ofFile "github_authorization_headers.headerfile"
2929

3030
let run () =
3131
// Dispose runtime context after using it.
32-
use runtimeContext = MyProvider.GetContext(serverUrl = "https://api.github.com/graphql", httpHeaders = headers)
33-
let result = operation.Run(runtimeContext)
32+
use runtimeContext = MyProvider.GetContext (serverUrl = "https://api.github.com/graphql", httpHeaders = headers)
33+
let result = operation.Run (runtimeContext)
3434
printfn "Data: %A\n" result.Data
3535

36-
run ()
36+
run ()

samples/client-provider/graphql_client.fsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@
1919
open FSharp.Data.GraphQL
2020

2121
let run () =
22-
// Dispose the connection after using it.
23-
use connection = new GraphQLClientConnection()
24-
let request : GraphQLRequest =
25-
{ Query = """query q { viewer { login } }"""
26-
Variables = [||]
27-
ServerUrl = "https://api.github.com/graphql"
28-
HttpHeaders =
29-
[| "Authorization", "bearer [your bearer token here]"
30-
"User-Agent", "[your github username here]" |]
31-
OperationName = Some "q" }
32-
let response = GraphQLClient.sendRequest connection request
33-
printfn "%s" response
34-
35-
run ()
22+
// Dispose the connection after using it.
23+
use connection = new GraphQLClientConnection ()
24+
25+
let request : GraphQLRequest =
26+
{ Query = """query q { viewer { login } }"""
27+
Variables = [||]
28+
ServerUrl = "https://api.github.com/graphql"
29+
HttpHeaders =
30+
[| "Authorization", "bearer [your bearer token here]"
31+
"User-Agent", "[your github username here]" |]
32+
OperationName = Some "q" }
33+
34+
let response = GraphQLClient.sendRequest connection request
35+
printfn "%s" response
36+
37+
run ()

0 commit comments

Comments
 (0)