Skip to content

Commit 1e69878

Browse files
committed
run formatter
1 parent e87f913 commit 1e69878

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+612
-568
lines changed

.ocamlformat

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version = 0.19.0
21
profile = janestreet
32
parse-docstrings = true
43
wrap-comments = true

benchmark/src/httpaf.ml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ let benchmark =
4747
let error_handler ?request:_ error start_response =
4848
let response_body = start_response Headers.empty in
4949
(match error with
50-
| `Exn exn ->
51-
Body.write_string response_body (Printexc.to_string exn);
52-
Body.write_string response_body "\n"
53-
| #Status.standard as error ->
54-
Body.write_string response_body (Status.default_reason_phrase error));
50+
| `Exn exn ->
51+
Body.write_string response_body (Printexc.to_string exn);
52+
Body.write_string response_body "\n"
53+
| #Status.standard as error ->
54+
Body.write_string response_body (Status.default_reason_phrase error));
5555
Body.close_writer response_body
5656
;;
5757

@@ -61,11 +61,11 @@ let () =
6161
let request_handler _ = benchmark in
6262
let error_handler _ = error_handler in
6363
Lwt.async (fun () ->
64-
Lwt_io.establish_server_with_client_socket
65-
~backlog:11_000
66-
listen_address
67-
(Server.create_connection_handler ~request_handler ~error_handler)
68-
>>= fun _server -> Lwt.return_unit);
64+
Lwt_io.establish_server_with_client_socket
65+
~backlog:11_000
66+
listen_address
67+
(Server.create_connection_handler ~request_handler ~error_handler)
68+
>>= fun _server -> Lwt.return_unit);
6969
let forever, _ = Lwt.wait () in
7070
Lwt_main.run forever
7171
;;

example/file_upload/main.ml

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -32,76 +32,76 @@ let index_view ?(success = false) () =
3232
layout
3333
~title:"Opium file upload"
3434
[ (if success
35-
then
36-
div
37-
~a:[ a_class [ "mx-auto mt-16 max-w-lg rounded-md bg-green-50 p-4" ] ]
38-
[ div
39-
~a:[ a_class [ "flex" ] ]
40-
[ div
41-
~a:[ a_class [ "flex-shrink-0" ] ]
42-
[ svg
43-
~a:
44-
[ Tyxml.Svg.a_class [ "h-5 w-5 text-green-400" ]
45-
; Tyxml.Svg.a_viewBox (0., 0., 20., 20.)
46-
; Tyxml.Svg.a_fill `CurrentColor
47-
]
48-
[ Tyxml.Svg.path
49-
~a:
50-
[ a_svg_custom "fill-rule" "evenodd"
51-
; Tyxml.Svg.a_d
52-
"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 \
53-
00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 \
54-
1.414l2 2a1 1 0 001.414 0l4-4z"
55-
; a_svg_custom "clip-rule" "evenodd"
56-
]
57-
[]
58-
]
59-
]
60-
; div
61-
~a:[ a_class [ "ml-3" ] ]
62-
[ p
63-
~a:[ a_class [ "text-sm leading-5 font-medium text-green-800" ] ]
64-
[ txt "Successfully uploaded" ]
65-
]
66-
; div
67-
~a:[ a_class [ "ml-auto pl-3" ] ]
68-
[ div
69-
~a:[ a_class [ "-mx-1.5 -my-1.5" ] ]
70-
[ button
71-
~a:
72-
[ a_class
73-
[ "inline-flex rounded-md p-1.5 text-green-500 \
74-
hover:bg-green-100 focus:outline-none \
75-
focus:bg-green-100 transition ease-in-out \
76-
duration-150"
77-
]
78-
; a_aria "label" [ "Dismiss" ]
79-
]
80-
[ svg
81-
~a:
82-
[ Tyxml.Svg.a_class [ "h-5 w-5" ]
83-
; Tyxml.Svg.a_viewBox (0., 0., 20., 20.)
84-
; Tyxml.Svg.a_fill `CurrentColor
85-
]
86-
[ Tyxml.Svg.path
87-
~a:
88-
[ a_svg_custom "fill-rule" "evenodd"
89-
; Tyxml.Svg.a_d
90-
"M4.293 4.293a1 1 0 011.414 0L10 \
91-
8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 \
92-
10l4.293 4.293a1 1 0 01-1.414 1.414L10 \
93-
11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 \
94-
10 4.293 5.707a1 1 0 010-1.414z"
95-
; a_svg_custom "clip-rule" "evenodd"
96-
]
97-
[]
98-
]
99-
]
100-
]
101-
]
102-
]
103-
]
104-
else div [])
35+
then
36+
div
37+
~a:[ a_class [ "mx-auto mt-16 max-w-lg rounded-md bg-green-50 p-4" ] ]
38+
[ div
39+
~a:[ a_class [ "flex" ] ]
40+
[ div
41+
~a:[ a_class [ "flex-shrink-0" ] ]
42+
[ svg
43+
~a:
44+
[ Tyxml.Svg.a_class [ "h-5 w-5 text-green-400" ]
45+
; Tyxml.Svg.a_viewBox (0., 0., 20., 20.)
46+
; Tyxml.Svg.a_fill `CurrentColor
47+
]
48+
[ Tyxml.Svg.path
49+
~a:
50+
[ a_svg_custom "fill-rule" "evenodd"
51+
; Tyxml.Svg.a_d
52+
"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 \
53+
00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 \
54+
1.414l2 2a1 1 0 001.414 0l4-4z"
55+
; a_svg_custom "clip-rule" "evenodd"
56+
]
57+
[]
58+
]
59+
]
60+
; div
61+
~a:[ a_class [ "ml-3" ] ]
62+
[ p
63+
~a:[ a_class [ "text-sm leading-5 font-medium text-green-800" ] ]
64+
[ txt "Successfully uploaded" ]
65+
]
66+
; div
67+
~a:[ a_class [ "ml-auto pl-3" ] ]
68+
[ div
69+
~a:[ a_class [ "-mx-1.5 -my-1.5" ] ]
70+
[ button
71+
~a:
72+
[ a_class
73+
[ "inline-flex rounded-md p-1.5 text-green-500 \
74+
hover:bg-green-100 focus:outline-none \
75+
focus:bg-green-100 transition ease-in-out \
76+
duration-150"
77+
]
78+
; a_aria "label" [ "Dismiss" ]
79+
]
80+
[ svg
81+
~a:
82+
[ Tyxml.Svg.a_class [ "h-5 w-5" ]
83+
; Tyxml.Svg.a_viewBox (0., 0., 20., 20.)
84+
; Tyxml.Svg.a_fill `CurrentColor
85+
]
86+
[ Tyxml.Svg.path
87+
~a:
88+
[ a_svg_custom "fill-rule" "evenodd"
89+
; Tyxml.Svg.a_d
90+
"M4.293 4.293a1 1 0 011.414 0L10 \
91+
8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 \
92+
10l4.293 4.293a1 1 0 01-1.414 1.414L10 \
93+
11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 \
94+
10 4.293 5.707a1 1 0 010-1.414z"
95+
; a_svg_custom "clip-rule" "evenodd"
96+
]
97+
[]
98+
]
99+
]
100+
]
101+
]
102+
]
103+
]
104+
else div [])
105105
; form
106106
~a:[ a_enctype "multipart/form-data"; a_action "/upload"; a_method `Post ]
107107
[ div

example/rock_server/main.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ let run () =
5959
fd
6060
in
6161
Lwt.async (fun () ->
62-
let* _ =
63-
Lwt_io.establish_server_with_client_socket listen_address connection_handler
64-
in
65-
Lwt.return_unit);
62+
let* _ =
63+
Lwt_io.establish_server_with_client_socket listen_address connection_handler
64+
in
65+
Lwt.return_unit);
6666
let forever, _ = Lwt.wait () in
6767
Lwt_main.run forever
6868
;;

opium-graphql/src/opium_graphql.ml

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -107,23 +107,24 @@ let execute_request schema ctx req =
107107
| Ok (query, variables, operation_name) ->
108108
let+ result = execute_query ctx schema variables operation_name query in
109109
(match result with
110-
| Ok (`Response data) -> data |> basic_to_safe |> Opium.Response.of_json ~status:`OK
111-
| Ok (`Stream stream) ->
112-
Graphql_lwt.Schema.Io.Stream.close stream;
113-
let body = "Subscriptions are only supported via websocket transport" in
114-
Opium.Response.of_plain_text ~status:`Bad_request body
115-
| Error err -> err |> basic_to_safe |> Opium.Response.of_json ~status:`Bad_request)
110+
| Ok (`Response data) -> data |> basic_to_safe |> Opium.Response.of_json ~status:`OK
111+
| Ok (`Stream stream) ->
112+
Graphql_lwt.Schema.Io.Stream.close stream;
113+
let body = "Subscriptions are only supported via websocket transport" in
114+
Opium.Response.of_plain_text ~status:`Bad_request body
115+
| Error err -> err |> basic_to_safe |> Opium.Response.of_json ~status:`Bad_request)
116116
;;
117117

118118
let make_handler
119-
: type a.
120-
make_context:(Rock.Request.t -> a) -> a Graphql_lwt.Schema.schema -> Rock.Handler.t
119+
: type a.
120+
make_context:(Rock.Request.t -> a) -> a Graphql_lwt.Schema.schema -> Rock.Handler.t
121121
=
122-
fun ~make_context schema req ->
122+
fun ~make_context schema req ->
123123
match req.Opium.Request.meth with
124124
| `GET ->
125-
if Httpaf.Headers.get req.Opium.Request.headers "Connection" = Some "Upgrade"
126-
&& Httpaf.Headers.get req.Opium.Request.headers "Upgrade" = Some "websocket"
125+
if
126+
Httpaf.Headers.get req.Opium.Request.headers "Connection" = Some "Upgrade"
127+
&& Httpaf.Headers.get req.Opium.Request.headers "Upgrade" = Some "websocket"
127128
then
128129
(* TODO: Add subscription support when there is a good solution for websockets with
129130
Httpaf *)
@@ -155,12 +156,12 @@ let make_graphiql_handler ~graphql_endpoint req =
155156
~etag:graphiql_etag
156157
~mime_type:"text/html; charset=utf-8"
157158
(fun () ->
158-
match Asset.read "graphiql.html" with
159-
| None -> Lwt.return_error `Internal_server_error
160-
| Some body ->
161-
let regexp = Str.regexp_string "%%GRAPHQL_API%%" in
162-
let body = Str.global_replace regexp graphql_endpoint body in
163-
Lwt.return_ok (Opium.Body.of_string body))
159+
match Asset.read "graphiql.html" with
160+
| None -> Lwt.return_error `Internal_server_error
161+
| Some body ->
162+
let regexp = Str.regexp_string "%%GRAPHQL_API%%" in
163+
let body = Str.global_replace regexp graphql_endpoint body in
164+
Lwt.return_ok (Opium.Body.of_string body))
164165
in
165166
if accept_html
166167
then h req

opium-graphql/test/request_test.ml

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ let schema =
77
"hello"
88
~typ:(non_null string)
99
~args:Arg.[ arg "name" ~typ:string ]
10-
~resolve:
11-
(fun _ () -> function
12-
| None -> "world"
13-
| Some name -> name)
10+
~resolve:(fun _ () -> function
11+
| None -> "world"
12+
| Some name -> name)
1413
])
1514
;;
1615

@@ -84,12 +83,12 @@ let suite =
8483
Opium.Body.of_string
8584
(Yojson.Safe.to_string
8685
(`Assoc
87-
[ ( "query"
88-
, `String
89-
"query A { hello(name: \"world\") } query B { hello(name: \
90-
\"fail\") }" )
91-
; "operationName", `String "A"
92-
]))
86+
[ ( "query"
87+
, `String
88+
"query A { hello(name: \"world\") } query B { hello(name: \
89+
\"fail\") }" )
90+
; "operationName", `String "A"
91+
]))
9392
in
9493
test_case
9594
~req:(Opium.Request.make ~headers:json_content_type ~body default_uri `POST)
@@ -101,11 +100,11 @@ let suite =
101100
Opium.Body.of_string
102101
(Yojson.Safe.to_string
103102
(`Assoc
104-
[ ( "query"
105-
, `String
106-
"query A { hello(name: \"world\") } query B { hello(name: \
107-
\"fail\") }" )
108-
]))
103+
[ ( "query"
104+
, `String
105+
"query A { hello(name: \"world\") } query B { hello(name: \
106+
\"fail\") }" )
107+
]))
109108
in
110109
let query = Some [ "operationName", [ "A" ] ] in
111110
let uri = Uri.with_uri ~query (Uri.of_string default_uri) in
@@ -124,9 +123,9 @@ let suite =
124123
Opium.Body.of_string
125124
(Yojson.Safe.to_string
126125
(`Assoc
127-
[ "query", `String "query A($name: String!) { hello(name: $name) }"
128-
; "variables", `Assoc [ "name", `String "world" ]
129-
]))
126+
[ "query", `String "query A($name: String!) { hello(name: $name) }"
127+
; "variables", `Assoc [ "name", `String "world" ]
128+
]))
130129
in
131130
test_case
132131
~req:(Opium.Request.make ~headers:json_content_type ~body default_uri `POST)
@@ -138,7 +137,7 @@ let suite =
138137
Opium.Body.of_string
139138
(Yojson.Safe.to_string
140139
(`Assoc
141-
[ "query", `String "query A($name: String!) { hello(name: $name) }" ]))
140+
[ "query", `String "query A($name: String!) { hello(name: $name) }" ]))
142141
in
143142
let query =
144143
Some [ "operationName", [ "A" ]; "variables", [ "{\"name\":\"world\"}" ] ]

opium/src/app.ml

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ let any methods route action t =
189189
if List.length methods = 0
190190
then
191191
Logs.warn (fun f ->
192-
f
193-
"Warning: you're using [any] attempting to bind to '%s' but your list\n\
194-
\ of http methods is empty route"
195-
route);
192+
f
193+
"Warning: you're using [any] attempting to bind to '%s' but your list of http \
194+
methods is empty route"
195+
route);
196196
let route = Route.of_string route in
197197
methods
198198
|> List.fold_left ~init:t ~f:(fun app meth -> app |> register ~meth ~route ~action)
@@ -214,11 +214,11 @@ let start app =
214214
let middlewares = attach_middleware app in
215215
setup_logger app;
216216
Logs.info (fun f ->
217-
f
218-
"Starting Opium on %s:%d%s"
219-
app.host
220-
app.port
221-
(if app.debug then " (debug mode)" else ""));
217+
f
218+
"Starting Opium on %s:%d%s"
219+
app.host
220+
app.port
221+
(if app.debug then " (debug mode)" else ""));
222222
run_unix
223223
?backlog:app.backlog
224224
~middlewares
@@ -234,12 +234,12 @@ let start_multicore app =
234234
let middlewares = attach_middleware app in
235235
setup_logger app;
236236
Logs.info (fun f ->
237-
f
238-
"Starting Opium on %s:%d with %d cores%s"
239-
app.host
240-
app.port
241-
app.jobs
242-
(if app.debug then " (debug mode)" else ""));
237+
f
238+
"Starting Opium on %s:%d with %d cores%s"
239+
app.host
240+
app.port
241+
app.jobs
242+
(if app.debug then " (debug mode)" else ""));
243243
run_unix_multicore
244244
~middlewares
245245
~host:app.host
@@ -263,12 +263,12 @@ let print_routes_f routes =
263263
Printf.printf "%d Routes:\n" (Hashtbl.length routes_tbl);
264264
Hashtbl.iter
265265
(fun key data ->
266-
Printf.printf
267-
"> %s (%s)\n"
268-
(Route.to_string key)
269-
(data
270-
|> List.map ~f:(fun m -> Httpaf.Method.to_string m |> String.uppercase_ascii)
271-
|> String.concat ~sep:" "))
266+
Printf.printf
267+
"> %s (%s)\n"
268+
(Route.to_string key)
269+
(data
270+
|> List.map ~f:(fun m -> Httpaf.Method.to_string m |> String.uppercase_ascii)
271+
|> String.concat ~sep:" "))
272272
routes_tbl
273273
;;
274274

0 commit comments

Comments
 (0)